<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_location',
            [
                'label'        => __('Show Location', '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(
            'location_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_location' => 'yes',
                ],
            ]
        );

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

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

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

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


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

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

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

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_location_styles  = [];
        $lkn_content_location_styles = [];
        $lkn_location_container = [];
        $lkn_location_class = 'lknwp-location';
        $lkn_content_location_class = 'lknwp-content-location';

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

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

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

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

        $location_settings = [
            "lkn_location_styles" => $lkn_location_styles,
            "lkn_location_container" => $lkn_location_container,
            "lkn_location_class" => $lkn_location_class,
            "lkn_content_location_class" => $lkn_content_location_class,
            "lkn_content_location_styles" => $lkn_content_location_styles
        ];

        return $location_settings;
    }
}
