<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Utils' ) ) {


    class Pricely_Admin_Utils {

        private static $instance = null;

        public static function get_instance(): self {

            if ( null == self::$instance ) {

                self::$instance = new self();
            }

            return self::$instance;
        }

        public function get_size_fields( $args = array() ) {

            if ( !isset( $args[ 'default_size' ] ) ) {
                $args[ 'default_size' ] = 12;
            }

            if ( !isset( $args[ 'default_unit' ] ) ) {
                $args[ 'default_unit' ] = 'px';
            }

            if ( !isset( $args[ 'placeholder' ] ) ) {
                $args[ 'placeholder' ] = esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' );
            }

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'size',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $args[ 'default_size' ],
                'placeholder' => $args[ 'placeholder' ],
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '55%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field-first' )
            );

            $in_fields[] = array(
                'id' => 'unit',
                'type' => 'select2',
                'default' => $args[ 'default_unit' ],
                'options' => array(
                    'rem' => esc_html__( 'rem', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vh' => esc_html__( 'vh', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vw' => esc_html__( 'vw', 'pricely-dynamic-pricing-cart-discounts' ),
                    'em' => esc_html__( 'em', 'pricely-dynamic-pricing-cart-discounts' ),
                    'px' => esc_html__( 'px', 'pricely-dynamic-pricing-cart-discounts' ),
                    '%' => esc_html__( '%', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
                'box_width' => '45%',
                'box_css_class' => array( 'rn-merge-field-last' )
            );

            return $in_fields;
        }

        public function get_boundary_sizes_fields( $args = array() ) {

            $default_sizes = array(
                'top' => '',
                'right' => '',
                'bottom' => '',
                'left' => '',
            );

            if ( isset( $args[ 'default_size' ] ) && is_array( $args[ 'default_size' ] ) ) {

                $default_sizes = $args[ 'default_size' ];
            } else if ( isset( $args[ 'default_size' ] ) ) {

                $default_sizes[ 'top' ] = $args[ 'default_size' ];
                $default_sizes[ 'right' ] = $args[ 'default_size' ];
                $default_sizes[ 'bottom' ] = $args[ 'default_size' ];
                $default_sizes[ 'left' ] = $args[ 'default_size' ];
            }

            if ( !isset( $args[ 'default_unit' ] ) ) {
                $args[ 'default_unit' ] = 'px';
            }

            if ( !isset( $args[ 'placeholder' ] ) ) {
                $args[ 'placeholder' ] = esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' );
            }

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'top',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'top' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'TOP', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '20%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field-first' )
            );

            $in_fields[] = array(
                'id' => 'right',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'right' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'RIGHT', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '20%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field' )
            );

            $in_fields[] = array(
                'id' => 'bottom',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'bottom' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'BOTTOM', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '20%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field' )
            );

            $in_fields[] = array(
                'id' => 'left',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'left' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'LEFT', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '20%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field' )
            );

            $in_fields[] = array(
                'id' => 'unit',
                'type' => 'select2',
                'default' => $args[ 'default_unit' ],
                'options' => array(
                    'rem' => esc_html__( 'rem', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vh' => esc_html__( 'vh', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vw' => esc_html__( 'vw', 'pricely-dynamic-pricing-cart-discounts' ),
                    'em' => esc_html__( 'em', 'pricely-dynamic-pricing-cart-discounts' ),
                    'px' => esc_html__( 'px', 'pricely-dynamic-pricing-cart-discounts' ),
                    '%' => esc_html__( '%', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'box_width' => '20%',
                'width' => '100%',
                'box_css_class' => array( 'rn-merge-field-last' )
            );

            return $in_fields;
        }
        
        public function get_two_sides_sizes_fields( $args = array() ) {

            $default_sizes = array(
                'top_bottom' => '',
                'left_right' => '',
            );

            if ( isset( $args[ 'default_size' ] ) && is_array( $args[ 'default_size' ] ) ) {

                $default_sizes = $args[ 'default_size' ];
            } else if ( isset( $args[ 'default_size' ] ) ) {

                $default_sizes[ 'top_bottom' ] = $args[ 'default_size' ];
                $default_sizes[ 'left_right' ] = $args[ 'default_size' ];
            }

            if ( !isset( $args[ 'default_unit' ] ) ) {
                $args[ 'default_unit' ] = 'px';
            }

            if ( !isset( $args[ 'placeholder' ] ) ) {
                $args[ 'placeholder' ] = esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' );
            }

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'top_bottom',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'top_bottom' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'TOP BOTTOM', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '35%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field-first' )
            );

            $in_fields[] = array(
                'id' => 'left_right',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => $default_sizes[ 'left_right' ],
                'placeholder' => $args[ 'placeholder' ],
                'tooltip' => array(
                    'title' => esc_html__( 'LEFT RIGHT', 'pricely-dynamic-pricing-cart-discounts' ),
                    'is_bottom' => true,
                ),
                'attributes' => array(
                    'step' => '1',
                ),
                'box_width' => '35%',
                'width' => '102%',
                'box_css_class' => array( 'rn-merge-field' )
            );

            $in_fields[] = array(
                'id' => 'unit',
                'type' => 'select2',
                'default' => $args[ 'default_unit' ],
                'options' => array(
                    'rem' => esc_html__( 'rem', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vh' => esc_html__( 'vh', 'pricely-dynamic-pricing-cart-discounts' ),
                    'vw' => esc_html__( 'vw', 'pricely-dynamic-pricing-cart-discounts' ),
                    'em' => esc_html__( 'em', 'pricely-dynamic-pricing-cart-discounts' ),
                    'px' => esc_html__( 'px', 'pricely-dynamic-pricing-cart-discounts' ),
                    '%' => esc_html__( '%', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'box_width' => '30%',
                'width' => '100%',
                'box_css_class' => array( 'rn-merge-field-last' )
            );

            return $in_fields;
        }

        public function get_theme_value( $key ) {

            $theme_values = array(
                'accent_color_1' => '#ffc000',
                'accent_color_2' => '#ff0',
                'accent_color_3' => '#efa400',
                'accent_color_4' => '#57bf6d',
                'color_1' => '#222',
                'color_2' => '#999',
                'color_3' => '#ddd',
                'color_4' => '#eee',
                'color_5' => '#fff',
            );

            return $theme_values[ $key ];
        }

    }

}