<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

class LknwpCrowdfundingListingTitleControl
{
    public static function getControl($input)
    {
        $input->start_controls_section(
            'title_section',
            [
                'label' => __('Title', 'link-nacional-wp-crowdfunding-extension'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $input->add_control(
            'show_title',
            [
                'label'        => __('Show Title', 'link-nacional-wp-crowdfunding-extension'),
                'type'         => Controls_Manager::SWITCHER,
                'label_on'     => __('Yes', 'link-nacional-wp-crowdfunding-extension'),
                'label_off'    => __('No', 'link-nacional-wp-crowdfunding-extension'),
                'return_value' => 'yes',
                'default'      => 'yes',
            ]
        );

        // Alinhamento com controle para desktop, tablet e mobile
        $input->add_control(
            'title_alignment',
            [
                'label'     => __('Text Alignment', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::CHOOSE,
                'options'   => [
                    'left'   => [
                        'title' => __('Left', 'link-nacional-wp-crowdfunding-extension'),
                        'icon'  => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => __('Center', 'link-nacional-wp-crowdfunding-extension'),
                        'icon'  => 'eicon-text-align-center',
                    ],
                    'right'  => [
                        'title' => __('Right', 'link-nacional-wp-crowdfunding-extension'),
                        'icon'  => 'eicon-text-align-right',
                    ],
                ],
                'default'   => 'left',
                'condition' => [
                    'show_title' => 'yes',
                ],
            ]
        );

        // Cor do texto
        $input->add_control(
            'title_color',
            [
                'label'     => __('Title Text Color', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#5d5d5d',
                'condition' => [
                    'show_title' => 'yes',
                ],
            ]
        );

        $input->add_control(
            'title_background_color',
            [
                'label'     => __('Background Color', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::COLOR,
                'default'   => 'transparent',
                'condition' => [
                    'show_title' => 'yes',
                ],
            ]
        );

        // Tipografia (Fonte, Tamanho, Estilo, etc.)
        $input->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name'      => 'title_typography',
                'label'     => __('Typography', 'link-nacional-wp-crowdfunding-extension'),
                'selector'  => '{{WRAPPER}} .lknwp-title',
                'condition' => [
                    'show_title' => 'yes',
                ],
            ]
        );

        // Sombra do texto
        $input->add_group_control(
            \Elementor\Group_Control_Text_Shadow::get_type(),
            [
                'name'      => 'title_text_shadow',
                'label'     => __('Text Shadow', 'link-nacional-wp-crowdfunding-extension'),
                'selector'  => '{{WRAPPER}} .lknwp-title',
                'condition' => [
                    'show_title' => 'yes',
                ],
            ]
        );

        $input->add_responsive_control(
            'title_padding',
            [
                'label'      => __('Padding', 'link-nacional-wp-crowdfunding-extension'),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'selectors'  => [
                    '{{WRAPPER}} .lknwp-title' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'condition'  => [
                    'show_title' => 'yes',
                ],
            ]
        );


        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_title_styles  = [];
        $lkn_title_container = [];
        $lkn_title_class = 'lknwp-title';

        // Alinhamento
        if (!empty($settings['title_alignment'])) {
            $lkn_title_container[] = 'text-align: ' . $settings['title_alignment'] . ';';
        }

        // Cor do texto
        if (!empty($settings['title_color'])) {
            $lkn_title_styles[] = 'color: ' . $settings['title_color'] . ';';
        }

        // Cor de fundo
        if (!empty($settings['title_background_color'])) {
            $lkn_title_container[] = 'background-color: ' . $settings['title_background_color'] . ';';
        }

        $title_settings = [
            "lkn_title_styles" => $lkn_title_styles,
            "lkn_title_container" => $lkn_title_container,
            "lkn_title_class" => $lkn_title_class,
        ];

        return $title_settings;
    }
}
