<?php if ( ! defined( 'ABSPATH' ) ) {
	die; } // Cannot access directly.
/**
 *
 * Field: icon
 *
 * @since 1.0.0
 * @version 1.0.0
 */
if ( ! class_exists( 'EDITH_Field_icon' ) ) {
	class EDITH_Field_icon extends EDITH_Fields {

		public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
			parent::__construct( $field, $value, $unique, $where, $parent );
		}

		public function render() {

			$args = wp_parse_args(
				$this->field,
				array(
					'button_title' => esc_html__( 'Add Icon', 'finch-cart-product-recommendations' ),
					'remove_title' => esc_html__( 'Remove Icon', 'finch-cart-product-recommendations' ),
				)
			);

			echo wp_kses_post( $this->field_before() );

			$nonce  = wp_create_nonce( 'edith_icon_nonce' );
			$hidden = ( empty( $this->value ) ) ? ' hidden' : '';

			echo '<div class="edith-icon-select">';
			echo '<span class="edith-icon-preview' . esc_attr( $hidden ) . '"><i class="' . esc_attr( $this->value ) . '"></i></span>';
			echo '<a href="#" class="button button-primary edith-icon-add" data-nonce="' . esc_attr( $nonce ) . '">' . esc_html( $args['button_title'] ) . '</a>';
			echo '<a href="#" class="button edith-warning-primary edith-icon-remove' . esc_attr( $hidden ) . '">' . esc_html( $args['remove_title'] ) . '</a>';
			echo '<input type="hidden" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $this->value ) . '" class="edith-icon-value"' . wp_kses_post( $this->field_attributes() ) . ' />';
			echo '</div>';

			echo wp_kses_post( $this->field_after() );
		}

		public function enqueue() {
			add_action( 'admin_footer', array( 'EDITH_Field_icon', 'add_footer_modal_icon' ) );
			add_action( 'customize_controls_print_footer_scripts', array( 'EDITH_Field_icon', 'add_footer_modal_icon' ) );
		}

		public static function add_footer_modal_icon() {
			?>
		<div id="edith-modal-icon" class="edith-modal edith-modal-icon hidden">
		<div class="edith-modal-table">
			<div class="edith-modal-table-cell">
			<div class="edith-modal-overlay"></div>
			<div class="edith-modal-inner">
				<div class="edith-modal-title">
				<?php esc_html_e( 'Add Icon', 'finch-cart-product-recommendations' ); ?>
				<div class="edith-modal-close edith-icon-close"></div>
				</div>
				<div class="edith-modal-header">
				<input type="text" placeholder="<?php esc_html_e( 'Search...', 'finch-cart-product-recommendations' ); ?>" class="edith-icon-search" />
				</div>
				<div class="edith-modal-content">
				<div class="edith-modal-loading"><div class="edith-loading"></div></div>
				<div class="edith-modal-load"></div>
				</div>
			</div>
			</div>
		</div>
		</div>
			<?php
		}
	}
}
