<?php
/**
 * Taxonomy Header Widget — TAB_STYLE controls
 * Included via bare require inside register_controls().
 * $this refers to the widget instance.
 */

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

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

$this->add_control(
    'image_position',
    [
        'label' => __('Image Position', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'above',
        'options' => [
            'above' => __('Above Title', 'ggm-commerce'),
            'below' => __('Below Title', 'ggm-commerce'),
            'left' => __('Left of Content', 'ggm-commerce'),
            'right' => __('Right of Content', 'ggm-commerce'),
            'background' => __('Background', 'ggm-commerce'),
        ],
    ]
);

$this->add_responsive_control(
    'image_width',
    [
        'label' => __('Image Width', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', '%', 'vw'],
        'range' => [
            'px' => [
                'min' => 50,
                'max' => 800,
            ],
            '%' => [
                'min' => 10,
                'max' => 100,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 200,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-image img' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%;',
        ],
        'condition' => [
            'image_position!' => 'background',
        ],
    ]
);

$this->add_responsive_control(
    'image_height',
    [
        'label' => __('Image Height', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'vh'],
        'range' => [
            'px' => [
                'min' => 50,
                'max' => 600,
            ],
            'vh' => [
                'min' => 10,
                'max' => 100,
            ],
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-image img' => 'height: {{SIZE}}{{UNIT}}; object-fit: cover;',
        ],
        'condition' => [
            'image_position!' => 'background',
        ],
    ]
);

$this->add_control(
    'image_border_radius',
    [
        'label' => __('Border Radius', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', '%'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        'condition' => [
            'image_position!' => 'background',
        ],
    ]
);

$this->add_responsive_control(
    'image_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-image' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        'condition' => [
            'image_position!' => 'background',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Box_Shadow::get_type(),
    [
        'name' => 'image_box_shadow',
        'selector' => '{{WRAPPER}} .ggmc-taxonomy-image img',
        'condition' => [
            'image_position!' => 'background',
        ],
    ]
);

// Background image specific controls
$this->add_responsive_control(
    'background_height',
    [
        'label' => __('Background Height', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'vh'],
        'range' => [
            'px' => [
                'min' => 100,
                'max' => 800,
            ],
            'vh' => [
                'min' => 10,
                'max' => 100,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 300,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-header--background' => 'min-height: {{SIZE}}{{UNIT}};',
        ],
        'condition' => [
            'image_position' => 'background',
        ],
    ]
);

$this->add_control(
    'background_overlay',
    [
        'label' => __('Overlay Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => 'rgba(0,0,0,0.4)',
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-header--background::before' => 'background-color: {{VALUE}};',
        ],
        'condition' => [
            'image_position' => 'background',
        ],
    ]
);

$this->end_controls_section();

// ===== TITLE STYLE SECTION =====
$this->start_controls_section(
    'title_style_section',
    [
        'label' => __('Title Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_title' => 'yes',
        ],
    ]
);

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

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

$this->add_control(
    'prefix_color',
    [
        'label' => __('Prefix Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-prefix' => 'color: {{VALUE}};',
        ],
        'description' => __('Leave empty to inherit from title color', 'ggm-commerce'),
    ]
);

$this->add_responsive_control(
    'title_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== DESCRIPTION STYLE SECTION =====
$this->start_controls_section(
    'description_style_section',
    [
        'label' => __('Description Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_description' => 'yes',
        ],
    ]
);

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

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

$this->add_responsive_control(
    'description_max_width',
    [
        'label' => __('Max Width', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', '%'],
        'range' => [
            'px' => [
                'min' => 200,
                'max' => 1200,
            ],
            '%' => [
                'min' => 20,
                'max' => 100,
            ],
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-description' => 'max-width: {{SIZE}}{{UNIT}}; margin-left: auto; margin-right: auto;',
        ],
    ]
);

$this->add_responsive_control(
    'description_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== PRODUCT COUNT STYLE SECTION =====
$this->start_controls_section(
    'count_style_section',
    [
        'label' => __('Product Count Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_product_count' => 'yes',
        ],
    ]
);

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

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

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

$this->add_responsive_control(
    'count_padding',
    [
        'label' => __('Padding', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-count' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_control(
    'count_border_radius',
    [
        'label' => __('Border Radius', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', '%'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-count' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'count_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-count' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// ===== CONTAINER STYLE SECTION =====
$this->start_controls_section(
    'container_style_section',
    [
        'label' => __('Container Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

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

$this->add_responsive_control(
    'container_padding',
    [
        'label' => __('Padding', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em', '%'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-header' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'container_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em', '%'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-header' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'container_border',
        'selector' => '{{WRAPPER}} .ggmc-taxonomy-header',
    ]
);

$this->add_control(
    'container_border_radius',
    [
        'label' => __('Border Radius', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', '%'],
        'selectors' => [
            '{{WRAPPER}} .ggmc-taxonomy-header' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();
