<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Condition_Type_Calendar' ) ) {

    class Pricely_Admin_Condition_Type_Calendar {

        private $group_id;

        public function __construct() {

            $this->group_id = 'calendar';
        }

        public function get_groups( $args ) {

            return array(
                $this->group_id => esc_html__( 'Calendar', 'pricely-dynamic-pricing-cart-discounts' )
            );
        }

        public function get_conditions( $group_id, $args ) {

            if ( $group_id !== $this->group_id ) {

                return false;
            }

            return array(
                'date' => esc_html__( 'Calendar - Date', 'pricely-dynamic-pricing-cart-discounts' ),
                'time' => esc_html__( 'Calendar - Time', 'pricely-dynamic-pricing-cart-discounts' ),
            );
        }

        public function get_fields( $condition_id, $args ) {

            if ( 'date' == $condition_id ) {

                return $this->get_date_fields( array() );
            }

            if ( 'time' == $condition_id ) {

                return $this->get_time_fields( array() );
            }

            return false;
        }

        private function get_date_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'date_type',
                'type' => 'select2',
                'default' => 'date',
                'options' => array(
                    'date' => esc_html__( 'Specific date', 'pricely-dynamic-pricing-cart-discounts' ),
                    'from' => esc_html__( 'From', 'pricely-dynamic-pricing-cart-discounts' ),
                    'to' => esc_html__( 'To', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'fold_id' => 'date_type',
                'width' => '98%',
                'box_width' => '26%',
            );

            $in_fields[] = array(
                'id' => 'date',
                'type' => 'date',
                'default' => '',
                'placeholder' => esc_html__( 'yy-mm-dd', 'pricely-dynamic-pricing-cart-discounts' ),
                'date_format' => 'yy-mm-dd',
                'number_of_months' => 1,
                'show_button_panel' => false,
                'change_month' => true,
                'change_year' => true,
                'first_day' => 0,
                'width' => '100%',
                'box_width' => '74%',
            );

            return $in_fields;
        }

        private function get_time_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'time_type',
                'type' => 'select2',
                'default' => 'from',
                'options' => array(
                    'from' => esc_html__( 'From', 'pricely-dynamic-pricing-cart-discounts' ),
                    'to' => esc_html__( 'To', 'pricely-dynamic-pricing-cart-discounts' ),
                    'between' => esc_html__( 'Between', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'fold_id' => 'time_type',
                'width' => '98%',
                'box_width' => '26%',
            );

            $in_fields[] = array(
                'id' => 'from_time',
                'type' => 'time',
                'default' => '',
                'placeholder' => esc_html__( '00:00:00', 'pricely-dynamic-pricing-cart-discounts' ),
                'time_format' => 'HH:mm:ss',
                'one_line' => true,
                'fold' => array(
                    'target' => 'time_type',
                    'attribute' => 'value',
                    'value' => 'between',
                    'oparator' => 'eq',
                    'clear' => true,
                ),
                'width' => '98%',
                'box_width' => '37%',
            );

            $in_fields[] = array(
                'id' => 'to_time',
                'type' => 'time',
                'default' => '',
                'placeholder' => esc_html__( '00:00:00', 'pricely-dynamic-pricing-cart-discounts' ),
                'time_format' => 'HH:mm:ss',
                'one_line' => true,
                'fold' => array(
                    'target' => 'time_type',
                    'attribute' => 'value',
                    'value' => 'between',
                    'oparator' => 'eq',
                    'clear' => true,
                ),
                'width' => '100%',
                'box_width' => '37%',
            );

            $in_fields[] = array(
                'id' => 'time',
                'type' => 'time',
                'default' => '',
                'placeholder' => esc_html__( '00:00:00', 'pricely-dynamic-pricing-cart-discounts' ),
                'time_format' => 'HH:mm:ss',
                'one_line' => true,
                'fold' => array(
                    'target' => 'time_type',
                    'attribute' => 'value',
                    'value' => 'between',
                    'oparator' => 'neq',
                    'clear' => true,
                ),
                'width' => '100%',
                'box_width' => '74%',
            );

            return $in_fields;
        }

    }

}