<?php

namespace Elementor;

use RivaxStudio\Traits\Rivax_Group_Control_Query;

if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly


class Rivax_Horizontal_Tags_Widget extends Widget_Base {

    use Rivax_Group_Control_Query;

    public function get_name() {
        return 'rivax-horizontal-tags';
    }

    public function get_title() {
        return esc_html__('Horizontal Tags', 'newsfy');
    }

    public function get_icon() {
        return 'eicon-navigation-horizontal rivax-e-icon';
    }

    protected function get_html_wrapper_class() {
        return $this->get_name() . '-widget';
    }

    public function get_categories() {
        return ['rivax-elements'];
    }

	public function get_style_depends() {
        return [ 'swiper', 'e-swiper' ];
	}


    protected function register_controls() {

        $this->start_controls_section(
            'section_settings',
            [
                'label' => esc_html__( 'Settings', 'newsfy' ),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title',
            [
                'label'     => esc_html__( 'Title', 'newsfy' ),
                'type'      => Controls_Manager::TEXT,
                'default'   => esc_html__( 'Popular Tags:', 'newsfy' ),
            ]
        );

        $this->add_control('open_link_new_tab', [
            'label' => esc_html__('Open Link New Tab', 'newsfy'),
            'type' => Controls_Manager::SWITCHER,
        ]);

        $this->add_control(
            'source',
            [
                'label'     => esc_html__( 'source', 'newsfy' ),
                'type'      => Controls_Manager::SELECT,
                'options'   => [
                    'post_tag'     => esc_html__( 'Posts Tags', 'newsfy' ),
                    'category'  => esc_html__( 'Categories', 'newsfy' ),
                ],
                'default'   => 'post_tag',
            ]
        );

        $this->add_control(
            'count',
            [
                'label' => esc_html__( 'Count', 'newsfy' ),
                'type' => Controls_Manager::NUMBER,
                'min' => 10,
                'max' => 30,
            ]
        );

        $this->end_controls_section();


        $this->start_controls_section('section_style_title',
            [
                'label' => esc_html__('Title', 'newsfy'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control('title_color',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .title-wrapper' => 'color: {{VALUE}};',
                ],
            ]);

        $this->add_control('title_color_dark_mode',
            [
                'label' => esc_html__('Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .title-wrapper' => 'color: {{VALUE}};',
                ],
            ]);

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'title_typography',
                'label' => esc_html__('Typography', 'newsfy'),
                'selector' => '{{WRAPPER}} .title-wrapper',
            ]);

        $this->end_controls_section();


        $this->start_controls_section('section_style_navigation',
            [
                'label' => esc_html__('Navigation', 'newsfy'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control('navigation_size',
            [
                'label' => esc_html__('Size', 'newsfy'),
                'type' => Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .arrows-wrapper a' => 'font-size: {{SIZE}}{{UNIT}};',
                ],
            ]);

        $this->start_controls_tabs('navigation_tabs');
        # Normal State Tab
        $this->start_controls_tab(
            'navigation_tab_normal',
            [
                'label' => esc_html__('Normal', 'newsfy'),
            ]
        );

        $this->add_control(
            'navigation_color',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .arrows-wrapper a' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'navigation_color_dark_mode',
            [
                'label' => esc_html__('Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .arrows-wrapper a' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->end_controls_tab();

        # Hover State Tab
        $this->start_controls_tab(
            'navigation_tab_hover',
            [
                'label' => esc_html__('Hover', 'newsfy'),
            ]
        );

        $this->add_control(
            'navigation_color_hover',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .arrows-wrapper a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'navigation_color_hover_dark_mode',
            [
                'label' => esc_html__('Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .arrows-wrapper a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->end_controls_section();


        $this->start_controls_section('section_style_items',
            [
                'label' => esc_html__('Items', 'newsfy'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control('items_padding',
            [
                'label' => esc_html__('Padding', 'newsfy'),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]);

        $this->add_responsive_control('items_border_radius',
            [
                'label' => esc_html__('Border Radius', 'newsfy'),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]);

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'items_typography',
                'label' => esc_html__('Typography', 'newsfy'),
                'selector' => '{{WRAPPER}} .items-wrapper a',
            ]);

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'items_border',
                'selector' => '{{WRAPPER}} .items-wrapper a',
            ]);

        $this->start_controls_tabs('items_tabs');
        # Normal State Tab
        $this->start_controls_tab(
            'items_tab_normal',
            [
                'label' => esc_html__('Normal', 'newsfy'),
            ]
        );

        $this->add_control(
            'items_color',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_color_dark_mode',
            [
                'label' => esc_html__('Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_bg',
            [
                'label' => esc_html__('Background', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a' => 'background: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_bg_dark_mode',
            [
                'label' => esc_html__('Background - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a' => 'background: {{VALUE}}',
                ],
            ]
        );

        $this->add_control('items_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'items_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->end_controls_tab();

        # Hover State Tab
        $this->start_controls_tab(
            'items_tab_hover',
            [
                'label' => esc_html__('Hover', 'newsfy'),
            ]
        );

        $this->add_control(
            'items_color_hover',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_color_hover_dark_mode',
            [
                'label' => esc_html__('Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_bg_hover',
            [
                'label' => esc_html__('Background', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a:hover' => 'background: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'items_bg_hover_dark_mode',
            [
                'label' => esc_html__('Background - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a:hover' => 'background: {{VALUE}}',
                ],
            ]
        );

        $this->add_control('items_hover_border_color',
            [
                'label' => esc_html__('Border Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'items_border_border!' => '',
                ],
                'selectors' => [
                    '{{WRAPPER}} .items-wrapper a:hover' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->add_control('items_hover_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'items_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .items-wrapper a:hover' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->end_controls_section();
    }


    protected function render()
    {
        $settings = $this->get_settings_for_display();

        $widget_path_name = str_replace('rivax-', '', $this->get_name() );
        include RIVAX_THEME_DIR . '/elementor/templates/' . $widget_path_name . '/' . $widget_path_name . '.php';
    }

}