<?php
/**
 * Mini Cart Widget - Phase 2
 *
 * @package GGM_Commerce
 */

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

require_once __DIR__ . '/widget-mini-cart/elementor-render.php';

/**
 * Class GGM_Commerce_Widget_Mini_Cart
 *
 * Displays an Elementor mini cart button with an optional dropdown panel.
 */
class GGM_Commerce_Widget_Mini_Cart extends \GGM_Commerce_Base_Widget {

    public function get_name() {
        return 'ggmc-mini-cart';
    }

    public function get_title() {
        return __( 'Mini Cart', 'ggm-commerce' );
    }

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

    public function get_categories() {
        return [ 'ggmc-widgets' ];
    }

    public function get_keywords() {
        return [ 'cart', 'shopping', 'mini', 'basket', 'checkout' ];
    }

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

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

    public static function get_static_default_styles() {
        $defaults = [
            // Cart Button Styling
            'cart_button_padding' => [
                'top'      => '12',
                'right'    => '16',
                'bottom'   => '12',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => false,
            ],
            'cart_button_color'            => '#374151',
            'cart_button_background'       => '',
            'cart_button_hover_color'      => '#2563eb',
            'cart_button_hover_background' => '',
            'cart_button_border_border'    => 'none',
            'cart_button_border_width'     => [
                'top'      => '0',
                'right'    => '0',
                'bottom'   => '0',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'cart_button_border_color'  => '',
            'cart_button_border_radius' => [
                'top'      => '6',
                'right'    => '6',
                'bottom'   => '6',
                'left'     => '6',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'cart_button_typography_font_family' => "'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
            'cart_button_typography_font_size'   => [ 'size' => 16, 'unit' => 'px' ],
            'cart_button_typography_font_weight' => '500',

            // Icon Styling (Button-like: blue background, white icon)
            'icon_size'                  => [ 'size' => 24, 'unit' => 'px' ],
            'icon_color'                 => '#ffffff',
            'icon_background_color'      => '#2563eb',
            'icon_hover_color'           => '#ffffff',
            'icon_hover_background_color'=> '#1d4ed8',
            'icon_padding'               => [
                'top'      => '10',
                'right'    => '10',
                'bottom'   => '10',
                'left'     => '10',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'icon_border_radius' => [
                'top'      => '6',
                'right'    => '6',
                'bottom'   => '6',
                'left'     => '6',
                'unit'     => 'px',
                'isLinked' => true,
            ],

            // Cart Count Badge Styling
            'count_background_color'        => '#dc2626',
            'count_text_color'              => '#ffffff',
            'count_typography_font_size'    => [ 'size' => 11, 'unit' => 'px' ],
            'count_typography_font_weight'  => '600',
            'count_size'                    => [ 'size' => 18, 'unit' => 'px' ],
            'count_position_top'            => [ 'size' => -4, 'unit' => 'px' ],
            'count_position_right'          => [ 'size' => -4, 'unit' => 'px' ],

            // Dropdown Container Styling
            'dropdown_width'      => [ 'size' => 320, 'unit' => 'px' ],
            'dropdown_background' => '#ffffff',
            'dropdown_border_radius' => [
                'top'      => '8',
                'right'    => '8',
                'bottom'   => '8',
                'left'     => '8',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'dropdown_border_border' => 'solid',
            'dropdown_border_width'  => [
                'top'      => '1',
                'right'    => '1',
                'bottom'   => '1',
                'left'     => '1',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'dropdown_border_color'          => '#e5e7eb',
            'dropdown_shadow_box_shadow_type'=> 'yes',
            'dropdown_shadow_box_shadow'     => [
                'horizontal' => 0,
                'vertical'   => 4,
                'blur'       => 12,
                'spread'     => 0,
                'color'      => 'rgba(0,0,0,0.1)',
            ],

            // Dropdown Header Styling
            'header_title_text'                  => 'Shopping Cart',
            'header_background_color'            => '',
            'header_title_color'                 => '#111827',
            'header_title_typography_font_size'  => [ 'size' => 18, 'unit' => 'px' ],
            'header_title_typography_font_weight'=> '600',
            'header_padding'                     => [
                'top'      => '16',
                'right'    => '16',
                'bottom'   => '16',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'header_border_color'     => '#e5e7eb',
            'close_button_color'      => '#6b7280',
            'close_button_hover_color'=> '#111827',
            'close_button_size'       => [ 'size' => 24, 'unit' => 'px' ],

            // Cart Items Styling
            'items_padding' => [
                'top'      => '16',
                'right'    => '16',
                'bottom'   => '16',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'item_image_size'                => [ 'size' => 50, 'unit' => 'px' ],
            'item_image_border_radius'       => [ 'size' => 6, 'unit' => 'px' ],
            'item_name_color'                => '#111827',
            'item_name_typography_font_size' => [ 'size' => 14, 'unit' => 'px' ],
            'item_name_typography_font_weight'=> '500',
            'item_meta_color'                => '#6b7280',
            'item_meta_typography_font_size' => [ 'size' => 12, 'unit' => 'px' ],
            'item_divider_color'             => '#f3f4f6',
            'item_spacing'                   => [ 'size' => 12, 'unit' => 'px' ],

            // Remove Button Styling
            'remove_button_color'            => '#dc2626',
            'remove_button_hover_color'      => '#b91c1c',
            'remove_button_background'       => '',
            'remove_button_hover_background' => '#fef2f2',
            'remove_button_size'             => [ 'size' => 16, 'unit' => 'px' ],

            // Footer Styling
            'footer_background_color'       => '',
            'footer_padding'                => [
                'top'      => '16',
                'right'    => '16',
                'bottom'   => '16',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => true,
            ],
            'footer_border_color'           => '#e5e7eb',
            'total_color'                   => '#111827',
            'total_typography_font_size'    => [ 'size' => 16, 'unit' => 'px' ],
            'total_typography_font_weight'  => '600',

            // View Cart Button Styling
            'view_cart_typography_font_size'  => [ 'size' => 14, 'unit' => 'px' ],
            'view_cart_typography_font_weight'=> '500',
            'view_cart_color'                 => '#374151',
            'view_cart_background'            => '#f3f4f6',
            'view_cart_border_color'          => '#d1d5db',
            'view_cart_hover_color'           => '#374151',
            'view_cart_hover_background'      => '#e5e7eb',
            'view_cart_padding'               => [
                'top'      => '10',
                'right'    => '16',
                'bottom'   => '10',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => false,
            ],
            'view_cart_border_radius' => [
                'top'      => '6',
                'right'    => '6',
                'bottom'   => '6',
                'left'     => '6',
                'unit'     => 'px',
                'isLinked' => true,
            ],

            // Checkout Button Styling
            'checkout_typography_font_size'  => [ 'size' => 14, 'unit' => 'px' ],
            'checkout_typography_font_weight'=> '500',
            'checkout_color'                 => '#ffffff',
            'checkout_background'            => '#2563eb',
            'checkout_border_color'          => '#2563eb',
            'checkout_hover_color'           => '#ffffff',
            'checkout_hover_background'      => '#1d4ed8',
            'checkout_padding'               => [
                'top'      => '10',
                'right'    => '16',
                'bottom'   => '10',
                'left'     => '16',
                'unit'     => 'px',
                'isLinked' => false,
            ],
            'checkout_border_radius' => [
                'top'      => '6',
                'right'    => '6',
                'bottom'   => '6',
                'left'     => '6',
                'unit'     => 'px',
                'isLinked' => true,
            ],

            // Empty Cart Message Styling
            'empty_cart_color'                   => '#6b7280',
            'empty_cart_typography_font_size'    => [ 'size' => 14, 'unit' => 'px' ],
            'empty_cart_alignment'               => 'center',
            'empty_cart_padding'                 => [
                'top'      => '20',
                'right'    => '0',
                'bottom'   => '20',
                'left'     => '0',
                'unit'     => 'px',
                'isLinked' => false,
            ],
        ];

        return apply_filters( 'ggm_commerce_widget_default_styles', $defaults, 'ggmc-mini-cart' );
    }
}
