<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_goal',
            [
                'label'        => __('Show Goal', '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(
            'goal_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_goal' => 'yes',
                ],
            ]
        );

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

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

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

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


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

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

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

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_goal_styles  = [];
        $lkn_content_goal_styles = [];
        $lkn_goal_container = [];
        $lkn_goal_class = 'lknwp-goal';
        $lkn_content_goal_class = 'lknwp-content-goal';

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

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

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

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

        $goal_settings = [
            "lkn_goal_styles" => $lkn_goal_styles,
            "lkn_goal_container" => $lkn_goal_container,
            "lkn_goal_class" => $lkn_goal_class,
            "lkn_content_goal_class" => $lkn_content_goal_class,
            "lkn_content_goal_styles" => $lkn_content_goal_styles
        ];

        return $goal_settings;
    }
}
