<?php

namespace Webnestors\Wsn\Snippets;

class GeneralDisbleHomePageCartFragments extends \Webnestors\Wsn\Snippet {
    public function tab(): string {
        return "general";
    }

    public function title(): string {
        return esc_html__("Disable Woo Cart Fragments", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return esc_html__(
            "Disable the woocommerce cart fragments only on the HOME PAGE of your site, great choice for speed",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Disable Woo Cart Fragments module is designed to optimize the loading speed of your WooCommerce site by selectively disabling the cart fragments script on your Home Page. WooCommerce cart fragments (AJAX requests) are responsible for dynamically updating the shopping cart icon and its contents without requiring a page reload. While this feature is useful for real-time cart updates, it can negatively affect your site’s performance, especially on the home page, where the cart may not be a primary focus.</p>
        <p>For many stores, the home page serves as a gateway to attract customers, featuring high-quality images, banners, and important information. By disabling cart fragments only on the home page, this module helps reduce unnecessary server requests and processing time, which can significantly speed up page load times. Faster loading pages improve user experience, reduce bounce rates, and can lead to better SEO rankings.</p>
        <h3>Settings</h3>
        <p>There are no setting for this module</p>
        <h3>Appearance</h3>
        <p>There are no customization options for this module.</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_action("wp_enqueue_scripts", [$this, "wn_disable_woocommerce_cart_fragments"], 11);
    }

    function wn_disable_woocommerce_cart_fragments() {
        if (is_front_page()) {
            wp_dequeue_script("wc-cart-fragments");
        }
    }
}
