<?php if ( ! defined( 'ABSPATH' ) ) {exit;} ?>
<div class="wrap">
	<div class="all-checkout-fields">
	<?php
	if ( file_exists( \Quicker::base_dir() . 'input-fields.php' ) ) {
		include_once \Quicker::base_dir() . 'input-fields.php';
	}

		/**
		 * Shows Rules
		 */

		$columns = array(
			'cb'                => '<input name="bulk-delete[]" type="checkbox" />',
			'drag_handle'       => '',
			'field_label'       => esc_html__( 'Label', 'quicker' ),
			'field_name'        => esc_html__( 'Name', 'quicker' ),
			'field_placeholder' => esc_html__( 'Placeholder', 'quicker' ),
			'field_required'    => esc_html__( 'Required', 'quicker' ),
			'field_enabled'     => esc_html__( 'Enabled', 'quicker' ),
		);

		$field_list = array(
			'singular_name' => esc_html__( 'All Checkout Field', 'quicker' ),
			'plural_name'   => esc_html__( 'All Discount Rules', 'quicker' ),
			'columns'       => $columns,
		);

		?>
		<div class="checkout-field-list">
			<?php
				$disabled = Quicker\Utils\Helper::instance()->is_pro_active() ? '' : 'disabled';
				$pro_txt  = Quicker\Utils\Helper::instance()->is_pro_active() ? '' : esc_html__( '(Pro)', 'quicker' );
			?>
			<div class="mt-2 content-header">
				<div class="title mr-1"><?php esc_html_e( 'Checkout Fields', 'quicker' ); ?></div>
				<button class="button add_checkout_field" <?php echo esc_attr( $disabled ); ?>>
					<span class="dashicons dashicons-plus-alt2"></span>
					<?php esc_html_e( 'Add Checkout Field', 'quicker' ); ?>
					<?php echo esc_html( $pro_txt ); ?>
				</button>
			</div>
			<form method="POST">
				<?php
					$table = new \Quicker\Core\Admin\Table( $field_list );
					$table->preparing_items();
					$table->display();
				?>
			</form>
			<style>.select2-container--open .select2-dropdown{z-index:100001;}</style>
			<script>
			(function($){
				$(document).on('click', '.add_checkout_field', function(){
					$('#checkout-modal-title').text('<?php echo esc_js( __( 'Add New Checkout Field', 'quicker' ) ); ?>');
				});
				$(document).on('click', '.update_checkout', function(){
					$('#checkout-modal-title').text('<?php echo esc_js( __( 'Edit Checkout Field', 'quicker' ) ); ?>');
				});
			})(jQuery);
			</script>
		<div id="checkout-field-modal" class="quicker-popup-modal">
				<div class="modal-content">
					<div class="checkout-form-update">
						<div class="modal-header">
							<div class="content-header">
								<div class="title" id="checkout-modal-title"><?php esc_html_e( 'Add New Checkout Field', 'quicker' ); ?></div>
							</div>
							<span class="modal-close">&times;</span>
						</div>
						<?php
							$args = array(
								'label'      => '',
								'field_type' => 'hidden',
								'id'         => 'action_type',
								'value'      => '',
							);
							quicker_number_input_field( $args );

							$args = array(
								'label'   => esc_html__( 'Enabled:', 'quicker' ),
								'id'      => 'field_enabled',
								'checked' => 'yes',
							);
							quicker_checkbox_field( $args );

							$args = array(
								'label'    => esc_html__( 'Field Position:', 'quicker' ),
								'id'       => 'field_position',
								'options'  => Quicker\Utils\Helper::checkout_field_type(),
								'selected' => 'before_checkout_billing_form',
							);
							quicker_select_field( $args );

							$args = array(
								'label'    => esc_html__( 'Input Type:', 'quicker' ),
								'id'       => 'input_type',
								'options'  => array(
									'text'         => esc_html__( 'Text', 'quicker' ),
									'number'       => esc_html__( 'Number', 'quicker' ),
									'password'     => esc_html__( 'Password', 'quicker' ),
									'phone'        => esc_html__( 'Phone', 'quicker' ),
									'textarea'     => esc_html__( 'Textarea', 'quicker' ),
									'radio'        => esc_html__( 'Radio', 'quicker' ),
									'checkbox'     => esc_html__( 'Checkbox', 'quicker' ),
									'select'       => esc_html__( 'Select', 'quicker' ),
									'multiselect'  => esc_html__( 'Multi Select', 'quicker' ),
									'date'         => esc_html__( 'Date', 'quicker' ),
									'time'         => esc_html__( 'Time', 'quicker' ),
									'heading'      => esc_html__( 'Heading', 'quicker' ),
									'hidden'       => esc_html__( 'Hidden', 'quicker' ),
								),
								'selected' => 'text',
							);

							quicker_select_field( $args );
							?>
							<div id="field-options-wrapper" class="single-block" style="display:none;">
								<div class="form-label"><?php esc_html_e( 'Options:', 'quicker' ); ?></div>
								<div class="input-section">
									<div id="field-options-rows"></div>
									<button type="button" class="button button-small add-field-option">
										<span class="dashicons dashicons-plus"></span> <?php esc_html_e( 'Add Option', 'quicker' ); ?>
									</button>
								</div>
							</div>
							<?php
							$args = array(
								'label'      => '',
								'field_type' => 'hidden',
								'id'         => 'ID',
								'value'      => '',
							);
							quicker_number_input_field( $args );

							$args = array(
								'label'      => '',
								'field_type' => 'hidden',
								'id'         => 'field_type',
								'value'      => '',
							);
							quicker_number_input_field( $args );

							$args = array(
								'label'      => esc_html__( 'Label:', 'quicker' ),
								'field_type' => 'text',
								'id'         => 'field_label',
								'value'      => '',
							);
							quicker_number_input_field( $args );

							$args = array(
								'label'      => esc_html__( 'Name:', 'quicker' ),
								'field_type' => 'text',
								'id'         => 'field_name',
								'disable'    => $disabled,
								'value'      => '',
							);
							quicker_number_input_field( $args );


							$args = array(
								'label'      => esc_html__( 'Placeholder:', 'quicker' ),
								'field_type' => 'text',
								'id'         => 'field_placeholder',
								'value'      => '',
							);
							quicker_number_input_field( $args );

							$args = array(
								'label'   => esc_html__( 'Required:', 'quicker' ),
								'id'      => 'field_required',
								'checked' => 'yes',
							);
							quicker_checkbox_field( $args );

							$args = array(
								'label'   => esc_html__( 'Display in Emails:', 'quicker' ),
								'id'      => 'display_in_emails',
								'checked' => 'yes',
							);
							quicker_checkbox_field( $args );

							$args = array(
								'label'   => esc_html__( 'Display in Order Details:', 'quicker' ),
								'id'      => 'display_in_order_details',
								'checked' => 'yes',
							);
							quicker_checkbox_field( $args );

							$wp_roles   = wp_roles()->get_names();
							$role_options = array();
							foreach ( $wp_roles as $role_key => $role_name ) {
								$role_options[ $role_key ] = translate_user_role( $role_name );
							}
							$args = array(
								'label'       => esc_html__( 'User Roles:', 'quicker' ),
								'id'          => 'field_user_roles',
								'options'     => $role_options,
								'selected'    => array(),
								'select_type' => 'multiple',
							);
							quicker_select_field( $args );

							$args = array(
								'label'   => esc_html__( 'Enable Conditional Logic:', 'quicker' ),
								'id'      => 'field_condition_enabled',
								'checked' => '',
							);
							quicker_checkbox_field( $args );
							?>
						<div id="field-conditions-wrapper" style="display:none;">
							<div class="condition-logic-label"><?php esc_html_e( 'Conditional Logic:', 'quicker' ); ?></div>
							<div class="condition-action-row">
								<select id="field_condition_action" name="field_condition_action">
									<option value="show"><?php esc_html_e( 'Show', 'quicker' ); ?></option>
									<option value="hide"><?php esc_html_e( 'Hide', 'quicker' ); ?></option>
								</select>
								<span><?php esc_html_e( 'this field when:', 'quicker' ); ?></span>
							</div>
							<div class="condition-table-scroll">
								<div class="condition-rows-table">
									<div class="condition-row-header">
										<div class="condition-col-h"><?php esc_html_e( 'Field', 'quicker' ); ?></div>
										<div class="condition-col-h"><?php esc_html_e( 'Condition', 'quicker' ); ?></div>
										<div class="condition-col-h"><?php esc_html_e( 'Value', 'quicker' ); ?></div>
										<div></div>
									</div>
									<div id="field-conditions-rows">
										<div class="condition-empty-state"><?php esc_html_e( 'No conditions added yet.', 'quicker' ); ?></div>
									</div>
								</div>
							</div>
							<button type="button" class="button button-small add-condition-btn">
								<span class="dashicons dashicons-plus"></span> <?php esc_html_e( 'Add Condition', 'quicker' ); ?>
							</button>
						</div>
						<button class="button button-primary update_checkout_field mt-3 <?php echo esc_attr( Quicker\Utils\Helper::instance()->is_pro_active() ); ?>"><?php esc_html_e( 'Save Changes', 'quicker' ); ?></button>

					</div>
				</div>
			</div>
		</div>

	</div>
</div>