<?php
/**
 * Product Tags Widget — TAB_STYLE controls
 * Included via require inside register_controls(). $this is the widget instance.
 */

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

// ===== LABEL STYLE SECTION =====
$this->start_controls_section(
    'label_style_section',
    [
        'label' => __('Label Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_label' => 'yes',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'label_typography',
        'selector' => '{{WRAPPER}} .ggmc-tags-label',
    ]
);

$this->add_control(
    'label_color',
    [
        'label' => __('Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-label' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_responsive_control(
    'label_spacing',
    [
        'label' => __('Spacing', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'em'],
        'range' => [
            'px' => [
                'min' => 0,
                'max' => 30,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 8,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-label' => 'margin-right: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== TAG LINK STYLE SECTION =====
$this->start_controls_section(
    'link_style_section',
    [
        'label' => __('Tag Link Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'link_typography',
        'selector' => '{{WRAPPER}} .ggmc-tag-link',
    ]
);

$this->start_controls_tabs('link_color_tabs');

$this->start_controls_tab(
    'link_normal_tab',
    [
        'label' => __('Normal', 'ggm-commerce'),
    ]
);

$this->add_control(
    'link_color',
    [
        'label' => __('Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'link_background',
    [
        'label' => __('Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link' => 'background-color: {{VALUE}};',
        ],
        'condition' => [
            'display_layout' => 'badges',
        ],
    ]
);

$this->end_controls_tab();

$this->start_controls_tab(
    'link_hover_tab',
    [
        'label' => __('Hover', 'ggm-commerce'),
    ]
);

$this->add_control(
    'link_hover_color',
    [
        'label' => __('Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link:hover' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'link_hover_background',
    [
        'label' => __('Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link:hover' => 'background-color: {{VALUE}};',
        ],
        'condition' => [
            'display_layout' => 'badges',
        ],
    ]
);

$this->end_controls_tab();

$this->end_controls_tabs();

$this->add_control(
    'link_decoration',
    [
        'label' => __('Text Decoration', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'none',
        'options' => [
            'none' => __('None', 'ggm-commerce'),
            'underline' => __('Underline', 'ggm-commerce'),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link' => 'text-decoration: {{VALUE}};',
        ],
        'separator' => 'before',
    ]
);

$this->add_control(
    'link_hover_decoration',
    [
        'label' => __('Hover Text Decoration', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'underline',
        'options' => [
            'none' => __('None', 'ggm-commerce'),
            'underline' => __('Underline', 'ggm-commerce'),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-link:hover' => 'text-decoration: {{VALUE}};',
        ],
    ]
);

$this->end_controls_section();

// ===== BADGE STYLE SECTION =====
$this->start_controls_section(
    'badge_style_section',
    [
        'label' => __('Badge Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'display_layout' => 'badges',
        ],
    ]
);

// Normal/Hover Tabs
$this->start_controls_tabs('badge_style_tabs');

$this->start_controls_tab(
    'badge_normal_tab',
    [
        'label' => __('Normal', 'ggm-commerce'),
    ]
);

$this->add_control(
    'badge_background_color',
    [
        'label' => __('Background Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'badge_text_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'badge_border',
        'label' => __('Border', 'ggm-commerce'),
        'selector' => '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link',
    ]
);

$this->end_controls_tab();

$this->start_controls_tab(
    'badge_hover_tab',
    [
        'label' => __('Hover', 'ggm-commerce'),
    ]
);

$this->add_control(
    'badge_hover_background_color',
    [
        'label' => __('Background Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link:hover' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'badge_hover_text_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link:hover' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'badge_hover_border_color',
    [
        'label' => __('Border Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link:hover' => 'border-color: {{VALUE}};',
        ],
    ]
);

$this->end_controls_tab();

$this->end_controls_tabs();

$this->add_responsive_control(
    'badge_padding',
    [
        'label' => __('Padding', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'default' => [
            'top' => '4',
            'right' => '12',
            'bottom' => '4',
            'left' => '12',
            'unit' => 'px',
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        'separator' => 'before',
    ]
);

$this->add_control(
    'badge_border_radius',
    [
        'label' => __('Border Radius', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', '%'],
        'default' => [
            'top' => '20',
            'right' => '20',
            'bottom' => '20',
            'left' => '20',
            'unit' => 'px',
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges .ggmc-tag-link' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'badge_gap',
    [
        'label' => __('Gap Between Badges', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'em'],
        'range' => [
            'px' => [
                'min' => 0,
                'max' => 30,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 8,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tags-badges' => 'gap: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== ICON STYLE SECTION =====
$this->start_controls_section(
    'icon_style_section',
    [
        'label' => __('Icon Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_icon' => 'yes',
            'display_layout' => 'badges',
        ],
    ]
);

$this->add_control(
    'icon_color',
    [
        'label' => __('Icon Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-icon' => 'color: {{VALUE}};',
        ],
        'description' => __('Leave empty to inherit from link color', 'ggm-commerce'),
    ]
);

$this->add_responsive_control(
    'icon_size',
    [
        'label' => __('Icon Size', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'em'],
        'range' => [
            'px' => [
                'min' => 8,
                'max' => 24,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 12,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-icon' => 'font-size: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'icon_spacing',
    [
        'label' => __('Icon Spacing', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => 0,
                'max' => 15,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 4,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-tag-icon' => 'margin-right: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();
