<?php

namespace Elementor;

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


class Rivax_Current_Date_Widget extends Widget_Base {

    public function get_name() {
        return 'rivax-current-date';
    }

    public function get_title() {
        return esc_html__('Current Date', 'newsfy');
    }

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

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

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

    protected function register_controls()
    {

        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__('Content', 'newsfy'),
            ]
        );

        $this->add_control(
            'date_style',
            [
                'label' => esc_html__('Style', 'newsfy'),
                'type' => Controls_Manager::SELECT,
                'default' => '1',
                'options' => [
                    '1' => esc_html__('1', 'newsfy'),
                    '2' => esc_html__('2', 'newsfy'),
                ],
            ]
        );

        $this->add_control(
            'date_format',
            [
                'label' => esc_html__( 'Date Format', 'newsfy' ),
                'type' => Controls_Manager::TEXT,
                'default' => 'F j, Y',
                'condition' => [
                    'date_style' => '1',
                ],
            ]
        );

        $this->add_control(
            'date_format_info',
            [
                'type'      => Controls_Manager::ALERT,
                'alert_type' => 'info',
                'content'       => sprintf(esc_html__('%s Date Format Documentation %s', 'newsfy'), '<a href="https://wordpress.org/documentation/article/customize-date-and-time-format/" target="_blank">', '</a>'),
                'condition' => [
                    'date_style' => '1',
                ],
            ]
        );

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

        $this->add_control(
            'date_icon',
            [
                'label' => esc_html__( 'Icon', 'newsfy' ),
                'type' => Controls_Manager::ICONS,
				'skin' => 'inline',
                'label_block' => false,
            ]
        );


        $this->add_control(
            'text_align', [
                'label' => esc_html__('Alignment', 'newsfy'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [

                    'left' => [
                        'title' => esc_html__('Left', 'newsfy'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'newsfy'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'newsfy'),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}}' => 'text-align: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_section();


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

        $this->add_control(
            'content_padding',
            [
                'label' => esc_html__('Padding', 'newsfy'),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .current-date' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );


        $this->add_control(
            'content_border_radius',
            [
                'label' => esc_html__( 'Border Radius', 'newsfy' ),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .current-date' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'content_shadow',
                'label' => esc_html__( 'Box Shadow', 'newsfy' ),
                'selector' => '{{WRAPPER}} .current-date',
            ]
        );

        $this->start_controls_tabs( 'tabs_content' );

        /* Normal */
        $this->start_controls_tab(
            'tab_content_normal',
            [
                'label' => esc_html__( 'Normal', 'newsfy' ),
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'content_bg',
                'label' => esc_html__('Background', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => '{{WRAPPER}} .current-date',
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'content_border',
                'label' => esc_html__( 'Border', 'newsfy' ),
                'selector' => '{{WRAPPER}} .current-date',
            ]
        );

        $this->end_controls_tab();

        /* Dark Mode */
        $this->start_controls_tab(
            'tab_content_dark_mode',
            [
                'label' => esc_html__( 'Dark Mode', 'newsfy' ),
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'content_bg_dark_mode',
                'label' => esc_html__('Background - Dark Mode', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => 'html[scheme="dark"] {{WRAPPER}} .current-date',
            ]
        );

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

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

        $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_padding',
            [
                'label' => esc_html__('Padding', 'newsfy'),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .title-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'title_spacing',
            [
                'label'     => esc_html__( 'Spacing', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 0,
                        'max' => 30,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .current-date' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );


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

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


        $this->start_controls_tabs( 'tabs_title' );

        /* Normal */
        $this->start_controls_tab(
            'tab_title_normal',
            [
                'label' => esc_html__( 'Normal', 'newsfy' ),
            ]
        );

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

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'title_bg',
                'label' => esc_html__('Background', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => '{{WRAPPER}} .title-wrapper',
            ]
        );


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

        $this->end_controls_tab();

        /* Dark Mode */
        $this->start_controls_tab(
            'tab_title_dark_mode',
            [
                'label' => esc_html__( 'Dark Mode', 'newsfy' ),
            ]
        );

        $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_Background::get_type(),
            [
                'name' => 'title_bg_dark_mode',
                'label' => esc_html__('Background - Dark Mode', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => 'html[scheme="dark"] {{WRAPPER}} .title-wrapper',
            ]
        );

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

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


        $this->add_control(
            'heading_style_icon',
            [
                'label'     => esc_html__( 'Icon', 'newsfy' ),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'icon_font_size',
            [
                'label'     => esc_html__( 'Font Size', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 8,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .icon' => 'font-size: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'icon_spacing',
            [
                'label'     => esc_html__( 'Spacing', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 0,
                        'max' => 30,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .title-wrapper' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

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

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

        $this->end_controls_section();




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

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


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


        $this->start_controls_tabs( 'tabs_date' );

        /* Normal */
        $this->start_controls_tab(
            'tab_date_normal',
            [
                'label' => esc_html__( 'Normal', 'newsfy' ),
            ]
        );

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

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'date_bg',
                'label' => esc_html__('Background', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => '{{WRAPPER}} .date-wrapper',
            ]
        );

        $this->end_controls_tab();

        /* Dark Mode */
        $this->start_controls_tab(
            'tab_date_dark_mode',
            [
                'label' => esc_html__( 'Dark Mode', 'newsfy' ),
            ]
        );

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

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'date_bg_dark_mode',
                'label' => esc_html__('Background - Dark Mode', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => 'html[scheme="dark"] {{WRAPPER}} .date-wrapper',
            ]
        );

        $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';
    }

}