<?php
/**
 * Features class.
 *
 * @package DokanKits\Admin\Dashboard\Pages
 * @since   3.0.0
 */

namespace DokanKits\Admin\Dashboard\Pages;

use DokanKits\Admin\Dashboard\Components\ComponentFactory as Factory;

/**
 * Features Page
 *
 * Manages features in the admin dashboard
 *
 * @since 1.0.0
 */
class Features extends Page {

	/**
	 * Page structure configuration
	 *
	 * @var mixed
	 * @since 3.0.0
	 */
	protected $structure;

	/**
	 * Get the ID of the page.
	 *
	 * @since 4.0.0
	 *
	 * @return string
	 */
	public function get_id(): string {
		return 'features';
	}

	/**
	 * Get menu configuration for the features page
	 *
	 * Defines the menu structure and configuration for the features page
	 * in the admin dashboard. This includes the page title, menu title,
	 * and routing information.
	 *
	 * @since 3.0.0
	 * @access public
	 *
	 * @param string $capability The required capability to access this menu.
	 * @param string $position   The menu position.
	 *
	 * @return array Menu configuration array.
	 */
	public function menu( string $capability, string $position ): array {
		return array(
			'page_title' => __( 'Dokan Kit Features', 'dokan-kits' ),
			'menu_title' => __( 'Features', 'dokan-kits' ),
			'route'      => 'status',
			'capability' => $capability,
			'position'   => 99,
		);
	}

	/**
	 * Describe settings for the features page
	 *
	 * Sets up the structure and configuration for all feature settings
	 * on the admin features page.
	 *
	 * @since 3.0.0
	 * @access public
	 *
	 * @return void
	 */
	public function describe_settings(): void {
		// Initialize the structure with factory.
		$this->structure = Factory::section( 'dokan-kits-features' );

		// Vendor Settings Group.
		$this->add_vendor_settings();

		// Product Settings Group.
		$this->add_product_settings();

		// Shipping Settings Group.
		$this->add_shipping_settings();

		// Cart & Checkout Settings Group.
		$this->add_cart_settings();

		// Allow other modules to extend our features.
		do_action( 'dokan_kits_describe_settings', $this->structure );
	}

