<?php

namespace ThemesflatAddons\Widgets;

use  Elementor\Repeater;
use  Elementor\Widget_Base;
use  Elementor\Controls_Manager;
use  Elementor\Utils;
use  Elementor\Scheme_Color;
use  Elementor\Group_Control_Typography;
use  Elementor\Group_Control_Image_Size;
use  Elementor\Scheme_Typography;
use  Elementor\Modules\DynamicTags\Module as TagsModule;

if (!defined('ABSPATH')) {
    exit;
}

// Exit if accessed directly
class TFL_Blur_Box_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-blur-box';
    }

    public function get_title()
    {
        return __('Blur-box', 'themesflat');
    }

    public function get_icon()
    {
        return 'tfl-icon-list';
    }

    public function get_categories()
    {
        return array('themesflat-addons');
    }


    protected function register_controls()
    {
        $this->start_controls_section('section_list_boxes', [
            'label' => __('List Boxes', 'themesflat'),
        ]);
        $repeater = new Repeater();

        $repeater->add_control('box_title', [
            'label' => __('Box Title', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'default' => __('Box Title', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('box_subtitle', [
            'label' => __('Box Subtitle', 'themesflat'),
            'type' => Controls_Manager::TEXTAREA,
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('box_image', [
            'label' => __('Box Image', 'themesflat'),
            'type' => Controls_Manager::MEDIA,
            'default' => [
                'url' => Utils::get_placeholder_image_src(),
            ],
            'label_block' => true,
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $this->add_group_control(Group_Control_Image_Size::get_type(), [
            'name' => 'thumbnail_size',
            'label' => __('Box Image Size', 'themesflat'),
            'default' => 'full',
        ]);

        $repeater->add_control( 'link', [
            'type'        => Controls_Manager::TEXT,
            'label'       => __( 'Link', 'themesflat' ),
            'label_block' => true,
            'separator'   => 'before',
            'default'     => '#',
            'dynamic'     => [
                'active' => true,
            ],
        ] );

        $repeater->add_control("widget_animation", [
            "type" => Controls_Manager::SELECT,
            "label" => __("Animation Type", "themesflat"),
            'options' => tfl_get_animation_options(),
            'default' => 'none',
            'separator' => 'before',
        ]);
        $this->add_control('items', [
            'label' => __('List Boxes', 'themesflat'),
            'type' => Controls_Manager::REPEATER,
            'separator' => 'before',
            'default' => [[
                'box_title' => __('Gardening Watering', 'themesflat'),
                'box_subtitle' => __('Landscaping', 'themesflat'),
                'box_image' => [
                    'url' => TFL_PLG_PATH . 'assets/images/blur-box/box-demo1.jpg',
                ],
            ], [
                'box_title' => __('Gardening Watering', 'themesflat'),
                'box_subtitle' => __('Landscaping', 'themesflat'),
                'box_image' => [
                    'url' => TFL_PLG_PATH . 'assets/images/blur-box/box-demo2.jpg',
                ],
            ], [
                'box_title' => __('Gardening Watering', 'themesflat'),
                'box_subtitle' => __('Landscaping', 'themesflat'),
                'box_image' => [
                    'url' => TFL_PLG_PATH . 'assets/images/blur-box/box-demo3.jpg',
                ],
            ], [
                'box_title' => __('Gardening Watering', 'themesflat'),
                'box_subtitle' => __('Landscaping', 'themesflat'),
                'box_image' => [
                    'url' => TFL_PLG_PATH . 'assets/images/blur-box/box-demo4.jpg',
                ],
            ]],
            'fields' => $repeater->get_controls(),
            'title_field' => '{{{ box_title }}}',
        ]);

        $this->end_controls_section();

//        general
        $this->start_controls_section('section_general_settings', [
            'label' => __('General Settings', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
            $this->add_control( 'style', [
                'type'    => Controls_Manager::SELECT,
                'label'   => __( 'Choose Style', 'themesflat' ),
                'default' => 'style1',
                'options' => [
                    'style1' => __( 'Style 1', 'themesflat' ),
                    'style2' => __( 'Style 2', 'themesflat' ),
                ],
            ] );

            $this->add_control('bg_color', [
                'label' => __('BG Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-image-wrapper:after' => 'background-image: linear-gradient(transparent,{{VALUE}});',
                    '{{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-image-wrapper:after' => 'background: {{VALUE}};',
                ],
            ]);

        $this->end_controls_section();

//        title
        $this->start_controls_section('section_box_title', ['label' => __('Title', 'themesflat'),'tab' => Controls_Manager::TAB_STYLE,]);
            $this->add_group_control(Group_Control_Typography::get_type(), [
                'name' => 'box_title_typography',
                'selector' => '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-box-item-text .tfl-title a,
                {{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .tfl-title a',
            ]);
            $this->add_control('box_title_color', [
                'label' => __('Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-box-item-text .tfl-title a, 
                    {{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .tfl-title a' => 'color: {{VALUE}};',
                ],
            ]);
            $this->add_control('box_title_hover_color', [
                'label' => __('Hover Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-box-item-text .tfl-title a:hover,
                    {{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .tfl-title a:hover' => 'color: {{VALUE}};',
                ],
            ]);
        $this->end_controls_section();

//        sub-title
        $this->start_controls_section('section_box_subtitle', ['label' => __('Sub-Title', 'themesflat'),'tab' => Controls_Manager::TAB_STYLE,]);
            $this->add_group_control(Group_Control_Typography::get_type(), [
                'name' => 'box_subtitle_typography',
                'selector' => '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-box-item-text .tfl-subtitle,
                {{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .tfl-subtitle',
            ]);
            $this->add_control('box_subtitle_color', [
                'label' => __('Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style1 .tfl-grid-item .tfl-box-item-text .tfl-subtitle,
                    {{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .tfl-subtitle' => 'color: {{VALUE}};',
                ],
            ]);
        $this->end_controls_section();


//       icon
        $this->start_controls_section('section_box_icon', ['label' => __('Icon', 'themesflat'),'tab' => Controls_Manager::TAB_STYLE,]);
            $this->add_control('icon_text', [
                'label' => __('Icon Text', 'themesflat'),
                'type' => Controls_Manager::TEXT,
                'default' => '<i aria-hidden="true" class="fas fa-arrow-right"></i>',
                'dynamic' => [
                    'active' => true,
                ],
            ]);
            $this->add_control('box_icon_color', [
                'label' => __('Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .wrap-arrow' => 'color: {{VALUE}};',
                ],
            ]);
            $this->add_control('box_icon_hover_color', [
                'label' => __('Hover Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .wrap-arrow:hover' => 'color: {{VALUE}};',
                ],
            ]);

            $this->add_control('box_icon_bg_color', [
                'label' => __('BG Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .wrap-arrow' => 'background: {{VALUE}};',
                ],
            ]);
            $this->add_control('box_icon_hover_bg_color', [
                'label' => __('BG Hover Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-blur_box-items-style2 .tfl-grid-item .tfl-box-item-text .wrap-arrow:hover' => 'background: {{VALUE}};',
                ],
            ]);

        $this->end_controls_section();

    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters('tfl_boxes_' . $this->get_id() . '_settings', $settings);
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part('addons/blur-box/loop', $args);
    }

    protected function content_template()
    {
    }

}