<?php
/**
 * Widget: Product Description
 *
 * Displays a product's full, short, or excerpted description with optional
 * read-more / read-less toggle.
 *
 * @package GGM_Commerce
 */

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

require_once __DIR__ . '/widget-product-description/elementor-render.php';

class GGM_Commerce_Widget_Product_Description extends \GGM_Commerce_Base_Widget
{

    public function get_name()
    {
        return 'ggmc-product-description';
    }

    public function get_title()
    {
        return 'Product Description';
    }

    public function get_icon()
    {
        return 'eicon-text-area';
    }

    protected function register_controls()
    {
        require __DIR__ . '/widget-product-description/elementor-controls.php';
        require __DIR__ . '/widget-product-description/elementor-controls-style.php';
    }

    protected function render()
    {
        ggmc_product_description_render( $this );
    }

    /**
     * Get default styles for this widget
     */
    public static function get_static_default_styles() {
        // Check if defaults have been cleared globally
        if (get_option('ggm_commerce_defaults_cleared', false)) {
            return []; // Return empty array so widget starts with no styling
        }

        $defaults = [
            // === DESCRIPTION CONTAINER ===
            'description_background_color' => '#FAFAFA',
            'description_padding' => [
                'top' => '20',
                'right' => '20',
                'bottom' => '20',
                'left' => '20',
                'unit' => 'px',
                'isLinked' => true
            ],
            'description_border_border' => 'solid',
            'description_border_width' => [
                'top' => '1',
                'right' => '1',
                'bottom' => '1',
                'left' => '1',
                'unit' => 'px',
                'isLinked' => true
            ],
            'description_border_color' => '#E5E7EB',
            'description_border_radius' => [
                'top' => '6',
                'right' => '6',
                'bottom' => '6',
                'left' => '6',
                'unit' => 'px',
                'isLinked' => true
            ],

            // === DESCRIPTION TYPOGRAPHY ===
            'description_typography_typography' => 'custom',
            'description_typography_font_family' => 'system-ui, -apple-system, sans-serif',
            'description_typography_font_size' => [
                'size' => '16',
                'unit' => 'px'
            ],
            'description_typography_font_weight' => '400',
            'description_typography_line_height' => [
                'size' => '1.6',
                'unit' => 'em'
            ],
            'description_color' => '#374151',

            // === HEADINGS IN DESCRIPTION ===
            'description_heading_color' => '#1F2937',
            'description_heading_typography_font_weight' => '600',
            'description_heading_margin_bottom' => [
                'size' => '12',
                'unit' => 'px'
            ],

            // === LINKS IN DESCRIPTION ===
            'description_link_color' => '#2563eb',
            'description_link_hover_color' => '#1d4ed8',

            // === READ MORE STYLING ===
            'read_more_color' => '#B45309',
            'read_more_typography_font_weight' => '500',
            'read_more_hover_color' => '#92400E',
            'read_more_margin_top' => [
                'size' => '12',
                'unit' => 'px'
            ],

            // === SPACING ===
            'description_margin' => [
                'top' => '0',
                'right' => '0',
                'bottom' => '20',
                'left' => '0',
                'unit' => 'px',
                'isLinked' => false
            ],

            // === RESPONSIVE ===
            'description_typography_font_size_tablet' => [
                'size' => '15',
                'unit' => 'px'
            ],
            'description_typography_font_size_mobile' => [
                'size' => '14',
                'unit' => 'px'
            ],
            'description_padding_tablet' => [
                'top' => '16',
                'right' => '16',
                'bottom' => '16',
                'left' => '16',
                'unit' => 'px',
                'isLinked' => true
            ],
            'description_padding_mobile' => [
                'top' => '12',
                'right' => '12',
                'bottom' => '12',
                'left' => '12',
                'unit' => 'px',
                'isLinked' => true
            ]
        ];

        // Apply filter to allow clearing defaults globally
        return apply_filters('ggm_commerce_widget_default_styles', $defaults, 'ggmc-product-description');
    }
}
