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

// === STYLE TAB ===
$this->start_controls_section(
    'style_section',
    [
        'label' => __('Description Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'description_typography',
        'selector' => '{{WRAPPER}} .ggmc-product-description',
        'fields_options' => [
            'typography' => [
                'default' => 'custom',
            ],
            'font_family' => [
                'default' => "'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
            ],
            'font_size' => [
                'default' => [
                    'size' => 16,
                    'unit' => 'px',
                ],
            ],
            'font_weight' => [
                'default' => '400',
            ],
            'line_height' => [
                'default' => [
                    'size' => 1.6,
                    'unit' => 'em',
                ],
            ],
        ],
    ]
);

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

$this->add_responsive_control(
    'description_align',
    [
        'label' => __('Alignment', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::CHOOSE,
        'options' => [
            'left' => [
                'title' => __('Left', 'ggm-commerce'),
                'icon' => 'eicon-text-align-left',
            ],
            'center' => [
                'title' => __('Center', 'ggm-commerce'),
                'icon' => 'eicon-text-align-center',
            ],
            'right' => [
                'title' => __('Right', 'ggm-commerce'),
                'icon' => 'eicon-text-align-right',
            ],
            'justify' => [
                'title' => __('Justified', 'ggm-commerce'),
                'icon' => 'eicon-text-align-justify',
            ],
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-description' => 'text-align: {{VALUE}};',
        ],
    ]
);

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

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

$this->add_responsive_control(
    'column_count',
    [
        'label'   => __( 'Columns', 'ggm-commerce' ),
        'type'    => \Elementor\Controls_Manager::SELECT,
        'default' => '1',
        'options' => [
            '1' => __( '1', 'ggm-commerce' ),
            '2' => __( '2', 'ggm-commerce' ),
            '3' => __( '3', 'ggm-commerce' ),
            '4' => __( '4', 'ggm-commerce' ),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-description' => 'column-count: {{VALUE}};',
        ],
    ]
);

$this->add_responsive_control(
    'column_gap',
    [
        'label'      => __( 'Column Gap', 'ggm-commerce' ),
        'type'       => \Elementor\Controls_Manager::SLIDER,
        'size_units' => [ 'px', 'em' ],
        'range'      => [
            'px' => [ 'min' => 0, 'max' => 100 ],
            'em' => [ 'min' => 0, 'max' => 6 ],
        ],
        'default'    => [ 'size' => 30, 'unit' => 'px' ],
        'selectors'  => [
            '{{WRAPPER}} .ggmc-product-description' => 'column-gap: {{SIZE}}{{UNIT}};',
        ],
        'condition'  => [ 'column_count!' => '1' ],
    ]
);

$this->add_control(
    'column_rule_style',
    [
        'label'     => __( 'Column Divider', 'ggm-commerce' ),
        'type'      => \Elementor\Controls_Manager::SELECT,
        'default'   => 'none',
        'options'   => [
            'none'   => __( 'None', 'ggm-commerce' ),
            'solid'  => __( 'Solid', 'ggm-commerce' ),
            'dashed' => __( 'Dashed', 'ggm-commerce' ),
            'dotted' => __( 'Dotted', 'ggm-commerce' ),
            'double' => __( 'Double', 'ggm-commerce' ),
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-description' => 'column-rule-style: {{VALUE}};',
        ],
        'condition' => [ 'column_count!' => '1' ],
    ]
);

$this->add_responsive_control(
    'column_rule_width',
    [
        'label'      => __( 'Divider Width', 'ggm-commerce' ),
        'type'       => \Elementor\Controls_Manager::SLIDER,
        'size_units' => [ 'px' ],
        'range'      => [
            'px' => [ 'min' => 1, 'max' => 10 ],
        ],
        'default'    => [ 'size' => 1, 'unit' => 'px' ],
        'selectors'  => [
            '{{WRAPPER}} .ggmc-product-description' => 'column-rule-width: {{SIZE}}{{UNIT}};',
        ],
        'condition'  => [
            'column_count!'     => '1',
            'column_rule_style!' => 'none',
        ],
    ]
);

$this->add_control(
    'column_rule_color',
    [
        'label'     => __( 'Divider Color', 'ggm-commerce' ),
        'type'      => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-description' => 'column-rule-color: {{VALUE}};',
        ],
        'condition' => [
            'column_count!'      => '1',
            'column_rule_style!' => 'none',
        ],
    ]
);

$this->end_controls_section();

// === READ MORE / LESS STYLE ===
$this->start_controls_section(
    'read_more_style_section',
    [
        'label' => __('Read More / Less Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'description_type' => 'excerpt',
            'show_read_more' => 'yes',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'read_more_typography',
        'selector' => '{{WRAPPER}} .ggmc-read-more, {{WRAPPER}} .ggmc-read-less',
        'fields_options' => [
            'typography' => [
                'default' => 'custom',
            ],
            'font_family' => [
                'default' => 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
            ],
            'font_size' => [
                'default' => [
                    'size' => 14,
                    'unit' => 'px',
                ],
            ],
            'font_weight' => [
                'default' => '500',
            ],
        ],
    ]
);

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

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

$this->end_controls_section();
