<?php

namespace Lknwp\CrowdfundingExtension\Includes\elementorFields\controls;

use Elementor\Controls_Manager;

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

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

        $input->add_control(
            'show_author',
            [
                'label'        => __('Show Author', '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(
            'author_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_author' => 'yes',
                ],
            ]
        );

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

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

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

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


        // Cor do texto
        $input->add_control(
            'link_author_color',
            [
                'label'     => __('Link Author Text Color', 'link-nacional-wp-crowdfunding-extension'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#0000EE',
                'condition' => [
                    'show_author' => 'yes',
                ],
            ]
        );

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

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

        $input->end_controls_section();

        return $input;
    }

    public static function getFields($settings)
    {
        $lkn_author_styles  = [];
        $lkn_link_author_styles = [];
        $lkn_author_container = [];
        $lkn_author_class = 'lknwp-author';
        $lkn_link_author_class = 'lknwp-link-author';

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

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

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

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

        $author_settings = [
            "lkn_author_styles" => $lkn_author_styles,
            "lkn_author_container" => $lkn_author_container,
            "lkn_author_class" => $lkn_author_class,
            "lkn_link_author_class" => $lkn_link_author_class,
            "lkn_link_author_styles" => $lkn_link_author_styles
        ];

        return $author_settings;
    }
}
