<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

class LknwpCrowdfundingListingDaysControl
{
    public static function getControl($input)
    {
        $input->start_controls_section(
            'days_section',
            [
                'label' => __('Days to go', 'link-nacional-wp-crowdfunding-extension'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $input->add_control(
            'show_days',
            [
                'label'        => __('Show Days to go', '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(
            'days_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_days' => 'yes',
                ],
            ]
        );

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

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

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

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


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

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

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

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_days_styles  = [];
        $lkn_content_days_styles = [];
        $lkn_days_container = [];
        $lkn_days_class = 'lknwp-days';
        $lkn_content_days_class = 'lknwp-content-days';

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

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

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

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

        $days_settings = [
            "lkn_days_styles" => $lkn_days_styles,
            "lkn_days_container" => $lkn_days_container,
            "lkn_days_class" => $lkn_days_class,
            "lkn_content_days_class" => $lkn_content_days_class,
            "lkn_content_days_styles" => $lkn_content_days_styles
        ];

        return $days_settings;
    }
}
