<?php

if ( !defined( 'ABSPATH' ) ) {
    exit;
}

if ( !class_exists( 'Reon' ) ) {
    return;
}

if ( !class_exists( 'Pricely_Admin_Product_Promotion_Type_Label' ) ) {

    class Pricely_Admin_Product_Promotion_Type_Label {

        public function __construct() {

            add_filter( 'pricely_admin_product-promotions_get-main-promotion-types', array( $this, 'get_types' ), 120, 2 );

            add_filter( 'pricely_admin_product-promotions_get-promotion-type-label-fields', array( $this, 'get_fields' ), 120, 2 );
        }

        public function get_types( $in_options, $args = array() ) {

            $in_options[ 'label' ] = array(
                'title' => esc_html__( 'Product Label', 'pricely-dynamic-pricing-cart-discounts' ),
            );

            return $in_options;
        }

        public function get_fields( $in_fields, $args ) {

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 3,
                'merge_fields' => false,
                'field_css_class' => array( 'rn-first' ),
                'fields' => $this->get_panel_fields( $args ),
            );

            $in_fields[] = array(
                'id' => 'shop',
                'type' => 'columns-field',
                'columns' => 8,
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Shop Loops', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( "Use these settings to configure the display options for the product label in shop loops", 'pricely-dynamic-pricing-cart-discounts' ),
                'field_css_class' => array( 'pricely_positions_title' ),
                'merge_fields' => true,
                'fields' => $this->get_shop_panel_fields( $args ),
            );

            $in_fields[] = array(
                'id' => 'single_product',
                'type' => 'columns-field',
                'columns' => 8,
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Product Summary', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( "Use these settings to configure the display options for the product label in product summary area", 'pricely-dynamic-pricing-cart-discounts' ),
                'field_css_class' => array( 'pricely_positions_title' ),
                'merge_fields' => true,
                'fields' => $this->get_product_panel_fields( $args ),
            );

            $in_fields[] = array(
                'id' => 'variatio_arg_any_id',
                'type' => 'columns-field',
                'columns' => 1,
                'full_width' => true,
                'center_head' => true,
                'merge_fields' => false,
                'fields' => $this->get_variation_view_args_fields(),
                'fold' => array(
                    'target' => 'product_label_enable',
                    'attribute' => 'value',
                    'value' => array( 'yes' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            return $in_fields;
        }

        private function get_panel_fields( $args ) {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'mode',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Display Mode', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Specify what should be displayed as text on the label", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'text',
                'options' => array(
                    'text' => esc_html__( 'Plain text', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
                'fold_id' => 'label_mode',
            );

            $in_fields[] = array(
                'id' => 'text',
                'type' => 'textbox',
                'column_size' => 1,
                'column_title' => esc_html__( 'Text', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Specify the text to be displayed on the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => esc_html__( 'Special Deal!', 'pricely-dynamic-pricing-cart-discounts' ),
                'placeholder' => esc_html__( 'Type here...', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fold' => array(
                    'target' => 'label_mode',
                    'attribute' => 'value',
                    'value' => array( 'text' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'remove_prev',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Replace Previous Labels', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Choose whether to remove previous labels or display them', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'yes',
                'options' => array(
                    'yes' => esc_html__( 'Yes', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            return $in_fields;
        }

        private function get_shop_panel_fields( $args ) {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'enable',
                'type' => 'select2',
                'column_size' => 2,
                'column_title' => esc_html__( 'Show In Shop Loops', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Specify whether the product label should be shown in shop loops', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'yes',
                'options' => array(
                    'yes' => esc_html__( 'Yes', 'pricely-dynamic-pricing-cart-discounts' ),
                    'no' => esc_html__( 'No', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
                'fold_id' => 'shop_label_enable',
            );

            $in_fields[] = array(
                'id' => 'position',
                'type' => 'select2',
                'column_size' => 3,
                'column_title' => esc_html__( 'Shop Loops - Position', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Choose the display position of the product label in the shop loops", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '',
                'data' => 'pricely:view_positions:shop',
                'width' => '100%',
                'fold' => array(
                    'target' => 'shop_label_enable',
                    'attribute' => 'value',
                    'value' => array( 'yes' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'ui_id',
                'type' => 'select2',
                'column_size' => 3,
                'column_title' => esc_html__( 'Shop Loops - UI Design', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Select a UI design for the product label in the shop loops", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '2234343',
                'data' => 'pricely:label_designs',
                'width' => '100%',
                'fold' => array(
                    'target' => 'shop_label_enable',
                    'attribute' => 'value',
                    'value' => array( 'yes' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            return $in_fields;
        }

        private function get_product_panel_fields( $args ) {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'enable',
                'type' => 'select2',
                'column_size' => 2,
                'column_title' => esc_html__( 'Show In Product Summary', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Specify whether the product label should be shown in product summary area', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'no',
                'options' => array(
                    'yes' => esc_html__( 'Yes', 'pricely-dynamic-pricing-cart-discounts' ),
                    'no' => esc_html__( 'No', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
                'fold_id' => 'product_label_enable',
            );

            $in_fields[] = array(
                'id' => 'position',
                'type' => 'select2',
                'column_size' => 3,
                'column_title' => esc_html__( 'Product Summary - Position', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Choose the display position of the product label in the product summary area", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '',
                'data' => 'pricely:view_positions:single-product',
                'width' => '100%',
                'fold' => array(
                    'target' => 'product_label_enable',
                    'attribute' => 'value',
                    'value' => array( 'yes' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'ui_id',
                'type' => 'select2',
                'column_size' => 3,
                'column_title' => esc_html__( 'Product Summary - UI Design', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Select a UI design for the product label in the product summary area", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '2234343',
                'data' => 'pricely:label_designs',
                'width' => '100%',
                'fold' => array(
                    'target' => 'product_label_enable',
                    'attribute' => 'value',
                    'value' => array( 'yes' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            return $in_fields;
        }

        private function get_variation_view_args_fields() {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'variation_view_mode',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Variations - Label Display', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Choose whether variation label values should be shown', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'combined',
                'options' => array(
                    'combined' => esc_html__( 'Display combined label values', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            return $in_fields;
        }

    }

    new Pricely_Admin_Product_Promotion_Type_Label();
}