<?php
/**
 * Product Name Widget
 * Displays product names with comprehensive styling controls
 */

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

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

class GGM_Commerce_Widget_Product_Name extends \GGM_Commerce_Base_Widget {

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

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

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

    public function get_keywords() {
        return ['product', 'name', 'title', 'heading', 'ggm-commerce'];
    }

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

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

    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 = [
            // Content Settings
            'html_tag'    => 'h2',
            'enable_link' => '',

            // Typography
            'typography_typography'      => 'custom',
            'typography_font_family'     => "'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
            'typography_font_size'       => ['size' => 28, 'unit' => 'px'],
            'typography_font_weight'     => '700',
            'typography_line_height'     => ['size' => 1.3, 'unit' => 'em'],
            'typography_letter_spacing'  => ['size' => -0.02, 'unit' => 'em'],

            // Colors
            'text_color'  => '#1F2937',
            'hover_color' => '#2563eb',

            // Hover Effects
            'hover_transition' => ['size' => 0.3, 'unit' => 's'],

            // Spacing
            'margin' => [
                'top'      => '',
                'right'    => '0',
                'bottom'   => '',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => false,
            ],
            'padding' => [
                'top'      => '',
                'right'    => '0',
                'bottom'   => '0',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => false,
            ],

            // Responsive Typography
            'typography_font_size_tablet' => ['size' => 24, 'unit' => 'px'],
            'typography_font_size_mobile' => ['size' => 20, 'unit' => 'px'],

            // Responsive Spacing
            'margin_tablet' => [
                'top'      => '',
                'right'    => '0',
                'bottom'   => '12',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => false,
            ],
            'margin_mobile' => [
                'top'      => '',
                'right'    => '0',
                'bottom'   => '10',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => false,
            ],
        ];

        return apply_filters( 'ggm_commerce_widget_default_styles', $defaults, 'ggmc-product-name' );
    }

    /**
     * Get conditional default value based on global setting
     */
    private function get_conditional_default( $key, $fallback = '' ) {
        if ( ! GGM_Commerce_Admin::are_defaults_enabled() ) {
            return $fallback;
        }

        $defaults = self::get_static_default_styles();
        return isset( $defaults[ $key ] ) ? $defaults[ $key ] : $fallback;
    }
}
