<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Settings_Styles_Label_Settings' ) ) {

    class Pricely_Admin_Settings_Styles_Label_Settings {

        private $admin_utils;

        public function __construct() {

            add_filter( 'pricely_admin_get-settings-styles-section-panels', array( $this, 'get_panel' ), 90 );

            add_filter( 'reon_get-repeater-field-pricely_labels-templates', array( $this, 'get_templates' ), 10, 2 );

            add_filter( 'reon_get-repeater-template-pricely_labels-ui_default-fields', array( $this, 'get_template_fields' ), 10, 2 );
            add_filter( 'reon_get-repeater-template-pricely_labels-ui_option-fields', array( $this, 'get_template_fields' ), 10, 2 );
        }

        public function get_panel( $in_fields ) {

            $this->init_settings();

            $in_fields[] = array(
                'id' => 'any_id',
                'type' => 'panel',
                'last' => true,
                'white_panel' => false,
                'panel_size' => 'smaller',
                'field_css_class' => array( 'pricely_setting_panel' ),
                'css_class' => array( 'rn-round-small' ),
                'width' => '100%',
                'merge_fields' => false,
                'fields' => $this->get_fields( array() ),
            );

            return $in_fields;
        }

        public function get_templates( $in_templates, $repeater_args ) {

            $in_templates[] = array(
                'id' => 'ui_default',
                'head' => array(
                    'title' => '',
                    'defaut_title' => esc_html__( 'Product Label', 'pricely-dynamic-pricing-cart-discounts' ),
                    'title_field' => 'admin_note',
                ),
                'empy_button' => true,
            );

            $in_templates[] = array(
                'id' => 'ui_option',
                'head' => array(
                    'title' => '',
                    'defaut_title' => esc_html__( 'Product Label', 'pricely-dynamic-pricing-cart-discounts' ),
                    'title_field' => 'admin_note',
                ),
            );

            return $in_templates;
        }

        public function get_template_fields( $in_fields, $repeater_args ) {

            $in_fields[] = array(
                'id' => 'ui_id',
                'type' => 'autoid',
                'autoid' => 'pricely_ui',
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 1,
                'full_width' => true,
                'merge_fields' => false,
                'fields' => $this->admin_note_fields( array() ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 5,
                'full_width' => true,
                'center_head' => true,
                'merge_fields' => false,
                'title' => esc_html__( 'Design Settings', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( 'Use these settings to control the look and feel of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'field_css_class' => array( 'pricely_subtitles' ),
                'fields' => $this->design_fields( array() ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 3,
                'full_width' => true,
                'merge_fields' => false,
                'fields' => $this->design_two_fields( array() ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 5,
                'full_width' => true,
                'center_head' => true,
                'merge_fields' => false,
                'field_css_class' => array( 'pricely_subtitles' ),
                'fields' => $this->design_three_fields( array() ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 3,
                'merge_fields' => false,
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Text Settings', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( 'Use these settings to control the text settings', 'pricely-dynamic-pricing-cart-discounts' ),
                'field_css_class' => array( 'pricely_subtitles' ),
                'fields' => $this->get_text_fields( array() ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 3,
                'merge_fields' => false,
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Icon Settings', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( 'Use these settings to control the icon settings', 'pricely-dynamic-pricing-cart-discounts' ),
                'field_css_class' => array( 'pricely_subtitles' ),
                'fields' => $this->get_icon_fields( array() ),
            );

            return $in_fields;
        }

        private function get_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'any_id',
                'type' => 'paneltitle',
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Product Label - Designs', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( 'Use these settings to create and manage product label designs', 'pricely-dynamic-pricing-cart-discounts' ),
            );

            $in_fields[] = array(
                'id' => 'ui_labels',
                'filter_id' => 'pricely_labels',
                'type' => 'repeater',
                'white_repeater' => true,
                'repeater_size' => 'smaller',
                'accordions' => true,
                'buttons_sep' => false,
                'delete_button' => true,
                'clone_button' => false,
                'width' => '100%',
                'css_class' => array( 'rn-round-small' ),
                'default' => $this->get_default_ui(),
                'static_template' => 'ui_default',
                'section_type_id' => 'option_type',
                'auto_expand' => array(
                    'new_section' => true,
                    'cloned_section' => false,
                ),
                'sortable' => array(
                    'enabled' => false,
                ),
                'template_adder' => array(
                    'position' => 'right',
                    'show_list' => false,
                    'button_text' => esc_html__( 'New Design', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
            );

            return $in_fields;
        }

        private function admin_note_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'admin_note',
                'type' => 'textbox',
                'tooltip' => esc_html__( 'Adds a private note for reference purposes', 'pricely-dynamic-pricing-cart-discounts' ),
                'column_size' => 1,
                'column_title' => esc_html__( 'Admin Note', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '',
                'placeholder' => esc_html__( 'Type here...', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
            );

            return $in_fields;
        }

        private function design_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'layout',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Layout', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the text and icon layout mode', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'inline',
                'options' => array(
                    'inline' => esc_html__( 'Inline', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            $in_fields[] = array(
                'id' => 'width',
                'type' => 'group-field',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_size' => 1,
                'column_title' => esc_html__( 'Width', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Determines the width of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_size_fields( array( 'default_size' => '', 'placeholder' => 'auto' ) ),
            );

            $in_fields[] = array(
                'id' => 'height',
                'type' => 'group-field',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_size' => 1,
                'column_title' => esc_html__( 'Height', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Determines the height of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_size_fields( array( 'default_size' => '', 'placeholder' => 'auto' ) ),
            );

            $in_fields[] = array(
                'id' => 'color',
                'type' => 'colorpicker',
                'column_size' => 1,
                'column_title' => esc_html__( 'Color', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the text and icon color of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => $this->admin_utils->get_theme_value( 'color_5' ),
                'buton_text' => esc_html__( 'Pick color', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
            );

            $in_fields[] = array(
                'id' => 'bg_color',
                'type' => 'colorpicker',
                'column_size' => 1,
                'column_title' => esc_html__( 'Background Color', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the background color of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => $this->admin_utils->get_theme_value( 'accent_color_4' ),
                'buton_text' => esc_html__( 'Pick color', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
            );

            return $in_fields;
        }

        private function design_two_fields( $in_fields ) {


            $in_fields[] = array(
                'id' => 'margin',
                'type' => 'group-field',
                'column_no_size' => true,
                'merge_fields' => true,
                'fluid-group' => true,
                'column_title' => esc_html__( 'Margin', 'pricely-dynamic-pricing-cart-discounts' ),
                'column_classes' => array( 'pricely_box_hint' ),
                'tooltip' => esc_html__( 'Determines the margins of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_boundary_sizes_fields( array( 'default_size' => array( 'top' => '', 'right' => '', 'bottom' => 5, 'left' => '' ), 'placeholder' => '', 'default_unit' => 'px' ) ),
            );

            $in_fields[] = array(
                'id' => 'padding',
                'type' => 'group-field',
                'column_no_size' => true,
                'merge_fields' => true,
                'fluid-group' => true,
                'column_title' => esc_html__( 'Padding', 'pricely-dynamic-pricing-cart-discounts' ),
                'column_classes' => array( 'pricely_box_hint' ),
                'tooltip' => esc_html__( 'Determines the paddings of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_boundary_sizes_fields( array( 'default_size' => array( 'top' => 8, 'right' => 10, 'bottom' => 8, 'left' => 10 ), 'placeholder' => '', 'default_unit' => 'px' ) ),
            );


            return $in_fields;
        }

        private function design_three_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'border_radius',
                'type' => 'group-field',
                'column_width' => '170px',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_title' => esc_html__( 'Border Radius', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Determines the border radius of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_size_fields( array( 'default_size' => '4', 'default_unit' => 'px' ) ),
            );

            $in_fields[] = array(
                'id' => 'border_style',
                'type' => 'select2',
                'column_no_size' => true,
                'column_title' => esc_html__( 'Border Style', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Determines the border style of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'inline',
                'options' => array(
                    'none' => esc_html__( 'None', 'pricely-dynamic-pricing-cart-discounts' ),
                    'solid' => esc_html__( 'Solid', 'pricely-dynamic-pricing-cart-discounts' ),
                    'dotted' => esc_html__( 'Dotted', 'pricely-dynamic-pricing-cart-discounts' ),
                    'dashed' => esc_html__( 'Dashed', 'pricely-dynamic-pricing-cart-discounts' )
                ),
                'width' => '100%',
                'column_attributes' => array(
                    'style' => 'min-width:170px;'
                ),
                'fold_id' => 'label_border_style',
            );

            $in_fields[] = array(
                'id' => 'border_color',
                'type' => 'colorpicker',
                'column_no_size' => true,
                'column_title' => esc_html__( 'Border Color', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the border color of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => $this->admin_utils->get_theme_value( 'color_2' ),
                'buton_text' => esc_html__( 'Pick color', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'column_attributes' => array(
                    'style' => 'min-width:170px;'
                ),
                'fold' => array(
                    'target' => 'label_border_style',
                    'attribute' => 'value',
                    'value' => array( 'none' ),
                    'oparator' => 'neq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'border_width',
                'type' => 'group-field',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_no_size' => true,
                'column_title' => esc_html__( 'Border Width', 'pricely-dynamic-pricing-cart-discounts' ),
                'column_classes' => array( 'pricely_box_hint' ),
                'tooltip' => esc_html__( 'Controls the border thickness of the label', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_boundary_sizes_fields( array( 'default_size' => 1, 'default_unit' => 'px' ) ),
                'fold' => array(
                    'target' => 'label_border_style',
                    'attribute' => 'value',
                    'value' => array( 'none' ),
                    'oparator' => 'neq',
                    'clear' => false,
                ),
            );

            return $in_fields;
        }

        private function get_text_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'font_size',
                'type' => 'group-field',
                'column_width' => '170px',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_title' => esc_html__( 'Font Size', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the font size of the text', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_size_fields( array( 'default_size' => 14, 'default_unit' => 'px' ) ),
            );

            $in_fields[] = array(
                'id' => 'line_height',
                'type' => 'group-field',
                'column_width' => '170px',
                'merge_fields' => true,
                'fluid-group' => true,
                'column_title' => esc_html__( 'Line Height', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Controls the line height of the text', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'fields' => $this->admin_utils->get_size_fields( array( 'default_size' => 13, 'default_unit' => 'px' ) ),
            );

            return $in_fields;
        }

        private function get_icon_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'icon_type',
                'type' => 'select2',
                'column_width' => '250px',
                'column_title' => esc_html__( 'Icon Type', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Determines the type of icon', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'no',
                'options' => array(
                    'no' => esc_html__( 'No icon', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            return $in_fields;
        }

        private function get_default_ui() {

            return array(
                array(
                    'option_type' => 'ui_default',
                    'ui_id' => '2234343',
                ),
            );
        }

        private function init_settings() {

            $this->admin_utils = Pricely_Admin_Utils::get_instance();
        }

    }

    new Pricely_Admin_Settings_Styles_Label_Settings();
}
