<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_progress',
            [
                'label'        => __('Show Progress', '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(
            'progress_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_progress' => 'yes',
                ],
            ]
        );

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

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

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

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

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

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

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


        $input->add_control(
            'progress_background_inside_bar',
            [
                'label'     => __('Background Inside Bar', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#ececec',
                'condition' => [
                    'show_progress' => 'yes',
                ],
            ]
        );

        $input->add_control(
            'progress_background_ouside_bar',
            [
                'label'     => __('Background Outside Bar', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#0000EE',
                'condition' => [
                    'show_progress' => 'yes',
                ],
            ]
        );

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_progress_styles  = [];
        $lkn_content_progress_styles = [];
        $lkn_progress_container = [];
        $lkn_progress_class = 'lknwp-progress';
        $lkn_content_progress_class = 'lknwp-content-progress';
        $progress_background_inside_bar = [];
        $progress_background_ouside_bar = [];

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

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

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

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

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

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

        $progress_settings = [
            "lkn_progress_styles" => $lkn_progress_styles,
            "lkn_content_progress_styles" => $lkn_content_progress_styles,
            "lkn_progress_container" => $lkn_progress_container,
            "lkn_progress_class" => $lkn_progress_class,
            "lkn_content_progress_class" => $lkn_content_progress_class,
            "progress_background_inside_bar" => $progress_background_inside_bar,
            "progress_background_ouside_bar" => $progress_background_ouside_bar
        ];

        return $progress_settings;
    }
}