	/**
	 * Add vendor features to the structure
	 *
	 * @since 3.0.0
	 * @return void
	 */
	private function add_vendor_settings(): void {
		/**
		 * Action before adding vendor settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_vendor_settings', $this->structure );

		$tab = Factory::section( 'vendor' )->set_title( esc_html__( 'Vendor', 'dokan-kits' ) )->set_icon( 'dashicons-businessman' );

		/**
		 * Filter vendor section
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The vendor section.
		 */
		$tab = apply_filters( 'dokan_kits_vendor_tab', $tab );

		do_action( 'dokan_kits_vendor_tab_before_field_definitions', $tab, $this->structure );

		// Registration.
		$registration = Factory::sub_section( 'registration' )
			->set_title( esc_html__( 'Vendor Registration', 'dokan-kits' ) )
			->set_description( esc_html__( 'Customize how vendors register and join your marketplace.', 'dokan-kits' ) );

		/**
		 * Filter vendor registration subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $registration The registration subsection.
		 */
		$registration = apply_filters( 'dokan_kits_vendor_registration_subsection', $registration );

		/**
		 * Action before adding registration fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $registration The registration subsection.
		 */
		do_action( 'dokan_kits_before_add_vendor_registration_fields', $registration );

		$registration->add(
			Factory::field( 'remove_vendor_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Vendor Registration', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the "I am a vendor" checkbox from the WooCommerce My Account registration page.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'vendor.registration.remove_vendor_checkbox' )
		);

		$registration->add(
			Factory::field( 'set_default_seller_role_checkbox', 'toggle' )
				->set_title( esc_html__( 'Enable "I am a Vendor" by default', 'dokan-kits' ) )
				->set_description( esc_html__( 'Pre-select the "I am a Vendor" checkbox on the registration form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'vendor.registration.set_default_seller_role_checkbox' )
				->add_dependency( 'vendor.registration.remove_vendor_checkbox', false )
		);

		$registration->add(
			Factory::field( 'remove_become_a_vendor_button_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Become a Vendor Button', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the "Become a Vendor" button from the WooCommerce My Account dashboard.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'vendor.registration.remove_become_a_vendor_button_checkbox' )
		);

		/**
		 * Action after adding registration fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $registration The registration subsection.
		 */
		do_action( 'dokan_kits_after_add_vendor_registration_fields', $registration );

		// Capabilities.
		$capabilities = Factory::sub_section( 'capabilities' )
			->set_title( esc_html__( 'Vendor Capabilities', 'dokan-kits' ) )
			->set_description( esc_html__( 'Manage what vendors can do within your marketplace.', 'dokan-kits' ) );

		/**
		 * Filter vendor capabilities subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $capabilities The capabilities subsection.
		 */
		$capabilities = apply_filters( 'dokan_kits_vendor_capabilities_subsection', $capabilities );

		/**
		 * Action before adding capability fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $capabilities The capabilities subsection.
		 */
		do_action( 'dokan_kits_before_add_vendor_capability_fields', $capabilities );

		$capabilities->add(
			Factory::field( 'enable_own_product_purchase_checkbox', 'toggle' )
				->set_title( esc_html__( 'Enable Purchase of Own Products', 'dokan-kits' ) )
				->set_description( esc_html__( 'Allow vendors to purchase products from their own store.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'vendor.capabilities.enable_own_product_purchase_checkbox' )
		);

		$capabilities->add(
			Factory::field( 'enable_publish_product_directly_checkbox', 'toggle' )
				->set_title( esc_html__( 'Enable Direct Product Publishing', 'dokan-kits' ) )
				->set_description( esc_html__( 'Allow vendors to publish products directly without admin approval.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'vendor.capabilities.enable_publish_product_directly_checkbox' )
		);

		/**
		 * Action after adding capability fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $capabilities The capabilities subsection.
		 */
		do_action( 'dokan_kits_after_add_vendor_capability_fields', $capabilities );

		$tab->add( $registration )->add( $capabilities );

		/**
		 * Action for adding additional vendor subsections
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The vendor section.
		 */
		do_action( 'dokan_kits_add_vendor_subsections', $tab );

		/**
		 * Action before adding vendor section to structure
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab       The vendor section.
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_vendor_section', $tab, $this->structure );

		$this->structure->add( $tab );

		/**
		 * Action after adding vendor settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_after_add_vendor_settings', $this->structure );
	}

	/**
	 * Add product features to the structure
	 *
	 * @since 3.0.0
	 * @return void
	 */
	private function add_product_settings(): void {
		/**
		 * Action before adding product settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_product_settings', $this->structure );

		$tab = Factory::section( 'product' )->set_title( esc_html__( 'Product', 'dokan-kits' ) )->set_icon( 'dashicons-products' );

		/**
		 * Filter product section
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The product section.
		 */
		$tab = apply_filters( 'dokan_kits_product_tab', $tab );

		do_action( 'dokan_kits_product_tab_before_field_definitions', $tab, $this->structure );

		// Product Types.
		$types = Factory::sub_section( 'types' )
			->set_title( esc_html__( 'Product Types', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control which product types vendors can create in their stores.', 'dokan-kits' ) );

		/**
		 * Filter product types subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $types The product types subsection.
		 */
		$types = apply_filters( 'dokan_kits_product_types_subsection', $types );

		/**
		 * Action before adding product type fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $types The product types subsection.
		 */
		do_action( 'dokan_kits_before_add_product_type_fields', $types, $tab, $this->structure );

		$registered_product_types = wc_get_product_types();
		if ( count( $registered_product_types ) > 0 ) {
			foreach ( $registered_product_types as $product_type => $product_type_label ) {
				$types->add(
					Factory::field( 'remove_' . $product_type . '_product_checkbox', 'toggle' )
						->set_title(
							sprintf(
							// translators: %s: product type label.
								esc_html__( 'Remove %ss', 'dokan-kits' ),
								$product_type_label
							)
						)
						->set_description(
							sprintf(
							// translators: %s: product type label.
								esc_html__( 'Hide the %s type option from vendors', 'dokan-kits' ),
								strtolower( $product_type_label )
							)
						)
						->set_default( false )
						->set_dependency_key( 'product.types.remove_' . $product_type . '_product_checkbox' )
				);
			}
		}

		// Add product types fields to product tab.
		$tab->add( $types );

		/**
		 * Action after adding product type fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $types The product types subsection.
		 */
		do_action( 'dokan_kits_after_add_product_type_fields', $types, $tab, $this->structure );
		do_action( 'dokan_kits_after_add_product_type_fields_definitions', $tab, $this->structure );

		// Product Fields.
		$fields = Factory::sub_section( 'fields' )
			->set_title( esc_html__( 'Product Fields', 'dokan-kits' ) )
			->set_description( esc_html__( 'Customize which fields appear in the vendor product editor.', 'dokan-kits' ) );

		/**
		 * Filter product fields subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $fields The product fields subsection.
		 */
		$fields = apply_filters( 'dokan_kits_product_fields_subsection', $fields );

		/**
		 * Action before adding product field options
		 *
		 * @since 3.0.0
		 *
		 * @param object $fields The product fields subsection.
		 */
		do_action( 'dokan_kits_before_add_product_field_options', $fields, $tab, $this->structure );

		$fields->add(
			Factory::field( 'remove_short_description_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Short Description', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the short description field from the product edit form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_short_description_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_long_description_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Long Description', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the main product description editor from the product edit form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_long_description_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_inventory_section_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Inventory Section', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the entire inventory management section from the product edit form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_inventory_section_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_downloadable_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Downloadable Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the downloadable product option from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_downloadable_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_virtual_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Virtual Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the virtual product option from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_virtual_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_linked_product_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Linked Product Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the linked product options (up-sells, cross-sells, etc.) from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_linked_product_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_attribute_variation_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Attribute and Variation Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the product attributes and variations section from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_attribute_variation_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_shipping_tax_option_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Product Shipping Tax Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the shipping and tax section from the product editor.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_shipping_tax_option_checkbox' )
		);

		$fields->add(
			Factory::field( 'remove_geolocation_option_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Geolocation Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the geolocation option from the product edit form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.fields.remove_geolocation_option_checkbox' )
		);

		// Add product fields to product tab.
		$tab->add( $fields );

		/**
		 * Action after adding product field options
		 *
		 * @since 3.0.0
		 *
		 * @param object $fields The product fields subsection.
		 */
		do_action( 'dokan_kits_after_add_product_field_options', $fields, $tab, $this->structure );
		do_action( 'dokan_kits_after_add_product_field_options_definitions', $tab, $this->structure );

		// Additional Features.
		$additional = Factory::sub_section( 'additional' )
			->set_title( esc_html__( 'Additional Features', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control additional product options and miscellaneous settings that can simplify the vendor experience.', 'dokan-kits' ) );

		/**
		 * Filter product additional features subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $additional The product additional features subsection.
		 */
		$additional = apply_filters( 'dokan_kits_product_additional_features_subsection', $additional );

		/**
		 * Action before adding additional product feature fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $additional The product additional features subsection.
		 */
		do_action( 'dokan_kits_before_add_additional_product_fields', $additional, $tab, $this->structure );

		$additional->add(
			Factory::field( 'remove_other_options_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Other Options', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide miscellaneous product options from the edit form.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.additional.remove_other_options_checkbox' )
		);

		// Add product additional fields to product tab.
		$tab->add( $additional );

		/**
		 * Action after adding additional product feature fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $additional The product additional features subsection.
		 */
		do_action( 'dokan_kits_after_add_additional_product_fields', $additional, $tab, $this->structure );
		do_action( 'dokan_kits_after_add_additional_product_fields_definitions', $tab, $this->structure );

		// Pro Features.
		$pro_features = Factory::sub_section( 'pro_features' )
			->set_title( esc_html__( 'Dokan Pro Features', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control the availability of premium Dokan Pro product features.', 'dokan-kits' ) );

		/**
		 * Filter product pro features subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $pro_features The product pro features subsection.
		 */
		$pro_features = apply_filters( 'dokan_kits_product_pro_features_subsection', $pro_features );

		/**
		 * Action before adding product pro feature fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $pro_features The product pro features subsection.
		 */
		do_action( 'dokan_kits_before_add_product_pro_feature_fields', $pro_features, $tab, $this->structure );

		$pro_features->add(
			Factory::field( 'remove_bulk_discount_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Bulk Discount Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the bulk discount feature from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.pro_features.remove_bulk_discount_checkbox' )
		);

		$pro_features->add(
			Factory::field( 'remove_rma_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove RMA Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the Return Merchandise Authorization (RMA) options from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.pro_features.remove_rma_checkbox' )
		);

		$pro_features->add(
			Factory::field( 'remove_wholesale_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Wholesale Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the wholesale product options from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.pro_features.remove_wholesale_checkbox' )
		);

		$pro_features->add(
			Factory::field( 'remove_min_max_product_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Min Max Product Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the minimum and maximum purchase quantity options from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.pro_features.remove_min_max_product_checkbox' )
		);

		$pro_features->add(
			Factory::field( 'remove_product_advertisement_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Product Advertisement Option', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the product advertisement feature from vendors.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'product.pro_features.remove_product_advertisement_checkbox' )
		);

		// Add product pro features to product tab.
		$tab->add( $pro_features );

		/**
		 * Action after adding product pro feature fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $pro_features The product pro features subsection.
		 */
		do_action( 'dokan_kits_after_add_product_pro_feature_fields', $pro_features, $tab, $this->structure );
		do_action( 'dokan_kits_after_add_product_pro_feature_fields_definitions', $tab, $this->structure );

		/**
		 * Action for adding additional product subsections
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The product section.
		 */
		do_action( 'dokan_kits_add_product_subsections', $tab );

		/**
		 * Action before adding product section to structure
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab       The product section.
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_product_section', $tab, $this->structure );

		$this->structure->add( $tab );

		/**
		 * Action after adding product settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_after_add_product_settings', $this->structure );
	}

	/**
	 * Add shipping features to the structure
	 *
	 * @since 3.0.0
	 * @return void
	 */
	private function add_shipping_settings(): void {
		/**
		 * Action before adding shipping settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_shipping_settings', $this->structure );

		$tab = Factory::section( 'shipping' )->set_title( esc_html__( 'Shipping', 'dokan-kits' ) )->set_icon( 'dashicons-car' );

		/**
		 * Filter shipping section
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The shipping section.
		 */
		$tab = apply_filters( 'dokan_kits_shipping_tab', $tab );

		do_action( 'dokan_kits_shipping_tab_before_field_definitions', $tab, $this->structure );

		// Split Shipping.
		$sub_section = Factory::sub_section( 'split' )
			->set_title( esc_html__( 'Split Shipping', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control split shipping options to manage how shipping costs are divided among vendors in multi-vendor orders.', 'dokan-kits' ) );

		/**
		 * Filter split shipping subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The split shipping subsection.
		 */
		$sub_section = apply_filters( 'dokan_kits_split_shipping_subsection', $sub_section );

		/**
		 * Action before adding split shipping fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The split shipping subsection.
		 */
		do_action( 'dokan_kits_before_add_split_shipping_fields', $sub_section );

		$sub_section->add(
			Factory::field( 'remove_split_shipping_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Split Shipping (Lite)', 'dokan-kits' ) )
				->set_description( esc_html__( 'Remove split shipping from cart and checkout pages in Dokan Lite.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'shipping.split.remove_split_shipping_checkbox' )
		);

		$sub_section->add(
			Factory::field( 'remove_split_shipping_pro_checkbox', 'toggle' )
				->set_title( esc_html__( 'Remove Split Shipping (Pro)', 'dokan-kits' ) )
				->set_description( esc_html__( 'Remove split shipping from cart and checkout pages in Dokan Pro.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'shipping.split.remove_split_shipping_pro_checkbox' )
		);

		/**
		 * Action after adding split shipping fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The split shipping subsection.
		 */
		do_action( 'dokan_kits_after_add_split_shipping_fields', $sub_section );

		// Order Processing.
		$orders = Factory::sub_section( 'orders' )
			->set_title( esc_html__( 'Order Processing', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control order processing options to streamline the handling of orders in your marketplace.', 'dokan-kits' ) );

		/**
		 * Filter order processing subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $orders The order processing subsection.
		 */
		$orders = apply_filters( 'dokan_kits_order_processing_subsection', $orders );

		/**
		 * Action before adding order processing fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $orders The order processing subsection.
		 */
		do_action( 'dokan_kits_before_add_order_processing_fields', $orders );

		$orders->add(
			Factory::field( 'auto_complete_order_checkbox', 'toggle' )
				->set_title( esc_html__( 'Auto-Complete Virtual Orders', 'dokan-kits' ) )
				->set_description( esc_html__( 'Automatically complete orders containing only virtual and downloadable products.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'shipping.orders.auto_complete_order_checkbox' )
		);

		/**
		 * Action after adding order processing fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $orders The order processing subsection.
		 */
		do_action( 'dokan_kits_after_add_order_processing_fields', $orders );

		$tab->add( $sub_section )->add( $orders );

		/**
		 * Action for adding additional shipping subsections
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The shipping section.
		 */
		do_action( 'dokan_kits_add_shipping_subsections', $tab );

		/**
		 * Action before adding shipping section to structure
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The shipping section.
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_shipping_section', $tab, $this->structure );

		$this->structure->add( $tab );

		/**
		 * Action after adding shipping settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_after_add_shipping_settings', $this->structure );
	}

	/**
	 * Add cart & checkout features to the structure
	 *
	 * @since 3.0.0
	 * @return void
	 */
	private function add_cart_settings(): void {
		/**
		 * Action before adding cart settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_cart_settings', $this->structure );

		$tab = Factory::section( 'cart' )->set_title( esc_html__( 'Cart & Checkout', 'dokan-kits' ) )->set_icon( 'dashicons-cart' );

		/**
		 * Filter cart section
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The cart section.
		 */
		$tab = apply_filters( 'dokan_kits_cart_tab', $tab );

		do_action( 'dokan_kits_cart_tab_before_field_definitions', $tab, $this->structure );

		// Cart Buttons.
		$sub_section = Factory::sub_section( 'buttons' )
			->set_title( esc_html__( 'Cart Buttons', 'dokan-kits' ) )
			->set_description( esc_html__( 'Control the visibility and functionality of cart buttons to enhance the shopping experience.', 'dokan-kits' ) );

		/**
		 * Filter cart buttons subsection
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The cart buttons subsection.
		 */
		$sub_section = apply_filters( 'dokan_kits_cart_buttons_subsection', $sub_section );

		/**
		 * Action before adding cart button fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The cart buttons subsection.
		 */
		do_action( 'dokan_kits_before_add_cart_button_fields', $sub_section );

		$sub_section->add(
			Factory::field( 'hide_add_to_cart_button_checkbox', 'toggle' )
				->set_title( esc_html__( 'Hide Add to Cart Button', 'dokan-kits' ) )
				->set_description( esc_html__( 'Hide the Add to Cart button from WooCommerce product pages.', 'dokan-kits' ) )
				->set_default( false )
				->set_dependency_key( 'cart.buttons.hide_add_to_cart_button_checkbox' )
		);

		/**
		 * Action after adding cart button fields
		 *
		 * @since 3.0.0
		 *
		 * @param object $sub_section The cart buttons subsection.
		 */
		do_action( 'dokan_kits_after_add_cart_button_fields', $sub_section );

		$tab->add( $sub_section );

		/**
		 * Action for adding additional cart subsections
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The cart section.
		 */
		do_action( 'dokan_kits_add_cart_subsections', $tab );

		/**
		 * Action before adding cart section to structure
		 *
		 * @since 3.0.0
		 *
		 * @param object $tab The cart section.
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_before_add_cart_section', $tab, $this->structure );

		$this->structure->add( $tab );

		/**
		 * Action after adding cart settings
		 *
		 * @since 3.0.0
		 *
		 * @param object $structure The settings structure.
		 */
		do_action( 'dokan_kits_after_add_cart_settings', $this->structure );
	}

	/**
	 * Get feature counts for each section and total
	 *
	 * @since 3.0.0
	 * @return array
	 */
	public function get_feature_counts(): array {
		$features = dokan_kits_get_container()->get( 'feature-service' );
		$counts   = array(
			'total'    => 0,
			'sections' => array(),
			'groups'   => array(),
		);

		foreach ( $features as $feature ) {
			$group   = $feature->get_settings_group();
			$section = $feature->get_settings_section();
			$total   = $feature->get_total_features();

			// Increment total.
			$counts['total'] += $total;

			// Count by section.
			if ( ! isset( $counts['sections'][ $section ] ) ) {
				$counts['sections'][ $section ] = 0;
			}
			$counts['sections'][ $section ] += $total;

			// Count by group.
			if ( ! isset( $counts['groups'][ $group ] ) ) {
				$counts['groups'][ $group ] = 0;
			}
			$counts['groups'][ $group ] += $total;
		}

		return $counts;
	}

	/**
	 * Get feature count for a specific group
	 *
	 * Returns the number of features available in the specified group.
	 * This is used for displaying counts in the admin interface and
	 * for statistical purposes.
	 *
	 * @since 3.0.0
	 * @access public
	 *
	 * @param string $group_name The name of the group to count features for.
	 *
	 * @return int Number of features in the group.
	 */
	public function get_group_count( string $group_name ): int {
		$counts = $this->get_feature_counts();

		return $counts['groups'][ $group_name ] ?? 0;
	}

	/**
	 * Get section count
	 *
	 * @since 3.0.0
	 *
	 * @param string $section_name The section name.
	 *
	 * @return int
	 */
	public function get_section_count( string $section_name ): int {
		$counts = $this->get_feature_counts();

		return $counts['sections'][ $section_name ] ?? 0;
	}

	/**
	 * Get feature settings configuration
	 *
	 * Returns the complete settings configuration array for all features
	 * on the features page.
	 *
	 * @since 3.0.0
	 * @access public
	 *
	 * @return array Settings configuration array.
	 */
	public function settings(): array {
		return $this->structure->populate();
	}

	/**
	 * Get scripts for the features page.
	 *
	 * @inheritDoc
	 */
	public function scripts(): array {
		return array( 'dokan-kits-dashboard-app' );
	}

	/**
	 * Get the styles.
	 *
	 * @since 4.0.0
	 *
	 * @return array<string> An array of style handles.
	 */
	public function styles(): array {
		return array( 'dokan-kits-dashboard-app' );
	}

	/**
	 * Register the page scripts and styles.
	 *
	 * @since 4.0.0
	 *
	 * @return void
	 */
	public function register(): void {
	}
}
