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

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

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

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

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

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

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

        $repeater->add_control('lfooter_title', [
            'label' => __('Title', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'default' => __('Logo Footer Title', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('lfooter_subtitle', [
            'label' => __('Logo Footer Subtitle', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('lfooter_image', [
            'label' => __('Logo Footer 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' => __('Logo Footer Items', 'themesflat'),
            'type' => Controls_Manager::REPEATER,
            'separator' => 'before',
            'default' => [[
                'lfooter_title' => __('Logo Footer #1', 'themesflat'),
                'lfooter_subtitle' => __('Subtitle', 'themesflat'),
                'lfooter_image' => '',
            ], [
                'lfooter_title' => __('Logo Footer #2', 'themesflat'),
                'lfooter_subtitle' => __('Subtitle', 'themesflat'),
                'lfooter_image' => '',
            ], [
                'lfooter_title' => __('Logo Footer  #3', 'themesflat'),
                'lfooter_subtitle' => __('Subtitle', 'themesflat'),
                'lfooter_image' => '',
            ]],
            'fields' => $repeater->get_controls(),
            'title_field' => '{{{ lfooter_title }}}',
        ]);

        $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 Style', 'themesflat'),
            'default' => 'style1',
            'options' => [
                'style1' => __('Style 1', 'themesflat'),
                'style2' => __('Style 2', 'themesflat'),
            ],
        ]);

        $this->add_control('lfooter_main', [
            'label' => __('Logo Footer', '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_lfooter_' . $this->get_id() . '_settings', $settings);
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part('addons/logo-footer/loop', $args);
    }

    protected function content_template()
    {
    }

}