<?php

namespace Webnestors\Wsn\Snippets;

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

    public function title(): string {
        return esc_html__("Display Stock Availability", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return esc_html__("Show the stock quantity on each product placed in the cart", "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 Display Stock Availability module enhances the customer experience by showing the available stock quantity for each product directly in the cart. When customers add products to their cart, they can instantly see how many units of each item are left in stock. This feature is especially helpful for stores with limited stock or high-demand products, as it informs customers about stock levels and encourages them to complete their purchase before the items sell out.</p>
        <p>This module provides real-time stock information, helping to create a sense of urgency and allowing customers to make more informed decisions regarding their purchases. It’s particularly beneficial for stores that handle limited editions, seasonal items, or frequently restocked products.</p>
        <h3>Settings</h3>
        <p>There are no settings for this module</p>
        <h3>Appearance</h3>
        <p>The are no customization options for thsi module</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("woocommerce_cart_item_name", [$this, "wn_add_availability_below_cart_item_name"], 10, 3);
    }

    function wn_add_availability_below_cart_item_name($item_name, $cart_item, $cart_item_key) {
        $availability = $cart_item["data"]->get_availability();
        return $item_name . "<br>" . $availability["availability"];
    }
}
