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

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

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

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

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

    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-accordions-styles'
        ];
    }

    protected function register_controls()
    {
        $this->start_controls_section('section_accordion', [
            'label' => __('Accordion', 'themesflat'),
        ]);
        $repeater = new Repeater();
        $repeater->add_control('accordion_name', [
            'label' => __('Accordion Name', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'default' => __('My accordion name', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);

        $repeater->add_control('short_text', [
            'type' => 'textarea',
            'label' => __('Short Text', 'themesflat'),
            'description' => __('Short text generally displayed below the title.', 'themesflat'),
        ]);

        $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('accordions', [
            'label' => __('Accordions', 'themesflat'),
            'type' => Controls_Manager::REPEATER,
            'separator' => 'before',
            'default' => [[
                'accordion_name' => __('Accordion #1', 'themesflat'),
                'accordion_details' => __('I am accordion details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ], [
                'accordion_name' => __('Accordion #2', 'themesflat'),
                'accordion_details' => __('I am accordion details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ], [
                'accordion_name' => __('Accordion #3', 'themesflat'),
                'accordion_details' => __('I am accordion details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ], [
                'accordion_name' => __('Accordion #2', 'themesflat'),
                'accordion_details' => __('I am accordion details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ],

            ],
            'fields' => $repeater->get_controls(),
            'title_field' => '{{{ accordion_name }}}',
        ]);
        $this->end_controls_section();
        $this->start_controls_section('section_general_settings', [
            'label' => __('General Settings', 'themesflat'),
            'tab' => Controls_Manager::TAB_SETTINGS,
        ]);
        $this->add_control('style', [
            'type' => Controls_Manager::SELECT,
            'label' => __('Choose Team Style', 'themesflat'),
            'default' => 'style1',
            'options' => [
                'style1' => __('Style 1', 'themesflat'),
            ],
        ]);
        $this->end_controls_section();

    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        
        $settings['title_tag'] = 'h4'; 
        $settings['per_line'] = 3;
        $settings['per_line_tablet'] = 2;
        $settings['per_line_mobile'] = 1;
        $settings = apply_filters('tfl_accordions_' . $this->get_id() . '_settings', $settings);
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part('addons/accordion/loop', $args);
    }

    protected function content_template()
    {
    }

}