<?php
namespace ShopyPress\Shortcodes;

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

class CartToggleShortcode
{
    static function register()
    {
        add_shortcode('synckube_cart_toggle', [self::class, 'render']);
    }

    /**
     * Render cart toggle button
     * Usage: [synckube_cart_toggle]
     */
    static function render($atts = [])
    {
        $atts = shortcode_atts([
            'show_count' => 'true',
            'class' => '',
        ], $atts);


        ob_start();
        ?>
        <label onclick="document.getElementById('shopypress-cart')?.showModal()" style="position: relative; cursor: pointer;" class="relative cursor-pointer navigation__view-cart shopypress-icon-cart">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="9" cy="21" r="1"></circle>
                <circle cx="20" cy="21" r="1"></circle>
                <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
            </svg>
            <shopify-context type="cart">
                <template>
                    <span class="cart-count-badge">
                        <shopify-data query="cart.totalQuantity" class="navigation__view-cart__quantity"></shopify-data>
                    </span>
                </template>
            </shopify-context>
        </label>
        <?php
        return ob_get_clean();

    }
}
