<?php

namespace Elementor;

use RivaxStudio\Traits\Rivax_Group_Control_Query;
use RivaxStudio\Traits\Rivax_Global_Widget_Controls;
use RivaxStudio\Traits\Rivax_Post_skin_base;

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


class Rivax_Post_Miniline_Widget extends Widget_Base {

    use Rivax_Group_Control_Query;
    use Rivax_Global_Widget_Controls;
    use Rivax_Post_skin_base;

    public function get_name() {
        return 'rivax-post-miniline';
    }

    public function get_title() {
        return esc_html__('Post Mini Line', 'newsfy');
    }

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

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

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

    protected function register_post_controls(){

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

        $this->add_control(
            'bullet_style',
            [
                'label'     => esc_html__( 'Bullet Style', 'newsfy' ),
                'type'      => Controls_Manager::SELECT,
                'options'   => [
                    'fill'     => esc_html__( 'Fill', 'newsfy' ),
                    'circle'  => esc_html__( 'Circle', 'newsfy' ),
                ],
                'default'   => 'fill',
            ]
        );

        $this->register_title_controls('h6');

        $this->add_control(
            'show_date',
            [
                'label'     => esc_html__( 'Date', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'default'   => 'yes',
            ]
        );

        $this->add_control(
            'human_diff_time',
            [
                'label'     => esc_html__( 'Human Different Time', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'condition' => [
                    'show_date' => 'yes',
                ]
            ]
        );

        $this->add_control(
            'show_time',
            [
                'label'     => esc_html__( 'Show Time', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'condition' => [
                    'human_diff_time' => '',
                    'show_date'       => 'yes',
                ]
            ]
        );

        $this->end_controls_section();

    }


    protected function register_style_post_controls() {

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

        $this->add_responsive_control(
            'items_spacing',
            [
                'label'     => esc_html__( 'Items Spacing', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .post-wrapper' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'date_spacing',
            [
                'label'     => esc_html__( 'Date Spacing', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .date' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'item_border',
            [
                'label'     => esc_html__( 'Border', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .post-wrapper' => 'border-bottom: {{SIZE}}{{UNIT}} solid;',
                ],
            ]
        );

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

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

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

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

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

        $this->end_controls_section();


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

        $this->add_control(
            'bullet_disable_shadow',
            [
                'label'     => esc_html__( 'Disable Shadow', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'selectors' => [
                    '{{WRAPPER}} .bullet' => 'box-shadow: none;',
                ],
            ]
        );

        $this->add_control(
            'bullet_always_active',
            [
                'label'     => esc_html__( 'Always Show Active', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'selectors' => [
                    '{{WRAPPER}} .bullet::before' => 'transform: scale(0.6);',
                ],
            ]
        );

        $this->start_controls_tabs('tabs_bullet_style');
        $this->start_controls_tab('tab_bullet_normal',
            [
                'label' => esc_html__('Normal', 'newsfy'),
            ]);

        $this->add_control('line_color',
            [
                'label' => esc_html__('Line Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-post-miniline' => '--line-color: {{VALUE}};',
                ],
            ]);

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

        $this->add_control('bullet_active_bg',
            [
                'label' => esc_html__('Active Background', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bullet::before' => 'background: {{VALUE}};',
                ],
            ]);

        $this->end_controls_tab();

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

        $this->add_control('line_color_dark_mode',
            [
                'label' => esc_html__('Line Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-post-miniline' => '--line-color: {{VALUE}};',
                ],
            ]);

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

        $this->add_control('bullet_active_bg_dark_mode',
            [
                'label' => esc_html__('Active Background', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .bullet::before' => 'background: {{VALUE}};',
                ],
            ]);

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

        $this->end_controls_section();

    }


    protected function register_controls() {

        $this->register_post_controls();
        $this->register_query_builder_controls();

        $this->register_style_post_controls();
        $this->register_style_title_controls();
    }


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

}