<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Shortcode to display the cart icon in the UI.
 * Shows or hides the icon based on saved plugin options.
 */
function doosearchas_cart_icon_ui_shortcode() {
    $doosearchas_options = get_option('doosearchas_search_additional_options');
    $is_cart = isset($doosearchas_options['doosearchas_search_cart_display_db']) ? $doosearchas_options['doosearchas_search_cart_display_db'] : '1';
    $display_style = ($is_cart === '1') ? 'block' : 'none';
    ob_start();
    ?>
    <div class="doosearchas_s-cart-icon-wrapper" style="display: <?php echo esc_attr($display_style); ?>;">
        <a href="#" id="doosearchas_s-cart-icon" class="doosearchas_s-cart-icon-link" aria-label="<?php esc_attr_e('Go to cart', 'doosearch-ajax-search-for-woo'); ?>" aria-live="polite">
            <span class="doosearchas_s-cart-item-count" aria-live="assertive"></span>
            <span class="doosearchas_s-cart-icon-svg" aria-hidden="true">
                <svg id="Layer_1" role="img" aria-label="<?php esc_attr_e('Shopping cart icon', 'doosearch-ajax-search-for-woo'); ?>"   style="enable-background:new 0 0 48 48;" version="1.1" viewBox="0 0 48 48" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                    <g>
                        <path d="M19,38c-2.2,0-4,1.8-4,4s1.8,4,4,4c2.2,0,4-1.8,4-4S21.2,38,19,38z M19,44c-1.1,0-2-0.9-2-2s0.9-2,2-2s2,0.9,2,2 S20.1,44,19,44z" stroke="#3b4238" stroke-width="2"/>
                        <path d="M37,38c-2.2,0-4,1.8-4,4s1.8,4,4,4s4-1.8,4-4S39.2,38,37,38z M37,44c-1.1,0-2-0.9-2-2s0.9-2,2-2s2,0.9,2,2 S38.1,44,37,44z" stroke="#3b4238" stroke-width="2"/>
                        <path d="M43.6,9.4C42.9,8.5,41.7,8,40.5,8H12.8l-0.4-2.6c-0.3-1.9-2-3.4-4-3.4H2v2h6.4c1,0,1.9,0.7,2,1.7l4.2,27.1 c0.4,1.9,2.1,3.3,4,3.3H40v-2H18.6c-1,0-1.8-0.7-2-1.7L16.2,30h22.2c1.9,0,3.6-1.4,4-3.5l2.1-14C44.7,11.4,44.4,10.3,43.6,9.4z M42.5,12.3l-2.1,14c-0.2,1.1-1,1.8-2,1.8H15.9l-2.8-18h27.4c0.6,0,1.2,0.3,1.6,0.7C42.5,11.1,42.6,11.7,42.5,12.3z" stroke="#3b4238" stroke-width="2"/>
                    </g>
                </svg>
            </span>
        </a>
    </div>
    <?php
    return ob_get_clean();
}
add_shortcode('doosearchas-cart-icon-ui', 'doosearchas_cart_icon_ui_shortcode');

/**
 * Shortcode to display the cart info popup UI.
 * Shows or hides the popup based on saved plugin options.
 */
