<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Cart_Discounts_Panel' ) ) {

    class Pricely_Admin_Cart_Discounts_Panel {

        private $option_name = PRICELY_OPTION_NAME;

        public function __construct() {

            add_filter( 'pricely_admin_cart-discounts_get-panels', array( $this, 'get_panel' ), 10 );

            add_filter( 'reon_sanitize-' . $this->option_name . '-cart_discounts-tooltip', array( $this, 'sanitize_kses' ), 10 );
        }

        public function get_panel( $in_fields ) {

            $in_fields[] = array(
                'id' => 'discount_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,
                'field_css_class' => array( 'pricely_first_panel' ),
                'css_class' => array( 'rn-round-small' ),
                'last' => true,
                'fields' => $this->get_fields( $in_fields ),
            );

            return $in_fields;
        }

        public function sanitize_kses( $option ) {

            $admin_page = Pricely_Admin_Page::get_instance();

            return $admin_page->sanitize_kses( $option );
        }

        private function get_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 4,
                'merge_fields' => false,
                'fields' => array(
                    array(
                        'id' => 'title',
                        'type' => 'textbox',
                        'column_size' => 2,
                        'column_title' => esc_html__( 'Title', 'pricely-dynamic-pricing-cart-discounts' ),
                        'tooltip' => esc_html__( 'Enter the title text to be displayed for the discount on the cart and checkout pages.', 'pricely-dynamic-pricing-cart-discounts' ),
                        'default' => '',
                        'placeholder' => esc_html__( 'Title...', 'pricely-dynamic-pricing-cart-discounts' ),
                        'width' => '100%',
                    ),
                    array(
                        'id' => 'admin_note',
                        'type' => 'textbox',
                        'column_size' => 2,
                        'column_title' => esc_html__( 'Admin Note', 'pricely-dynamic-pricing-cart-discounts' ),
                        'tooltip' => esc_html__( 'Adds a private note for reference purposes', 'pricely-dynamic-pricing-cart-discounts' ),
                        'default' => '',
                        'placeholder' => esc_html__( 'Type here...', 'pricely-dynamic-pricing-cart-discounts' ),
                        'width' => '100%',
                    ),
                ),
            );

            $in_fields[] = array(
                'id' => 'any_ids',
                'type' => 'columns-field',
                'columns' => 4,
                'merge_fields' => false,
                'fields' => array(
                    array(
                        'id' => 'tooltip',
                        'type' => 'textarea',
                        'column_size' => 3,
                        'column_title' => esc_html__( 'Description (Tooltip)', 'pricely-dynamic-pricing-cart-discounts' ),
                        'tooltip' => esc_html__( 'Add tooltip text to provide discount info. on cart and checkout pages', 'pricely-dynamic-pricing-cart-discounts' ),
                        'default' => '',
                        'rows' => 1,
                        'placeholder' => esc_html__( 'Tooltip....', 'pricely-dynamic-pricing-cart-discounts' ),
                        'width' => '100%',
                    ),
                    array(
                        'id' => 'coupon_code',
                        'type' => 'textbox',
                        'column_size' => 1,
                        'column_title' => esc_html__( 'Coupon Code', 'pricely-dynamic-pricing-cart-discounts' ),
                        'tooltip' => esc_html__( 'Set a unique coupon code for the discount', 'pricely-dynamic-pricing-cart-discounts' ),
                        'default' => '',
                        'placeholder' => esc_html__( 'Coupon code....', 'pricely-dynamic-pricing-cart-discounts' ),
                        'width' => '100%',
                    ),
                ),
            );

            return apply_filters( 'pricely_admin_cart-discounts_get-fields', $in_fields );
        }

    }

    new Pricely_Admin_Cart_Discounts_Panel();
}
