<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Condition_Type_Cart' ) ) {

    class Pricely_Admin_Condition_Type_Cart {

        private $group_id;

        public function __construct() {

            $this->group_id = 'cart';
        }

        public function get_groups( $args ) {

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

        public function get_conditions( $group_id, $args ) {

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

                return false;
            }

            return array(
                'cart_line_count' => esc_html__( 'Cart - Line Item Count', 'pricely-dynamic-pricing-cart-discounts' ),
            );
        }

        public function get_fields( $condition_id, $args ) {

            if ( 'cart_line_count' == $condition_id ) {

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

            return false;
        }

        private function get_line_count_fields( $in_fields ) {

            $in_fields[] = array(
                'id' => 'compare',
                'type' => 'select2',
                'default' => '--',
                'options' => array(
                    '--' => esc_html__( 'Between', 'pricely-dynamic-pricing-cart-discounts' ),
                    '>=' => esc_html__( 'More than or equal to', 'pricely-dynamic-pricing-cart-discounts' ),
                    '>' => esc_html__( 'More than', 'pricely-dynamic-pricing-cart-discounts' ),
                    '<=' => esc_html__( 'Less than or equal to', 'pricely-dynamic-pricing-cart-discounts' ),
                    '<' => esc_html__( 'Less than', 'pricely-dynamic-pricing-cart-discounts' ),
                    '==' => esc_html__( 'Equal to', 'pricely-dynamic-pricing-cart-discounts' ),
                    '!=' => esc_html__( 'Not equal to', 'pricely-dynamic-pricing-cart-discounts' ),
                ),
                'width' => '99%',
                'box_width' => '44%',
                'fold_id' => 'cart_line_count',
            );

            $in_fields[] = array(
                'id' => 'line_count',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => '0',
                'placeholder' => esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'box_width' => '56%',
                'attributes' => array(
                    'min' => '0',
                    'step' => '1',
                ),
                'fold' => array(
                    'target' => 'cart_line_count',
                    'attribute' => 'value',
                    'value' => array( '--' ),
                    'oparator' => 'neq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'from_line_count',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => '0',
                'placeholder' => esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '98%',
                'box_width' => '28%',
                'attributes' => array(
                    'min' => '0',
                    'step' => '1',
                ),
                'fold' => array(
                    'target' => 'cart_line_count',
                    'attribute' => 'value',
                    'value' => array( '--' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            $in_fields[] = array(
                'id' => 'to_line_count',
                'type' => 'textbox',
                'input_type' => 'number',
                'default' => '1',
                'placeholder' => esc_html__( '0', 'pricely-dynamic-pricing-cart-discounts' ),
                'width' => '100%',
                'box_width' => '28%',
                'attributes' => array(
                    'min' => '1',
                    'step' => '1',
                ),
                'fold' => array(
                    'target' => 'cart_line_count',
                    'attribute' => 'value',
                    'value' => array( '--' ),
                    'oparator' => 'eq',
                    'clear' => false,
                ),
            );

            return $in_fields;
        }

    }

}