<?php

/**
 * Control for footer
 *
 * @since 1.0.0
 */

namespace Kubelio\Customizer;

if (! defined('ABSPATH')) {
	exit;
}

class Footer {

	use Helper;

	public function __construct() {
		add_action('after_setup_theme', array($this, 'register_fields'));
	}

	/**
	 * Register Footer related customizer fields
	 */
	public function register_fields() {
		$this->set_section();
		$this->add_footer();
	}

	public function set_section() {

		$this->add_section(
			'footer',
			array(
				'title' => esc_html__('Footer', 'kubelio'),
			)
		);
	}

	public function add_footer() {
		$section = 'footer';

		$this->add_field(
			array(
				'type'     => 'headline',
				'settings' => 'headline_' . uniqid(),
				'label'   => esc_html__('Footer Options', 'kubelio'),
				'section' => $section,
			)
		);

		$this->add_field(
			array(
				'type'        => 'radio-image',
				'section'     => $section,
				'settings'    => 'footer_layout',
				'label'       => esc_html__('Layout', 'kubelio'),
				'description' => sprintf(
					/* translators: %s is the URL to the Widgets panel. */
					wp_kses_post(__('Visit the <a href="%s">Widgets panel</a> and add a widget to display a element on footer.', 'kubelio')),
					"javascript:wp.customize.panel( 'widgets' ).focus();"
				),
				'default'     => 'footer-copyright-social',
				'sanitize_callback' => 'sanitize_key',
				'choices'     => array(
					'footer-copyright-social'   => get_template_directory_uri() . '/assets/images/customizer/footer-copyright-social.webp',
					'footer-copyright-menu'     => get_template_directory_uri() . '/assets/images/customizer/footer-copyright-menu.webp',
					'footer-column-3-big-first' => get_template_directory_uri() . '/assets/images/customizer/footer-column-3-big-first.webp',
					'footer-column-4-equal'     => get_template_directory_uri() . '/assets/images/customizer/footer-column-4-equal.webp',
				),
			)
		);

		$this->add_field(
			array(
				'type'              => 'textarea',
				'label'             => esc_html__('Copyright (Support HTML tag)', 'kubelio'),
				'settings'          => 'footer_copyright',
				'description'       => esc_html__('You can use text map {{site_name}} {{year}}', 'kubelio'),
				'section'           => $section,
				'default'           => '@Copyright {{site_name}}. All Rights Reserved',
				'sanitize_callback' => 'wp_kses_post',
			)
		);

		$this->add_field(
			array(
				'type'     => 'headline',
				'label'   => esc_html__('Footer Styles', 'kubelio'),
				'section' => $section,
			)
		);

		$this->add_field(
			array(
				'type'      => 'color',
				'label'     => esc_html__('Heading Color', 'kubelio'),
				'choices'   => array('alpha' => true),
				'settings'  => 'footer_heading_color',
				'default'   => kubelio_get_theme('color')['heading-alt'],
				'section'   => $section,
				'transport' => 'auto',
				'output'    => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--heading',
					),
				),

			)
		);

		$this->add_field(
			array(
				'type'      => 'color',
				'label'     => esc_html__('Text Color', 'kubelio'),
				'choices'   => array('alpha' => true),
				'settings'  => 'footer_text_color',
				'default'   => kubelio_get_theme('color')['body-alt'],
				'section'   => $section,
				'transport' => 'auto',
				'output'    => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--body',
					),
				),
			)
		);

		$this->add_field(
			array(
				'type'      => 'color',
				'label'     => esc_html__('Meta Color', 'kubelio'),
				'choices'   => array('alpha' => true),
				'settings'  => 'footer_meta_color',
				'default'   => kubelio_get_theme('color')['meta-alt'],
				'section'   => $section,
				'transport' => 'auto',
				'output'    => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--meta',
					),
				),

			)
		);

		$this->add_field(
			array(
				'type'        => 'color',
				'choices'     => array('alpha' => true),
				'settings'    => 'footer_accent_color',
				'label'       => esc_html__('Accent Color', 'kubelio'),
				'description' => esc_html__('Set the color when hovering over the element.', 'kubelio'),
				'section'     => $section,
				'default'     => '#ffffff',
				'transport'   => 'auto',
				'output'      => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--text-link-active',
					),
				),

			)
		);

		$this->add_field(
			array(
				'type'      => 'color',
				'choices'   => array('alpha' => true),
				'settings'  => 'footer_background_color',
				'label'     => esc_html__('Background Color', 'kubelio'),
				'section'   => $section,
				'default'   => kubelio_get_theme('color')['background-alt'],
				'transport' => 'auto',
				'output'    => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--surface',
					),
				),
			)
		);

		$this->add_field(
			array(
				'type'      => 'color',
				'choices'   => array('alpha' => true),
				'settings'  => 'footer_border_color',
				'label'     => esc_html__('Border Color', 'kubelio'),
				'section'   => $section,
				'default'   => kubelio_get_theme('color')['outline-alt'],
				'transport' => 'auto',
				'output'    => array(
					array(
						'element'  => '.kubelio-default-scheme .site-footer',
						'property' => '--wp--preset--color--outline',
					),
				),
			)
		);
	}

	// end class
}
