<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Misc_Settings' ) ) {

    class Pricely_Admin_Misc_Settings {

        private $option_name = PRICELY_OPTION_NAME;

        public function __construct() {

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

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

        public function get_panel( $in_fields ) {

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

            return $in_fields;
        }

        public function sanitize_kses( $option ) {

            $admin_page = Pricely_Admin_Page::get_instance();

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

        private function get_panel_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'any_id',
                'type' => 'paneltitle',
                'full_width' => true,
                'center_head' => true,
                'title' => esc_html__( 'Style Sheet & Misc.', 'pricely-dynamic-pricing-cart-discounts' ),
                'desc' => esc_html__( 'Use these settings to configure stylesheets and other miscellaneous settings', 'pricely-dynamic-pricing-cart-discounts' ),
            );

            $in_fields[] = array(
                'id' => 'any_id',
                'type' => 'columns-field',
                'columns' => 3,
                'merge_fields' => false,
                'fields' => $this->get_misc_fields(),
            );

            $in_fields[] = array(
                'id' => 'any_id',
                'type' => 'columns-field',
                'columns' => 1,
                'merge_fields' => false,
                'fields' => $this->get_custom_css_fields(),
            );

            return $in_fields;
        }

        private function get_misc_fields() {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'use_external_css',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Use External CSS', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Choose whether any generated CSS should be included externally or inline', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => array( 'no' ),
                'options' => array(
                    'no' => esc_html__( 'No, Do not use external css', 'pricely-dynamic-pricing-cart-discounts' ),
                    'yes' => esc_html__( 'Yes, Use external css', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            $in_fields[] = array(
                'id' => 'include_fontawesome',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Font Awesome - Include Font Icons', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( 'Choose whether font icon stylesheets should be included on the front-end', 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => array( 'no' ),
                'options' => array(
                    'no' => esc_html__( 'No, Do not include font icons', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            $in_fields[] = array(
                'id' => 'trigger_payment_method',
                'type' => 'select2',
                'column_size' => 1,
                'column_title' => esc_html__( 'Checkout Update', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Choose whether checkout page should automatically update based on user activities", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => array( 'no' ),
                'options' => array(
                    'no' => esc_html__( 'Do not update checkout page', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '100%',
            );

            return $in_fields;
        }

        private function get_custom_css_fields() {

            $in_fields = array();

            $in_fields[] = array(
                'id' => 'custom_css',
                'type' => 'textarea',
                'column_size' => 1,
                'column_title' => esc_html__( 'Custom CSS', 'pricely-dynamic-pricing-cart-discounts' ),
                'tooltip' => esc_html__( "Add additional custom stylesheet for the UI components", 'pricely-dynamic-pricing-cart-discounts' ),
                'default' => '',
                'placeholder' => esc_html__( 'Type here...', 'pricely-dynamic-pricing-cart-discounts' ),
                'rows' => 5,
                'width' => '100%',
            );

            return $in_fields;
        }

    }

    new Pricely_Admin_Misc_Settings();
}