function doosearchas_cart_info_ui_shortcode() {
    $doosearchas_options = get_option('doosearchas_search_additional_options');
    $is_cart = isset($doosearchas_options['doosearchas_search_cart_display_db']) ? $doosearchas_options['doosearchas_search_cart_display_db'] : '1';
    $display_style = ($is_cart === '1') ? 'block' : 'none';
    ob_start();
    ?>
    <div id="doosearchas_s-cart-popup" class="doosearchas_s-cart-popup" style="display: <?php echo esc_attr($display_style); ?>;">
        <div class="doosearchas_s-cart-popup-header">
            <h3><?php esc_html_e('Your Cart', 'doosearch-ajax-search-for-woo'); ?></h3>
            <button id="doosearchas_s-cart-popup-close">&times;</button>
        </div>
        <div class="doosearchas_s-empty-cart-wrapper">
            <span class="doosearchas_s-empty-cart-icon"><svg height="120" role="img" aria-label="<?php esc_attr_e('Empty cart icon', 'doosearch-ajax-search-for-woo'); ?>"  viewBox="0 0 48 48" width="120" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48H0zm36.62 12L31.1 22z" fill="none"/><path d="M22 18h4v-6h6V8h-6V2h-4v6h-6v4h6v6zm-8 18c-2.21 0-3.98 1.79-3.98 4s1.77 4 3.98 4 4-1.79 4-4-1.79-4-4-4zm20 0c-2.21 0-3.98 1.79-3.98 4s1.77 4 3.98 4 4-1.79 4-4-1.79-4-4-4zm-19.65-6.5c0-.09.02-.17.06-.24l1.8-3.26h14.9c1.5 0 2.81-.83 3.5-2.06l7.72-14.02L38.83 8h-.01l-2.21 4-5.51 10H17.07l-.26-.54L12.32 12l-1.9-4-1.89-4H2v4h4l7.2 15.17-2.71 4.9c-.31.58-.49 1.23-.49 1.93 0 2.21 1.79 4 4 4h24v-4H14.85c-.28 0-.5-.22-.5-.5z"/></svg></span>
            <p><?php esc_html_e('No products in the cart.', 'doosearch-ajax-search-for-woo'); ?></p>
        </div>
        <div id="doosearchas_s-cart-item-wrapper">
            <div class="doosearchas_s-cart-item"  data-goto-cart-item-key="">
                <div class="doosearchas_s-cart-item-details">
                    <h4></h4>
                    <span class="doosearchas_s-cart-item-price"></span>
                    <div class="doosearchas_s-quantity-controls" id="doosearchas_s-quantity-controls-">
                        <button class="doosearchas_s-decrease-quantity" data-goto-cart-item-key="">-</button>
                        <input type="number" class="doosearchas_s-quantity-input" value="" min="1" readonly>
                        <button class="doosearchas_s-increase-quantity" data-goto-cart-item-key="">+</button>
                    </div>
                </div>
                <button class="doosearchas_s-remove-cart-item" id="doosearchas_s-remove-cart-item-" data-goto-cart-item-key="" aria-label="<?php esc_attr_e('Remove item from cart', 'doosearch-ajax-search-for-woo'); ?>">
                    <svg id="Layer_1" role="img" aria-label="<?php esc_attr_e('Remove item icon', 'doosearch-ajax-search-for-woo'); ?>" style="enable-background:new 0 0 64 64;" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><g id="Icon-Trash" transform="translate(232.000000, 228.000000)"><polygon fill="#134563" id="Fill-6" points="-207.5,-205.1 -204.5,-205.1 -204.5,-181.1 -207.5,-181.1    "/><polygon fill="#134563" id="Fill-7" points="-201.5,-205.1 -198.5,-205.1 -198.5,-181.1 -201.5,-181.1    "/><polygon fill="#134563" id="Fill-8" points="-195.5,-205.1 -192.5,-205.1 -192.5,-181.1 -195.5,-181.1    "/><polygon fill="#134563" id="Fill-9" points="-219.5,-214.1 -180.5,-214.1 -180.5,-211.1 -219.5,-211.1    "/><path fill="#134563" d="M-192.6-212.6h-2.8v-3c0-0.9-0.7-1.6-1.6-1.6h-6c-0.9,0-1.6,0.7-1.6,1.6v3h-2.8v-3     c0-2.4,2-4.4,4.4-4.4h6c2.4,0,4.4,2,4.4,4.4V-212.6" id="Fill-10"/><path fill="#134563" d="M-191-172.1h-18c-2.4,0-4.5-2-4.7-4.4l-2.8-36l3-0.2l2.8,36c0.1,0.9,0.9,1.6,1.7,1.6h18     c0.9,0,1.7-0.8,1.7-1.6l2.8-36l3,0.2l-2.8,36C-186.5-174-188.6-172.1-191-172.1" id="Fill-11"/></g></g></svg>
                </button>
            </div>
        </div>
        <div class="doosearchas_s-cart-footer">
            <div class="doosearchas_s-cart-item-total-price">
                <strong>Total: </strong>
            </div>
            <div class="doosearchas_s-cart-actions">
                <a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="view-cart-button"><?php esc_html_e('View Cart', 'doosearch-ajax-search-for-woo'); ?></a>
                <a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-button"><?php esc_html_e('Checkout', 'doosearch-ajax-search-for-woo'); ?></a>
            </div>
        </div>
    </div>
    <?php
    return ob_get_clean();
}
add_shortcode('doosearchas-cart-info-ui', 'doosearchas_cart_info_ui_shortcode');



