<?php

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

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

if ( !class_exists( 'Pricely_Admin_Checkout_Prices_Panel_Conditions' ) ) {

    class Pricely_Admin_Checkout_Prices_Panel_Conditions {

        public function __construct() {

            add_filter( 'pricely_admin_checkout-pricing_get-panels', array( $this, 'get_panel' ), 100 );
            
            add_filter( 'pricely_admin_checkout-pricing_process-pricing-options', array( $this, 'process_options' ), 300, 3 );
        }

        public function get_panel( $in_fields ) {

            $in_fields[] = array(
                'id' => 'condition_args',
                'type' => 'panel',
                'full_width' => true,
                'center_head' => true,
                'white_panel' => true,
                'panel_size' => 'smaller',
                'width' => '100%',
                'merge_fields' => true,
                '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[ 'condition_args' ] ) ) {

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

            return $options;
        }

        private function get_panel_fields( $in_fields ) {

            $args = array(
                'module' => 'checkout-pricing',
                'format_text' => esc_html__( 'pricing', 'pricely-dynamic-pricing-cart-discounts' ),
            );

            return apply_filters( 'pricely_admin_get-panel-conditions-fields', $in_fields, $args );
        }

    }

    new Pricely_Admin_Checkout_Prices_Panel_Conditions();
}

        
