<?php

/**
 * @author : Webforia Studio
 */

namespace Retheme\Customizer;

use Retheme\Customizer_Base;

class General extends Customizer_Base {

    public function __construct() {
        $this->set_section();
        $this->add_typography();
        $this->add_color();
        $this->add_button();
        $this->add_sub_menu();
        $this->add_off_canvas_panel();
        $this->add_global_search();
        $this->add_element();
    }

    public function set_section() {
        $this->add_panel('general', [
            'title' => __('Global', 'jelajah-text'),
            'priority' => 50,
        ]);

        $this->add_section('general_typography', [
            'title'       => __('Typography', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_color', [
            'title'       => __('Colors & Styles', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_button', [
            'title'       => __('Button', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_menu', [
            'title'       => __('Sub Menu', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_off_canvas_panel', [
            'title'       => __('Off-Canvas Area', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_global_search', [
            'title'       => __('Global Search', 'jelajah-text'),
            'panel'       => 'general',
        ]);

        $this->add_section('general_element', [
            'title'       => __('Element', 'jelajah-text'),
            'panel'       => 'general',
        ]);
    }

    public function add_typography() {
        $section = 'general_typography';

        $this->add_field([
            'type' => 'typography',
            'settings' => 'typography_heading',
            'label' => __('Headings', 'jelajah-text'),
            'section' => $section,
            'default'     => rt_get_theme('typography')['heading'],
            'output' => [
                [
                    'choice' => 'font-family',
                    'element' => 'body',
                    'property' => '--wp--preset--font-family--heading',
                ],
                [
                    'choice' => 'variant',
                    'element' => 'h1, h2, h3, h4, h5, h6',
                    'property' => 'font-weight',
                ],
            ],
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        $this->add_field([
            'type' => 'typography',
            'settings' => 'typography_body',
            'label' => __('Body', 'jelajah-text'),
            'section' => $section,
            'default'     => rt_get_theme('typography')['body'],
            'output' => [
                [
                    'choice' => 'font-family',
                    'element' => 'body',
                    'property' => '--wp--preset--font-family--body',
                ],
                [
                    'choice' => 'variant',
                    'element' => 'body',
                    'property' => 'font-weight',
                ],
            ],
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        $this->add_field([
            'type' => 'typography',
            'settings' => 'typography_navigation',
            'label' => __('Primary Navigation', 'jelajah-text'),
            'section' => $section,
            'default' => rt_get_theme('typography')['menu'],
            'output' => [
                [
                    'choice' => 'font-family',
                    'element' => '.site-header__main .rt-menu, .site-header__sticky .rt-menu',
                    'property' => 'font-family',
                ],
                [
                    'choice' => 'variant',
                    'element' => '.site-header__main .rt-menu, .site-header__sticky .rt-menu',
                    'property' => 'font-weight',
                ],
            ],
        ]);
    }

    public function add_color() {
        $section = 'general_color';

        // Brand
        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Primary Color', 'jelajah-text'),
            'settings' => 'global_color_primary',
            'section' => $section,
            'default' => rt_get_theme('color')['primary'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--primary',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        // Font Color
        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Heading Color', 'jelajah-text'),
            'settings' => 'global_color_heading',
            'section' => $section,
            'default' => rt_get_theme('color')['heading'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--heading',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Text Color', 'jelajah-text'),
            'settings' => 'global_color_body',
            'section' => $section,
            'default' => rt_get_theme('color')['body'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--body',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Meta Color', 'jelajah-text'),
            'settings' => 'global_color_meta',
            'section' => $section,
            'default' => rt_get_theme('color')['meta'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--meta',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        // Link
        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Link Color', 'jelajah-text'),
            'settings' => 'global_color_link',
            'section' => $section,
            'default' => rt_get_theme('color')['text-link'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--text-link',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Link Accent Color', 'jelajah-text'),
            'description' => __('Link color on hover', 'jelajah-text'),
            'settings' => 'global_color_link_active',
            'section' => $section,
            'default' => rt_get_theme('color')['text-link'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--text-link-active',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        // Background
        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Background Color', 'jelajah-text'),
            'settings' => 'global_color_background',
            'section' => $section,
            'default' => rt_get_theme('color')['background'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--background',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Foreground Color', 'jelajah-text'),
            'settings' => 'global_color_foreground',
            'section' => $section,
            'default' => rt_get_theme('color')['foreground'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--foreground',
                ],
            ],
            'transport' => 'auto',
        ]);

        // Image Background
        $this->add_field([
            'type'        => 'image',
            'label' => __('Background Image', 'jelajah-text'),
            'description' => __('Recommended size 600 × 180 pixels.', 'jelajah-text'),
            'settings' => 'global_background_image',
            'section' => $section,
            'choices'     => [
                'save_as' => 'id',
            ],
        ]);

        $this->add_divinder([
            'section' => $section,
        ]);

        // Border Color
        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Border Color', 'jelajah-text'),
            'settings' => 'global_color_border',
            'section' => $section,
            'default' => rt_get_theme('color')['outline'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--preset--color--outline',
                ],
            ],
            'transport' => 'auto',
        ]);
    }

    public function add_button() {
        $section = 'general_button';

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Text Color', 'jelajah-text'),
            'settings' => 'global_button_color',
            'section' => $section,
            'default' => rt_get_theme('button')['primary']['color'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--custom--button--color',
                ],
            ],
            'transport' => 'auto',
        ]);

        $this->add_field([
            'type' => 'color',
            'choices' => ['alpha' => true],
            'label' => __('Background Color', 'jelajah-text'),
            'settings' => 'global_button_background',
            'section' => $section,
            'default' => rt_get_theme('button')['primary']['background'],
            'output' => [
                [
                    'element' => '.retheme-default-scheme',
                    'property' => '--wp--custom--button--background',
                ],
            ],
            'transport' => 'auto',
        ]);
    }

    public function add_global_search() {
        $section = 'general_global_search';

        $this->add_field([
            'type' => 'select',
            'settings' => 'global_search_post_type',
            'label' => __('Global Search Posts Type', 'jelajah-text'),
            'section' => $section,
            'default' => 'post',
            'choices' => [
                'post' => __('Post', 'jelajah-text'),
                'trip' => __('Trip', 'jelajah-text'),
            ],
        ]);

        $this->add_field([
            'type' => 'text',
            'settings' => 'global_search_placeholder',
            'label' => __('Global Search Placeholder', 'jelajah-text'),
            'section' => $section,
            'default' => __('Search posts', 'jelajah-text'),
        ]);
    }

    public function add_sub_menu() {

        $section = 'general_menu';

        $this->add_field([
            'type' => 'color',
            'label' => __('Text Color', 'jelajah-text'),
            'choices' => ['alpha' => true],
            'settings' => 'submenu_color',
            'default' => rt_get_theme('color')['body'],
            'section' => $section,
            'transport' => 'auto',
            'output' => [
                [
                    'element' => '.retheme-default-scheme .site-header .sub-menu',
                    'property' => ' --color-menu',
                ],
            ],

        ]);

        $this->add_field([
            'type' => 'color',
            'label' => __('Background Color', 'jelajah-text'),
            'choices' => ['alpha' => true],
            'settings' => 'submenu_background',
            'default' => rt_get_theme('color')['background'],
            'section' => $section,
            'transport' => 'auto',
            'output' => [
                [
                    'element' => '.retheme-default-scheme .site-header .sub-menu',
                    'property' => '--wp--preset--color--background',
                ],
            ],

        ]);
    }

    public function add_off_canvas_panel() {

        $section = 'general_off_canvas_panel';

        $this->add_field([
            'type' => 'color',
            'label' => __('Text Color', 'jelajah-text'),
            'choices' => ['alpha' => true],
            'settings' => 'offcanvas_color',
            'default' => rt_get_theme('color')['body'],
            'section' => $section,
            'transport' => 'auto',
            'output' => [
                [
                    'element' => '.retheme-default-scheme .rt-slidepanel .rt-menu',
                    'property' => '--wp--preset--color--body',
                ],
            ],

        ]);

        $this->add_field([
            'type' => 'color',
            'label' => __('Background Color', 'jelajah-text'),
            'choices' => ['alpha' => true],
            'settings' => 'offcanvas_background',
            'default' => rt_get_theme('color')['background'],
            'section' => $section,
            'transport' => 'auto',
            'output' => [
                [
                    'element' => '.retheme-default-scheme .rt-slidepanel__inner',
                    'property' => 'background-color',
                ],
            ],

        ]);
    }

    public function add_element() {

        $section = 'general_element';

        $this->add_field([
            'type' => 'toggle',
            'settings' => 'breadcrumbs',
            'label' => __('Breadcrumbs', 'jelajah-text'),
            'default' => true,
            'section' => $section,
            'default' => true,
        ]);

        $this->add_field([
            'type' => 'toggle',
            'settings' => 'gotop',
            'label' => __('Go Top Navigation', 'jelajah-text'),
            'default' => true,
            'section' => $section,
            'default' => true,
        ]);
    }
    // end class
}

new General;
