<?php
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-categories-label',
    ]
);

$this->add_control(
    'label_color',
    [
        'label' => __('Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-categories-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-categories-label' => 'margin-right: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== CATEGORY LINK STYLE SECTION =====
$this->start_controls_section(
    'link_style_section',
    [
        'label' => __('Category 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-category-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-category-link' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'link_background',
    [
        'label' => __('Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-category-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-category-link:hover' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'link_hover_background',
    [
        'label' => __('Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-category-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-category-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-category-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-categories-badges .ggmc-category-link' => 'background-color: {{VALUE}};',
        ],
    ]
);

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

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'badge_border',
        'label' => __('Border', 'ggm-commerce'),
        'selector' => '{{WRAPPER}} .ggmc-categories-badges .ggmc-category-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-categories-badges .ggmc-category-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-categories-badges .ggmc-category-link:hover' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'badge_hover_border_color',
    [
        'label' => __('Border Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-categories-badges .ggmc-category-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-categories-badges .ggmc-category-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-categories-badges .ggmc-category-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-categories-badges' => 'gap: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== IMAGE STYLE SECTION =====
$this->start_controls_section(
    'image_style_section',
    [
        'label' => __('Category Image Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_image' => 'yes',
            'display_layout!' => 'inline',
        ],
    ]
);

$this->add_responsive_control(
    'image_size',
    [
        'label' => __('Image Size', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => 20,
                'max' => 100,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 32,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-category-image' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
        ],
    ]
);

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

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

$this->end_controls_section();
