<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_description',
            [
                'label'        => __('Show Description', '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(
            'description_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_description' => 'yes',
                ],
            ]
        );

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

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

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

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


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

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

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

        $input->add_control(
            'show_label',
            [
                'label'        => __('Show Label', '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',
            ]
        );

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_description_styles  = [];
        $lkn_content_description_styles = [];
        $lkn_description_container = [];
        $lkn_description_class = 'lknwp-description';
        $lkn_content_description_class = 'lknwp-content-description';

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

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

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

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

        $description_settings = [
            "lkn_description_styles" => $lkn_description_styles,
            "lkn_description_container" => $lkn_description_container,
            "lkn_description_class" => $lkn_description_class,
            "lkn_content_description_class" => $lkn_content_description_class,
            "lkn_content_description_styles" => $lkn_content_description_styles
        ];

        return $description_settings;
    }
}
