<?php
/**
 * Dynamic Tag: Site Icon (Image)
 *
 * @package captain-widgets-kit
 * @since   1.1.0
 */

use Elementor\Core\DynamicTags\Data_Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
/**
 * Class Captwiki_Tag_Site_Icon
 * Returns the site favicon/icon as an image array.
 */
class Captwiki_Tag_Site_Icon extends Data_Tag {
	/**
	 * Get tag name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-tag-site-icon'; }
	/**
	 * Get tag title.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'Site Icon', 'captain-widgets-kit' ); }
	/**
	 * Get tag group.
	 *
	 * @return array
	 */
	public function get_group(): array {
		return array( 'captwiki-site' ); }
	/**
	 * Get tag categories.
	 *
	 * @return array
	 */
	public function get_categories(): array {
		return array( Module::IMAGE_CATEGORY, Module::MEDIA_CATEGORY ); }
	/**
	 * Check whether settings are required.
	 *
	 * @return bool
	 */
	public function is_settings_required() {
		return true; }
	/**
	 * Register tag controls.
	 *
	 * @return void
	 */
	protected function register_controls(): void {}
	/**
	 * Handle register advanced section.
	 *
	 * @return mixed
	 */
	protected function register_advanced_section() {}
	/**
	 * Get tag value.
	 *
	 * @param array $options Function parameter.
	 * @return mixed
	 */
	public function get_value( array $options = array() ) {
		$icon_id = get_option( 'site_icon' );
		if ( ! $icon_id ) {
			return false; }
		$url = wp_get_attachment_image_url( $icon_id, 'full' );
		return $url ? array(
			'id'  => $icon_id,
			'url' => $url,
		) : false;
	}
	/**
	 * Render tag output.
	 *
	 * @return void
	 */
	public function render(): void {
		$value = $this->get_value();
		if ( ! empty( $value['url'] ) ) {
			echo esc_url( $value['url'] ); }
	}
}
