<?php

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

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

if ( !class_exists( 'Pricely_Admin_Checkout_Prices_Panel_Max' ) ) {

    class Pricely_Admin_Checkout_Prices_Panel_Max {

        public function __construct() {

            add_filter( 'pricely_admin_checkout-pricing_get-panels', array( $this, 'get_panel' ), 30 );

            add_filter( 'pricely_admin_checkout-pricing_process-pricing-options', array( $this, 'process_options' ), 200, 3 );
        }

        public function get_panel( $in_fields ) {

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

            return $in_fields;
        }

        public function process_options( $options, $raw_options, $args ) {

            if ( isset( $raw_options[ 'limit' ] ) ) {

                $options[ 'limit' ] = $raw_options[ 'limit' ];
            }

            return $options;
        }

        private function get_panel_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'limit',
                'type' => 'columns-field',
                'columns' => 11,
                'merge_fields' => true,
                'fields' => $this->get_fields( array() ),
            );

            return $in_fields;
        }

        private function get_fields( $in_fields ) {

            $currency = get_woocommerce_currency_symbol( get_woocommerce_currency() );

            $in_fields[] = array(
                'id' => 'limit_type',
                'type' => 'select2',
                'column_size' => 3,
                'column_title' => esc_html__( 'Pricing Limit', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Choose whether pricing should be limited to a specific amount', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => 'no',
                'disabled_list_filter' => 'pricely_admin_get-disabled-grouped-list',
                'options' => array(
                    'no' => esc_html__( 'No pricing limit', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );


            return $in_fields;
        }

    }

    new Pricely_Admin_Checkout_Prices_Panel_Max();
}