<?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_List_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-list';
    }

    public function get_title()
    {
        return __('List', 'themesflat');
    }

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

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

    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/list-lists/';
    }

    public function get_script_depends()
    {
        return ['tfl-waypoints', 'tfl-frontend-scripts'];
    }

    public function get_style_depends()
    {
        return [
            'tfl-icomoon-styles',
            'tfl-animate-styles',
            'tfl-frontend-styles',
            'tfl-list-lists-styles'
        ];
    }

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

        $repeater->add_control('list_title', [
            'label' => __('Title', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'default' => __('List Title', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('list_subtitle', [
            'label' => __('List Subtitle', 'themesflat'),
            'type' => Controls_Manager::TEXTAREA,
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('list_image', [
            'label' => __('List Image', 'themesflat'),
            'type' => Controls_Manager::MEDIA,
            'default' => [
                'url' => Utils::get_placeholder_image_src(),
            ],
            'label_block' => true,
            '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 Members', 'themesflat'),
            'type' => Controls_Manager::REPEATER,
            'separator' => 'before',
            'default' => [[
                'list_title' => __('List Member #1', 'themesflat'),
                'list_subtitle' => __('CEO', 'themesflat'),
                'list_image' => '',
            ], [
                'list_title' => __('List Member #2', 'themesflat'),
                'list_subtitle' => __('Lead Developer', 'themesflat'),
                'list_image' => '',
            ], [
                'list_title' => __('List Member #3', 'themesflat'),
                'list_subtitle' => __('Finance Manager', 'themesflat'),
                'list_image' => '',
            ]],
            'fields' => $repeater->get_controls(),
            'title_field' => '{{{ list_title }}}',
        ]);

        $this->end_controls_section();

        $this->start_controls_section('section_general_settings', [
            'label' => __('General Settings', 'themesflat'),
            'tab' => Controls_Manager::TAB_SETTINGS,
        ]);

        $this->add_control('list_bg', [
            'label' => __('List BG', 'themesflat'),
            'type' => Controls_Manager::MEDIA,
            'default' => [
                'url' => Utils::get_placeholder_image_src(),
            ],
            'label_block' => true,
            'dynamic' => [
                'active' => true,
            ],
        ]);

        $this->end_controls_section();

    }

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

    protected function content_template()
    {
    }

}