<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
 *
 * Field: icon
 *
 * @since 1.0.0
 * @version 1.0.0
 *
 */
if ( ! class_exists( 'WDPOP_CORE_Field_icon' ) ) {
  class WDPOP_CORE_Field_icon extends WDPOP_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', 'wing-popup' ),
        'remove_title' => esc_html__( 'Remove Icon', 'wing-popup' ),
      ) );

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

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

      echo '<div class="wdpop_core-icon-select">';
      echo '<span class="wdpop_core-icon-preview'. esc_attr( $hidden ) .'"><i class="'. esc_attr( $this->value ) .'"></i></span>';
      echo '<a href="#" class="button button-primary wdpop_core-icon-add" data-nonce="'. esc_attr( $nonce ) .'">'. wp_kses_post($args['button_title']) .'</a>';
      echo '<a href="#" class="button wdpop_core-warning-primary wdpop_core-icon-remove'. esc_attr( $hidden ) .'">'. wp_kses_post($args['remove_title']) .'</a>';
      echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="wdpop_core-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( 'WDPOP_CORE_Field_icon', 'add_footer_modal_icon' ) );
      add_action( 'customize_controls_print_footer_scripts', array( 'WDPOP_CORE_Field_icon', 'add_footer_modal_icon' ) );
    }

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

  }
}
