<?php
// If this file is called directly, abort.
if (! defined('ABSPATH')) {
    exit;
}

// === LAYOUT STYLE ===
$this->start_controls_section(
    'layout_style_section',
    [
        'label' => __('Layout', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_responsive_control(
    'layout_justify',
    [
        'label' => __('Justify Content', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => '',
        'options' => [
            '' => __('Default', 'ggm-commerce'),
            'flex-start' => __('Start', 'ggm-commerce'),
            'center' => __('Center', 'ggm-commerce'),
            'flex-end' => __('End', 'ggm-commerce'),
            'space-between' => __('Space Between', 'ggm-commerce'),
            'space-around' => __('Space Around', 'ggm-commerce'),
            'space-evenly' => __('Space Evenly', 'ggm-commerce'),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-add-to-cart-wrapper' => 'justify-content: {{VALUE}};',
        ],
    ]
);

$this->add_responsive_control(
    'layout_align',
    [
        'label' => __('Align Items', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => '',
        'options' => [
            '' => __('Default', 'ggm-commerce'),
            'flex-start' => __('Start', 'ggm-commerce'),
            'center' => __('Center', 'ggm-commerce'),
            'flex-end' => __('End', 'ggm-commerce'),
            'stretch' => __('Stretch', 'ggm-commerce'),
            'baseline' => __('Baseline', 'ggm-commerce'),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-add-to-cart-wrapper' => 'align-items: {{VALUE}};',
        ],
    ]
);

$this->add_responsive_control(
    'layout_gap',
    [
        'label' => __('Gap', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px', 'em'],
        'range' => [
            'px' => ['min' => 0, 'max' => 60],
            'em' => ['min' => 0, 'max' => 4],
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-add-to-cart-wrapper' => 'gap: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// === BUTTON STYLE ===
$this->start_controls_section(
    'button_style_section',
    [
        'label' => __('Button', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'button_typography',
        'selector' => '{{WRAPPER}} .ggmc-add-to-cart-btn',
    ]
);

$this->start_controls_tabs('button_style_tabs');

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

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

$this->add_group_control(
    \Elementor\Group_Control_Background::get_type(),
    [
        'name' => 'button_background',
        'types' => ['classic', 'gradient'],
        'selector' => '{{WRAPPER}} .ggmc-add-to-cart-btn',
    ]
);

$this->end_controls_tab();

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

$this->add_control(
    'button_hover_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-add-to-cart-btn:hover' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Background::get_type(),
    [
        'name' => 'button_hover_background',
        'types' => ['classic', 'gradient'],
        'selector' => '{{WRAPPER}} .ggmc-add-to-cart-btn:hover',
    ]
);

$this->end_controls_tab();

$this->end_controls_tabs();

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'button_border',
        'selector' => '{{WRAPPER}} .ggmc-add-to-cart-btn',
    ]
);

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

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

$this->add_group_control(
    \Elementor\Group_Control_Box_Shadow::get_type(),
    [
        'name' => 'button_box_shadow',
        'label' => __('Box Shadow', 'ggm-commerce'),
        'selector' => '{{WRAPPER}} .ggmc-add-to-cart-btn',
    ]
);

$this->end_controls_section();

// === QUANTITY STYLE ===
$this->start_controls_section(
    'quantity_style_section',
    [
        'label' => __('Quantity', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_quantity' => 'yes',
        ],
    ]
);

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

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

$this->add_control(
    'quantity_input_heading',
    [
        'label' => __('Input Field', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::HEADING,
        'separator' => 'before',
    ]
);

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

$this->add_control(
    'quantity_input_background',
    [
        'label' => __('Input Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-quantity-input' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'quantity_input_border',
        'label' => __('Input Border', 'ggm-commerce'),
        'selector' => '{{WRAPPER}} .ggmc-quantity-input',
    ]
);

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

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

$this->add_control(
    'quantity_buttons_heading',
    [
        'label' => __('Plus/Minus Buttons', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::HEADING,
        'separator' => 'before',
    ]
);

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

$this->add_control(
    'quantity_button_background',
    [
        'label' => __('Button Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-quantity-btn' => 'background-color: {{VALUE}};',
        ],
    ]
);

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

$this->add_control(
    'quantity_button_hover_background',
    [
        'label' => __('Button Hover Background', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-quantity-btn:hover' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->end_controls_section();

// === PRICE STYLE ===
$this->start_controls_section(
    'price_style_section',
    [
        'label' => __('Price', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_price' => 'yes',
        ],
    ]
);

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

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

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

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

$this->add_control(
    'price_prefix_color',
    [
        'label' => __('Prefix Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'description' => __('"From" label color for variable products.', 'ggm-commerce'),
        'selectors' => [
            '{{WRAPPER}} .ggmc-cart-price .price-from-label' => 'color: {{VALUE}};',
        ],
    ]
);

$this->end_controls_section();
