<?php

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

$discountify_repeater_field = array(
	array(
		'label'       => esc_html__( 'Minimum QTY:', 'discountify' ),
		'label_class' => 'min-label',
		'field_type'  => 'number',
		'id'          => 'min',
		'value'       => '',
	),
	array(
		'label'       => esc_html__( 'Maximum QTY:', 'discountify' ),
		'label_class' => 'max-label',
		'field_type'  => 'number',
		'id'          => 'max',
		'value'       => '',
	),
	array(
		'label'           => esc_html__( 'Discount QTY:', 'discountify' ),
		'field_type'      => 'number',
		'id'              => 'free_quantity',
		'condition_class' => 'free_qty',
		'value'           => '',
	),
	array(
		'label'           => esc_html__( 'If:', 'discountify' ),
		'field_type'      => 'select',
		'id'              => 'condition_type',
		'condition_class' => 'offer_condition d-none',
		'options'         => array(
			'>'  => esc_html__( 'Greater Than (>)', 'discountify' ),
			'>=' => esc_html__( 'Greater Than or Equal (>=)', 'discountify' ),
			'<'  => esc_html__( 'Less Than (<)', 'discountify' ),
			'<=' => esc_html__( 'Less Than or Equal (<=) ', 'discountify' ),
		),
	),
	array(
		'label'           => esc_html__( 'Discount Type:', 'discountify' ),
		'field_type'      => 'select',
		'id'              => 'offer_type',
		'condition_class' => 'offer_category',
		'options'         => array(
			'free'       => esc_html__( 'Free', 'discountify' ),
			'percentage' => esc_html__( 'Percentage', 'discountify' ),
			'fixed'      => esc_html__( 'Fixed', 'discountify' ),
		),
	),
	array(
		'label'             => ( isset( $bogo_discount_type ) && 'bogo_fixed_price' === $bogo_discount_type ) ? esc_html__( 'Price:', 'discountify' ) : esc_html__( 'Discount:', 'discountify' ),
		'field_type'        => 'number',
		'id'                => 'discount_number',
		'condition_class'   => 'repeat_discount_no',
		'extra_label_class' => 'multi_discounts_symbol',
	),
);


$discountify_products = array(
	'label'           => esc_html__( 'Products:', 'discountify' ),
	'field_type'      => 'select2',
	'id'              => 'bogo_x_y_products',
	'condition_class' => 'x_y_product d-none',
	'options'         => \discountify\Utils\Helper::get_products(),
);

$discountify_categories = array(
	'label'           => esc_html__( 'Categories:', 'discountify' ),
	'field_type'      => 'select2',
	'id'              => 'bogo_x_y_categories',
	'condition_class' => 'x_y_category d-none',
	'options'         => \discountify\Utils\Helper::get_categories(),
);

array_push( $discountify_repeater_field, $discountify_products, $discountify_categories );

if ( $rules_type === 'cart_adjustment' ) {
	$discountify_repeater_field = array(
		array(
			'label'       => esc_html__( 'Subtotal:', 'discountify' ),
			'label_class' => 'min-label',
			'field_type'  => 'number',
			'id'          => 'min',
			'value'       => '',
		),
		array(
			'label'           => esc_html__( 'If:', 'discountify' ),
			'field_type'      => 'select',
			'id'              => 'condition_type',
			'condition_class' => 'offer_condition',
			'options'         => array(
				'>'  => esc_html__( 'Greater Than (>)', 'discountify' ),
				'>=' => esc_html__( 'Greater Than or Equal (>=)', 'discountify' ),
				'<'  => esc_html__( 'Less Than (<)', 'discountify' ),
				'<=' => esc_html__( 'Less Than or Equal (<=) ', 'discountify' ),
			),
		),
		array(
			'label'           => esc_html__( 'Discount Type:', 'discountify' ),
			'field_type'      => 'select',
			'id'              => 'offer_type',
			'condition_class' => 'offer_category',
			'options'         => array(
				'percentage' => esc_html__( 'Percentage', 'discountify' ),
				'fixed'      => esc_html__( 'Fixed', 'discountify' ),
			),
		),
		array(
			'label'             => esc_html__( 'Discount:', 'discountify' ),
			'field_type'        => 'number',
			'id'                => 'discount_number',
			'condition_class'   => 'repeat_discount_no',
			'extra_label_class' => 'multi_discounts_symbol',
		),
	);
}

if ( $rules_type === 'total_spend' ) {
	$discountify_repeater_field = array(
		array(
			'label'       => esc_html__( 'Minimum Spend:', 'discountify' ),
			'label_class' => 'min-label',
			'field_type'  => 'number',
			'id'          => 'min',
			'value'       => '',
		),
		array(
			'label'       => esc_html__( 'Maximum Spend:', 'discountify' ),
			'label_class' => 'max-label',
			'field_type'  => 'number',
			'id'          => 'max',
			'value'       => '',
		),
		array(
			'label'           => esc_html__( 'Discount Type:', 'discountify' ),
			'field_type'      => 'select',
			'id'              => 'offer_type',
			'condition_class' => 'offer_category',
			'options'         => array(
				'percentage' => esc_html__( 'Percentage', 'discountify' ),
				'fixed'      => esc_html__( 'Fixed', 'discountify' ),
			),
		),
		array(
			'label'             => esc_html__( 'Discount:', 'discountify' ),
			'field_type'        => 'number',
			'id'                => 'discount_number',
			'condition_class'   => 'repeat_discount_no',
			'extra_label_class' => 'multi_discounts_symbol',
		),
	);
}

// Repeater field multi discounts
$discountify_repeater_args = array(
	'label'        => esc_html__( 'Discount:', 'discountify' ),
	'id'           => 'multi_discounts',
	'name'         => 'multi_discounts[' . $type . ']',
	'repeat_field' => $discountify_repeater_field,
);

discountify_repeater_field( $type, $discountify_repeater_args );
