<?php

use Elementor\Controls_Manager;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Typography;

class themesflat_options_elementor
{
    public function __construct()
    {
        add_action('elementor/documents/register_controls', [$this, 'themesflat_elementor_register_options'], 10);
        add_action('elementor/editor/before_enqueue_scripts', function () {
            wp_enqueue_script('elementor-preview-load', THEMESFLAT_LINK . 'js/elementor/elementor-preview-load.js', array('jquery'), null, true);
        }, 10, 3);
    }

    public function themesflat_elementor_register_options($element)
    {
        $post_id = $element->get_id();
        $post_type = get_post_type($post_id);

        $this->themesflat_options_color($element);
        if (($post_type !== 'post') && ($post_type !== 'portfolios') && ($post_type !== 'services') && ($post_type !== 'doctor')) {
            $this->themesflat_options_topbar($element);
            $this->themesflat_options_page_header($element);
        }

        $this->themesflat_options_page($element);
        $this->themesflat_options_page_pagetitle($element);

        if ($post_type == 'services') {
            $this->themesflat_options_services($element);
        }
    }

    public function themesflat_options_color($element)
    {

        // TF Services
        $element->start_controls_section(
            'themesflat_color_options',
            [
                'label' => esc_html__('TF Color', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        $element->add_control(
            'secondary_color',
            [
                'label' => esc_html__('Secondary Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-secondary-color: {{VALUE}};',
                ],
            ]
        );

        $element->add_control(
            'primary_color',
            [
                'label' => esc_html__('Primary Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-primary-color: {{VALUE}};',
                ],
            ]
        );
        $element->add_control(
            'accent_color',
            [
                'label' => esc_html__('Accent Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-accent-color: {{VALUE}};',
                ],
            ]
        );

        $element->add_control(
            'body_background_color',
            [
                'label' => esc_html__('Body Background Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-background-color-main: {{VALUE}};',
                ],
            ]
        );

        $element->end_controls_section();
    }

    public function themesflat_options_page_header($element)
    {
        // TF Header
        $element->start_controls_section(
            'themesflat_header_options',
            [
                'label' => esc_html__('TF Header', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        $element->add_control(
            'h_options_header',
            [
                'label' => esc_html__('Header', 'devoer'),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $element->add_control(
            'style_header',
            [
                'label' => esc_html__('Header Style', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    'header-default' => esc_html__('Header Default', 'devoer'),
                    'header-01' => esc_html__('Header 01', 'devoer'),
                    'header-02' => esc_html__('Header 02', 'devoer'),
                ],
            ]
        );
        // Logo
        $element->add_control(
            'site_logo',
            [
                'label' => esc_html__('Custom Logo', 'devoer'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $element->add_control(
            'site_logo_sticky',
            [
                'label' => esc_html__('Custom Logo Sticky', 'devoer'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
	    $element->add_control(
		    'site_logo_mobile',
		    [
			    'label' => esc_html__('Custom Logo Mobile', 'devoer'),
			    'type' => Controls_Manager::MEDIA,
		    ]
	    );
        $element->add_responsive_control(
            'logo_width',
            [
                'label' => esc_html__('Logo Width', 'devoer'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', '%'],
                'range' => [
                    'px' => [
                        'min' => 30,
                        'max' => 500,
                    ],
                    '%' => [
                        'min' => 50,
                        'max' => 150,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} #header #logo a img, {{WRAPPER}} .modal-menu__panel-footer .logo-panel a img' => 'max-width: {{SIZE}}{{UNIT}} !important;',
                ],
            ]
        );

	    $element->add_responsive_control(
		    'spacing_menu',
		    [
			    'label' => esc_html__('Spacing Menu', 'devoer'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px', '%'],
			    'range' => [
				    'px' => [
					    'min' => 0,
					    'max' => 200,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} #mainnav > ul > li' => 'margin-right: {{SIZE}}{{UNIT}} !important; margin-left: {{SIZE}}{{UNIT}} !important;',
			    ],
		    ]
	    );

	    $element->add_responsive_control(
		    'header_height',
		    [
			    'label' => esc_html__('Height Header', 'devoer'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range' => [
				    'px' => [
					    'min' => 0,
					    'max' => 500,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}}' => '--theme-height-header: {{SIZE}}{{UNIT}};',
			    ],
		    ]
	    );

        $element->add_control(
            'header_absolute',
            [
                'label' => esc_html__('Header Absolute', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('No', 'devoer'),
                    1 => esc_html__('Yes', 'devoer'),
                ],
                'condition' => ['style_header!' => ''],
            ]
        );
        $element->add_control(
            'header_sticky',
            [
                'label' => esc_html__('Header Sticky', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('No', 'devoer'),
                    1 => esc_html__('Yes', 'devoer'),
                ],
                'condition' => ['style_header!' => ''],
            ]
        );
        $element->add_control(
            'header_search_box',
            [
                'label' => esc_html__('Search Box', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('Hide', 'devoer'),
                    1 => esc_html__('Show', 'devoer'),
                ],
                'condition' => ['style_header!' => ''],
            ]
        );
        $element->add_control(
            'header_sidebar_toggler',
            [
                'label' => esc_html__('Sidebar Toggler', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('Hide', 'devoer'),
                    1 => esc_html__('Show', 'devoer'),
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_custom_html_enable',
            [
                'label' => esc_html__('Custom HTML', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('Hide', 'devoer'),
                    1 => esc_html__('Show', 'devoer'),
                ],
            ]
        );

        $element->add_control(
            'header_custom_html',
            [
                'label' => esc_html__('Enter Custom HTML', 'devoer'),
                'type' => Controls_Manager::WYSIWYG,
                'label_block' => true,
                'condition' => [
                    'header_custom_html_enable!' => '0',
                ],
            ]
        );

        $element->add_control(
            'header_backgroundcolor',
            [
                'label' => esc_html__('Header Background', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} #header' => 'background: {{VALUE}};',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_backgroundcolor_sticky',
            [
                'label' => esc_html__('Header Background Sticky', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} header .header-sticky ' => 'background-color: {{VALUE}} !important;',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_color_main_nav',
            [
                'label' => esc_html__('Navigation Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-color-main-navigation: {{VALUE}};',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_color_hover_main_nav',
            [
                'label' => esc_html__('Header Navigation Hover Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-color-hover-main-navigation: {{VALUE}};',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_sticky_color_main_nav',
            [
                'label' => esc_html__('Header Sticky Navigation Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => '--theme-header-sticky-color-main-navigation: {{VALUE}};',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

        $element->add_control(
            'header_sticky_color_hover_main_nav',
            [
                'label' => esc_html__('Header Sticky Navigation Hover Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}}' => ' --theme-header-sticky-color-hover-main-navigation: {{VALUE}};',
                ],
                'condition' => ['style_header!' => ''],
            ]
        );

	    $element->add_control(
		    'header_menu_spacing',
		    [
			    'label' => esc_html__('Menu Item Spacing', 'devoer'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range' => [
				    'px' => [
					    'min' => 50,
					    'max' => 200,
					    'step' => 1,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} #mainnav > ul > li' => 'margin-left: {{SIZE}}{{UNIT}};margin-right: {{SIZE}}{{UNIT}};',
			    ],
		    ]
	    );

        //Extra Classes Header
        $element->add_control(
            'extra_classes_header',
            [
                'label' => esc_html__('Extra Classes', 'devoer'),
                'type' => Controls_Manager::TEXT,
                'label_block' => true,
            ]
        );

        $element->end_controls_section();
    }

    public function themesflat_topbar_options_plus($element)
    {
        $element->add_control(
            'social_topbar_left',
            [
                'label' => esc_html__('Social Left ( OFF | ON )', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('Hide', 'devoer'),
                    1 => esc_html__('Show', 'devoer'),
                ],
            ]
        );

	    $element->add_control(
		    'topbar_left_custom_html_enable',
		    [
			    'label' => esc_html__('Custom HTML Left ( OFF | ON )', 'devoer'),
			    'type' => Controls_Manager::SELECT,
			    'default' => '',
			    'options' => [
				    '' => esc_html__('Theme Setting', 'devoer'),
				    0 => esc_html__('Hide', 'devoer'),
				    1 => esc_html__('Show', 'devoer'),
			    ],
		    ]
	    );

        $element->add_control(
            'topbar_left_custom_html',
            [
                'label' => esc_html__('Custom HTML Left', 'devoer'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
            ]
        );

	    $element->add_control(
		    'social_topbar_right',
		    [
			    'label' => esc_html__('Social Right ( OFF | ON )', 'devoer'),
			    'type' => Controls_Manager::SELECT,
			    'default' => '',
			    'options' => [
				    '' => esc_html__('Theme Setting', 'devoer'),
				    0 => esc_html__('Hide', 'devoer'),
				    1 => esc_html__('Show', 'devoer'),
			    ],
		    ]
	    );

	    $element->add_control(
		    'topbar_right_custom_html_enable',
		    [
			    'label' => esc_html__('Custom HTML Right ( OFF | ON )', 'devoer'),
			    'type' => Controls_Manager::SELECT,
			    'default' => '',
			    'options' => [
				    '' => esc_html__('Theme Setting', 'devoer'),
				    0 => esc_html__('Hide', 'devoer'),
				    1 => esc_html__('Show', 'devoer'),
			    ],
		    ]
	    );

	    $element->add_control(
		    'topbar_right_custom_html',
		    [
			    'label' => esc_html__('Custom HTML Right', 'devoer'),
			    'type' => Controls_Manager::TEXTAREA,
			    'label_block' => true,
		    ]
	    );

    }

    public function themesflat_options_topbar($element)
    {
        $element->start_controls_section(
            'themesflat_topbar_options',
            [
                'label' => esc_html__('TF Topbar', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        $element->add_control(
            'h_options_topbar',
            [
                'label' => esc_html__('Topbar', 'devoer'),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        $element->add_control(
            'topbar_enabled',
            [
                'label' => esc_html__('Enable Topbar', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => esc_html__('Theme Setting', 'devoer'),
                    0 => esc_html__('Hide', 'devoer'),
                    1 => esc_html__('Show', 'devoer'),
                ],
            ]
        );

        $element->add_responsive_control(
            'topbar_padding',
            [
                'label' => esc_html__('Padding', 'devoer'),
                'type' => Controls_Manager::DIMENSIONS,
                'allowed_dimensions' => ['top', 'bottom'],
                'size_units' => ['px'],
                'selectors' => [
                    '{{WRAPPER}} .themesflat-top .container-inside' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $element->add_control(
            'topbar_background_color',
            [
                'label' => esc_html__('Background', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .themesflat-top' => 'background: {{VALUE}};',
                ],
            ]
        );
        $element->add_control(
            'topbar_textcolor',
            [
                'label' => esc_html__('Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .themesflat-top' => 'color: {{VALUE}};',
                ],
            ]
        );
        $element->add_control(
            'topbar_link_color',
            [
                'label' => esc_html__('Link Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .themesflat-top a' => 'color: {{VALUE}};',
                ],
            ]
        );
        $element->add_control(
            'topbar_link_color_hover',
            [
                'label' => esc_html__('Link Hover Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .themesflat-top a:hover' => 'color: {{VALUE}};',
                    '{{WRAPPER}}.header-04 .themesflat-top ul.flat-information li > i' => 'color: {{VALUE}};',
                    '{{WRAPPER}}.header-default .themesflat-top ul.flat-information li > i' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .themesflat-top .wrap-btn-topbar .btn-topbar:before' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $element->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'topbar_typography',
                'label' => esc_html__('Typography', 'devoer'),
                'selector' => '{{WRAPPER}} .themesflat-top',
            ]
        );

        $this->themesflat_topbar_options_plus($element);

        $element->end_controls_section();
    }

    public function themesflat_options_page_pagetitle($element)
    {
        // TF Page Title
        $element->start_controls_section(
            'themesflat_pagetitle_options',
            [
                'label' => esc_html__('TF Page Title', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        $element->add_control(
            'hide_pagetitle',
            [
                'label' => esc_html__('Hide Page Title', 'devoer'),
                'type' => Controls_Manager::SELECT,
                'default' => 'block',
                'options' => [
                    'none' => esc_html__('Yes', 'devoer'),
                    'block' => esc_html__('No', 'devoer'),
                ],
                'selectors' => [
                    '{{WRAPPER}} .page-title' => 'display: {{VALUE}};',
                ],
            ]
        );

        $element->add_responsive_control(
            'pagetitle_padding',
            [
                'label' => esc_html__('Padding', 'devoer'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'allowed_dimensions' => ['top', 'bottom'],
                'selectors' => [
                    '{{WRAPPER}} .page-title' => 'padding-top: {{TOP}}{{UNIT}}; padding-bottom: {{BOTTOM}}{{UNIT}};',
                ],
                'condition' => ['hide_pagetitle' => 'block']
            ]
        );

        $element->add_responsive_control(
            'pagetitle_margin',
            [
                'label' => esc_html__('Margin', 'devoer'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'allowed_dimensions' => ['top', 'bottom'],
                'selectors' => [
                    '{{WRAPPER}} .page-title' => 'margin-top: {{TOP}}{{UNIT}}; margin-bottom: {{BOTTOM}}{{UNIT}};',
                ],
                'condition' => ['hide_pagetitle' => 'block']
            ]
        );

        $element->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'pagetitle_bg',
                'label' => esc_html__('Background', 'devoer'),
                'types' => ['classic', 'gradient', 'video'],
                'selector' => '{{WRAPPER}} .page-title',
                'condition' => ['hide_pagetitle' => 'block']
            ]
        );

        $element->add_control(
            'pagetitle_overlay_color',
            [
                'label' => esc_html__('Overlay Color', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-title .overlay' => 'background: {{VALUE}}; opacity: 100%;filter: alpha(opacity=100);',
                ],
                'condition' => ['hide_pagetitle' => 'block']
            ]
        );

        //Extra Classes Page Title
        $element->add_control(
            'extra_classes_pagetitle',
            [
                'label' => esc_html__('Extra Classes', 'devoer'),
                'type' => Controls_Manager::TEXT,
                'label_block' => true,
                'separator' => 'before'
            ]
        );

        $element->end_controls_section();
    }

    public function themesflat_options_page($element)
    {
        $post_id = $element->get_id();
        $post_type = get_post_type($post_id);

        // TF Page
        $element->start_controls_section(
            'themesflat_page_options',
            [
                'label' => esc_html__('TF Page', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        if (($post_type !== 'post') && ($post_type !== 'portfolios') && ($post_type !== 'services') && ($post_type !== 'doctor')) {
            $element->add_control(
                'page_sidebar_layout',
                [
                    'label' => esc_html__('Sidebar Position', 'devoer'),
                    'type' => Controls_Manager::SELECT,
                    'default' => '',
                    'options' => [
                        '' => esc_html__('No Sidebar', 'devoer'),
                        'sidebar-right' => esc_html__('Sidebar Right', 'devoer'),
                        'sidebar-left' => esc_html__('Sidebar Left', 'devoer'),
                        'fullwidth' => esc_html__('Full Width', 'devoer'),
                        'fullwidth-small' => esc_html__('Full Width Small', 'devoer'),
                        'fullwidth-center' => esc_html__('Full Width Center', 'devoer'),
                    ],
                ]
            );
        }

        $element->add_control(
            'main_content_background',
            [
                'label' => esc_html__('Background', 'devoer'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .themesflat-boxed' => 'background: {{VALUE}};',
                ],
            ]
        );

        $element->add_control(
            'main_content_heading',
            [
                'label' => esc_html__('Main Content', 'devoer'),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before'
            ]
        );

        $element->add_responsive_control(
            'main_content_padding',
            [
                'label' => esc_html__('Padding', 'devoer'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'allowed_dimensions' => ['top', 'bottom'],
                'selectors' => [
                    '{{WRAPPER}} #themesflat-content' => 'padding-top: {{TOP}}{{UNIT}}; padding-bottom: {{BOTTOM}}{{UNIT}};',
                ],
            ]
        );

        $element->add_responsive_control(
            'main_content_margin',
            [
                'label' => esc_html__('Margin', 'devoer'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'allowed_dimensions' => ['top', 'bottom'],
                'selectors' => [
                    '{{WRAPPER}} #themesflat-content' => 'margin-top: {{TOP}}{{UNIT}}; margin-bottom: {{BOTTOM}}{{UNIT}};',
                ],
            ]
        );

        $element->end_controls_section();
    }

    public function themesflat_options_services($element)
    {
        // TF Services
        $element->start_controls_section(
            'themesflat_services_options',
            [
                'label' => esc_html__('TF Services', 'devoer'),
                'tab' => Controls_Manager::TAB_SETTINGS,
            ]
        );

        $element->add_control(
            'services_post_heading',
            [
                'label' => esc_html__('Services Post', 'devoer'),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $element->add_control(
            'services_post_icon',
            [
                'label' => esc_html__('Post Icon', 'devoer'),
                'type' => Controls_Manager::ICONS,
                'default' => [
                    'value' => '',
                    'library' => 'devoer',
                ],
            ]
        );

        $element->end_controls_section();
    }
}

new themesflat_options_elementor();