<?php

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

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

if ( !class_exists( 'Pricely_Admin_Product_Prices_Panel' ) ) {

    class Pricely_Admin_Product_Prices_Panel {

        public function __construct() {

            add_filter( 'pricely_admin_product-pricing_get-panels', array( $this, 'get_panel' ), 10 );
            add_filter( 'pricely_admin_product-pricing_get-panel-fields', array( $this, 'get_panel_fields' ), 10 );
        }

        public function get_panel( $in_fields ) {

            $in_fields[] = array(
                'id' => 'pricing_id',
                'type' => 'autoid',
                'autoid' => 'pricely',
            );


            $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_first_panel' ),
                'css_class' => array( 'rn-round-small-top' ),
                'fields' => $this->get_basic_fields( $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_lone_panel' ),
                'fields' => apply_filters( 'pricely_admin_product-pricing_get-panel-fields', array() ),
            );


            return $in_fields;
        }

        public function get_panel_fields( $in_fields ) {

            return apply_filters( 'pricely_admin_product-pricing_get-panel-option-fields', $in_fields );
        }

        private function get_basic_fields( $in_fields ) {

            $pricing_types = Pricely_Admin_Product_Prices_Types::get_instance();

            $args = array(
                'module' => 'product-pricing',
            );

            $mode_types = $pricing_types->get_modes( $args );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 5,
                'merge_fields' => false,
                'fields' => array(
                    array(
                        'id' => 'mode',
                        'type' => 'select2',
                        'column_size' => 2,
                        'column_title' => esc_html__( 'Adjustment Method', 'pricely-dynamic-pricing-cart-discounts' ),
                        'tooltip' => esc_html__( "Specify which product's price should be adjusted", 'pricely-dynamic-pricing-cart-discounts' ),
                        'default' => 'sale',
                        'disabled_list_filter' => 'pricely_admin_get-disabled-list',
                        'options' => $mode_types,
                        'width' => '100%',
                        'fold_id' => 'product_prices_mode',
                    ),
                    array(
                        'id' => 'admin_note',
                        'type' => 'textbox',
                        'tooltip' => esc_html__( 'Adds a private note for reference purposes', 'pricely-dynamic-pricing-cart-discounts' ),
                        'column_size' => 3,
                        '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;
        }

    }

    new Pricely_Admin_Product_Prices_Panel();
}
