<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\Fields;

use DropshippingExportFreeVendor\WPDesk\Forms\Field\InputTextField;
use DropshippingExportFreeVendor\WPDesk\Forms\Field\NoOnceField;
use DropshippingExportFreeVendor\WPDesk\Forms\Field\SubmitField;
use DropshippingExportFreeVendor\WPDesk\Forms\FieldProvider;
use DropshippingExportFreeVendor\WPDesk\Forms\Field\SelectField;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\Fields\Component\AdvancedLogicComponent;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\Fields\Component\ConditionalLogicComponent;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\ContainsCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\EqualCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\HigherCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\LowerCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\NotContainsCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\NotEqualCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsInCategoryCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsNotInCategoryCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsInTagCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsNotInTagCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Modificator\Value\FixedValueModificator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Modificator\Value\PercentValueModificator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\Fields\Component\PriceCompareProductFieldsComponent;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\ProductFieldsValueFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\NokautConfig;
class NokautExportMapperFormFields implements FieldProvider
{
    public const NONCE_ACTION = 'product_mapper_action';
    public const NONCE_NAME = 'product_mapper_nonce';
    public const SUBMIT_NEXT_STEP = 'next_step';
    public const PRODUCT_FIELDS = 'product_fields';
    public const PRODUCT_ATTRIBUTES_SELECT = 'product_attributes_select';
    public const PRODUCT_ATTRIBUTES_SELECT_VALUE_NONE = 'none';
    public const PRODUCT_ATTRIBUTES_SELECT_VALUE_ALL = 'all';
    public const PRODUCT_ATTRIBUTES_VALUES = 'product_attributes_values';
    public const PRODUCT_ATTRIBUTES_AS_SINGLE_VALUE = 'product_attributes_as_single_value';
    public const PRODUCT_FILTER = 'product_filter';
    public const PRODUCT_ADVANCED_PRICE_MOD = 'product_advanced_price_mod';
    public const PRODUCT_ADVANCED_STOCK_MOD = 'product_advanced_stock_mod';
    public const PRODUCT_ADVANCED_MOD_TYPE = 'product_advanced_mod_type';
    public const PRODUCT_ADVANCED_MOD_LOGIC = 'product_advanced_mod_logic';
    public const PRODUCT_ADVANCED_MOD_LOGIC_VALUE = 'product_advanced_mod_logic_value';
    public const PRODUCT_ADVANCED_MOD_MATH = 'product_advanced_mod_logic_math';
    public const PRODUCT_ADVANCED_MOD_MATH_VALUE = 'product_advanced_mod_logic_math_value';
    private NokautConfig $nokaut_config;
    private ProductFieldsValueFactory $product_fields_value_factory;
    public function __construct(NokautConfig $nokaut_config, ProductFieldsValueFactory $product_fields_value_factory)
    {
        $this->nokaut_config = $nokaut_config;
        $this->product_fields_value_factory = $product_fields_value_factory;
    }
    /**
     * @see FieldProvider::get_fields()
     */
    public function get_fields()
    {
        $fields = array_merge($this->get_default_fields(), $this->get_product_fields_for_table(), $this->get_advanced_logic_components());
        return $fields;
    }
    private function get_advanced_logic_components(): array
    {
        return [(new AdvancedLogicComponent())->set_label(__('Price modifier', 'dropshipping-export-free'))->set_name(self::PRODUCT_ADVANCED_PRICE_MOD)->set_items([(new SelectField())->set_name(self::PRODUCT_ADVANCED_MOD_TYPE)->add_class('width-100 product-field')->set_options(ConditionalLogicComponent::get_export_options()), (new SelectField())->set_name(self::PRODUCT_ADVANCED_MOD_LOGIC)->add_class('width-100 conditional-value-type')->set_options(ConditionalLogicComponent::get_value_types()), (new InputTextField())->add_class('width-100')->set_name(EqualCondition::get_name())->set_attribute('data-value', EqualCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(NotEqualCondition::get_name())->set_attribute('data-value', NotEqualCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(HigherCondition::get_name())->set_attribute('data-value', HigherCondition::get_name())->set_placeholder(__('Numeric value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(LowerCondition::get_name())->set_attribute('data-value', LowerCondition::get_name())->set_placeholder(__('Numeric value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(ContainsCondition::get_name())->set_attribute('data-value', ContainsCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(NotContainsCondition::get_name())->set_attribute('data-value', NotContainsCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new SelectField())->set_name(IsInCategoryCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsInCategoryCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_categories()), (new SelectField())->set_name(IsNotInCategoryCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsNotInCategoryCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_categories()), (new SelectField())->set_name(IsInTagCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsInTagCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_tags()), (new SelectField())->set_name(IsNotInTagCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsNotInTagCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_tags()), (new SelectField())->set_label(__('modify price by', 'dropshipping-export-free'))->add_class('width-100')->set_name(self::PRODUCT_ADVANCED_MOD_MATH)->set_options(self::get_math_options()), (new InputTextField())->set_name(self::PRODUCT_ADVANCED_MOD_MATH_VALUE)->add_class('width-100')->set_placeholder(__('Value', 'dropshipping-export-free'))]), (new AdvancedLogicComponent())->set_label(__('Stock modifier', 'dropshipping-export-free'))->set_name(self::PRODUCT_ADVANCED_STOCK_MOD)->set_items([(new SelectField())->set_name(self::PRODUCT_ADVANCED_MOD_TYPE)->add_class('width-100 product-field')->set_options(ConditionalLogicComponent::get_export_options()), (new SelectField())->set_name(self::PRODUCT_ADVANCED_MOD_LOGIC)->add_class('width-100 conditional-value-type')->set_options(ConditionalLogicComponent::get_value_types()), (new InputTextField())->add_class('width-100')->set_name(EqualCondition::get_name())->set_attribute('data-value', EqualCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(NotEqualCondition::get_name())->set_attribute('data-value', NotEqualCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(HigherCondition::get_name())->set_attribute('data-value', HigherCondition::get_name())->set_placeholder(__('Numeric value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(LowerCondition::get_name())->set_attribute('data-value', LowerCondition::get_name())->set_placeholder(__('Numeric value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(ContainsCondition::get_name())->set_attribute('data-value', ContainsCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new InputTextField())->add_class('width-100')->set_name(NotContainsCondition::get_name())->set_attribute('data-value', NotContainsCondition::get_name())->set_placeholder(__('String or value', 'dropshipping-export-free')), (new SelectField())->set_name(IsInCategoryCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsInCategoryCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_categories()), (new SelectField())->set_name(IsNotInCategoryCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsNotInCategoryCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_categories()), (new SelectField())->set_name(IsInTagCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsInTagCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_tags()), (new SelectField())->set_name(IsNotInTagCondition::get_name())->add_class('dropshipping-select2-multi width-100')->set_multiple()->set_attribute('type', 'select')->set_attribute('data-value', IsNotInTagCondition::get_name())->set_options(ConditionalLogicComponent::get_woocommerce_tags()), (new SelectField())->set_label(__('modify stock by', 'dropshipping-export-free'))->add_class('width-100 field-disabled')->set_name(self::PRODUCT_ADVANCED_MOD_MATH)->set_readonly()->set_options(self::get_fixed_math_options()), (new InputTextField())->set_name(self::PRODUCT_ADVANCED_MOD_MATH_VALUE)->add_class('width-100')->set_placeholder(__('Value', 'dropshipping-export-free'))])];
    }
    public static function get_math_options(): array
    {
        return \array_merge([PercentValueModificator::get_name() => PercentValueModificator::get_nice_name()], self::get_fixed_math_options());
    }
    public static function get_fixed_math_options(): array
    {
        return [FixedValueModificator::get_name() => FixedValueModificator::get_nice_name()];
    }
    private function get_default_fields(): array
    {
        return [(new SubmitField())->set_name(self::SUBMIT_NEXT_STEP)->set_label(__('Go to the next step &rarr;', 'dropshipping-export-free'))->add_class('button button-primary button-hero button-mapper')->set_attribute('id', self::SUBMIT_NEXT_STEP), (new NoOnceField(self::NONCE_ACTION))->set_name(self::NONCE_NAME)];
    }
    private function get_product_fields_for_table(): array
    {
        return [(new PriceCompareProductFieldsComponent($this->product_fields_value_factory))->set_product_fields($this->nokaut_config->get_supported_fields())];
    }
}
