<?php
/**
 *
 * Field: Icon
 *
 * @link       https://shapedplugin.com/
 *
 * @package Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/admin/views
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access directly.

if ( ! class_exists( 'SP_PCP_Field_icon' ) ) {
	/**
	 *
	 * Field: icon
	 *
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	class SP_PCP_Field_icon extends SP_PCP_Fields {
		/**
		 * The class constructor.
		 *
		 * @param array  $field The field type.
		 * @param string $value The values of the field.
		 * @param string $unique The unique ID for the field.
		 * @param string $where To where show the output CSS.
		 * @param string $parent The parent args.
		 */
		public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
			parent::__construct( $field, $value, $unique, $where, $parent );
		}
		/**
		 * The render method.
		 *
		 * @return void
		 */
		public function render() {

			$args = wp_parse_args(
				$this->field,
				array(
					'button_title' => esc_html__( 'Add Icon', 'smart-post-show-pro' ),
					// 'remove_title' => esc_html__( 'Remove Icon', 'smart-post-show-pro' ),
					'remove_title' => 'fa fa-trash',
				)
			);

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

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

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

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