<?php

/**
 * Control for logo, tagline, and browser brand
 *
 * @since 1.0.0
 */

namespace Kubelio\Customizer;

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

class Brand {

	use Helper;

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

	/**
	 * Register Brand related customizer fields
	 */
	public function register_fields() {
		$this->add_logo();
		$this->add_color_browser();
	}

	/**
	 * Add color browser on mobile
	 */
	public function add_color_browser() {
		$section = 'title_tagline';

		$this->add_field(
			array(
				'type'     => 'headline',
				'settings' => 'headline_' . uniqid(),
				'label'    => esc_html__('Browser Theme', 'kubelio'),
				'section'  => $section,
				'priority' => 200,
			)
		);

		$this->add_field(
			array(
				'type'        => 'color',
				'choices'     => array('alpha' => true),
				'label'       => esc_html__('Color Browser', 'kubelio'),
				'settings'    => 'color_browser',
				'description' => esc_html__('Change the Color of Address Bar in Mobile Browser', 'kubelio'),
				'section'     => $section,
				'priority'    => 210,
				'default'     => kubelio_get_theme('color')['primary'],
			)
		);
	}

	public function add_logo() {

		$section = 'title_tagline';

		// Logo Desktop
		$this->add_field(
			array(
				'type'     => 'headline',
				'settings' => 'headline_' . uniqid(),
				'label'    => esc_html__('Desktop Logo', 'kubelio'),
				'section'  => $section,
				'priority' => 100,
			)
		);

		$this->add_field(
			array(
				'type'            => 'image',
				'settings'        => 'logo_primary',
				'label'           => esc_html__('Main Logo', 'kubelio'),
				'description'     => esc_html__('This logo will be used as your default logo on desktop device', 'kubelio'),
				'section'         => $section,
				'priority'        => 120,
				'choices'         => array(
					'save_as' => 'array',
				),
				'partial_refresh' => array(
					'logo_primary' => array(
						'selector'        => '.rt-logo',
						'render_callback' => '',
					),
				),
			)
		);

		$this->add_field(
			array(
				'type'      => 'slider',
				'settings'  => 'logo_primary_width',
				'label'     => esc_html__('Main Logo Size', 'kubelio'),
				'section'   => $section,
				'priority'  => 140,
				'choices'   => array(
					'min'  => '10',
					'max'  => '300',
					'step' => '1',
				),
				'default'   => '180',
				'output'    => array(
					array(
						'element'  => '.site-header .rt-logo',
						'property' => 'width',
						'units'    => 'px',
					),

				),
				'transport' => 'auto',
			)
		);

		// Logo Mobile
		$this->add_field(
			array(
				'type'     => 'headline',
				'label'    => esc_html__('Mobile Logo', 'kubelio'),
				'section'  => $section,
				'priority' => 150,
			)
		);

		$this->add_field(
			array(
				'type'            => 'image',
				'settings'        => 'logo_mobile',
				'label'           => esc_html__('Mobile Logo', 'kubelio'),
				'description'     => esc_html__('This logo will be used on mobile devices. If it is not available, the main logo will be used.', 'kubelio'),
				'section'         => $section,
				'priority'        => 160,
				'choices'         => array(
					'save_as' => 'array',
				),
				'partial_refresh' => array(
					'logo_mobile' => array(
						'selector'        => '.rt-logo-mobile',
						'render_callback' => '',
					),
				),
			)
		);

		$this->add_field(
			array(
				'type'      => 'slider',
				'settings'  => 'logo_mobile_width',
				'label'     => esc_html__('Mobile Logo Size', 'kubelio'),
				'section'   => $section,
				'priority'  => 180,
				'choices'   => array(
					'min'  => '10',
					'max'  => '300',
					'step' => '1',
				),
				'default'   => '130',
				'output'    => array(
					array(
						'element'  => '.rt-logo-mobile',
						'property' => 'width',
						'units'    => 'px',
					),
				),
				'transport' => 'auto',
			)
		);

		// Logo Checkout
		$this->add_field(
			array(
				'type'     => 'headline',
				'settings' => 'headline_' . uniqid(),
				'label'    => esc_html__('Checkout Logo', 'kubelio'),
				'section'  => $section,
				'priority' => 190,
			)
		);

		$this->add_field(
			array(
				'type'            => 'image',
				'settings'        => 'logo_checkout',
				'label'           => esc_html__('Checkout Logo', 'kubelio'),
				'description'     => esc_html__('This logo will be used on Checkout Focused Pages Templates. If it is not available, the main logo will be used.', 'kubelio'),
				'section'         => $section,
				'priority'        => 195,
				'choices'         => array(
					'save_as' => 'array',
				),
				'partial_refresh' => array(
					'logo_checkout' => array(
						'selector'        => '.rt-logo-checkout',
						'render_callback' => '',
					),
				),
			)
		);

		$this->add_field(
			array(
				'type'      => 'slider',
				'settings'  => 'logo_checkout_width',
				'label'     => esc_html__('Checkout Logo Size', 'kubelio'),
				'section'   => $section,
				'priority'  => 200,
				'choices'   => array(
					'min'  => '10',
					'max'  => '300',
					'step' => '1',
				),
				'default'   => '130',
				'output'    => array(
					array(
						'element'  => '.site-checkout-header .rt-logo',
						'property' => 'width',
						'units'    => 'px',
					),
				),
				'transport' => 'auto',
			)
		);
	}

	// end class
}
