<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_fund_raised',
            [
                'label'        => __('Show Fund Raised', '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(
            'fund_raised_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_fund_raised' => 'yes',
                ],
            ]
        );

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

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

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

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


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

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

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

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_fund_raised_styles  = [];
        $lkn_content_fund_raised_styles = [];
        $lkn_fund_raised_container = [];
        $lkn_fund_raised_class = 'lknwp-fund_raised';
        $lkn_content_fund_raised_class = 'lknwp-content-fund_raised';

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

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

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

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

        $fund_raised_settings = [
            "lkn_fund_raised_styles" => $lkn_fund_raised_styles,
            "lkn_fund_raised_container" => $lkn_fund_raised_container,
            "lkn_fund_raised_class" => $lkn_fund_raised_class,
            "lkn_content_fund_raised_class" => $lkn_content_fund_raised_class,
            "lkn_content_fund_raised_styles" => $lkn_content_fund_raised_styles
        ];

        return $fund_raised_settings;
    }
}
