<?php

namespace Webnestors\Wsn\Snippets;

class SingleStockQuantitySuffix extends \Webnestors\Wsn\Snippet {
    public $stock_suffix = "";

    public function tab(): string {
        return "product";
    }

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

    public function description(): string {
        return esc_html__(
            "Enabling this you will be able to display a suffix of the stock quantity value, for example 15 Pieces in stock",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [
            [
                "label" => esc_html__("Suffix Text", "enhancements-for-woocommerce"),
                "name" => "stock_suffix",
                "type" => "text",
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        
        <h3>Description</h3>
        <p>The Stock Quantity Suffix module allows you to add a customizable suffix to the stock quantity displayed on product pages. Instead of simply showing a number, you can enhance the stock display by adding descriptive text, such as “15 Pieces in stock” or “20 Units Available.” This feature helps clarify quantities for customers and can make the shopping experience more informative, especially for products where the unit type is important, such as “bottles,” “packs,” or “boxes.”</p>
        <p>This module is ideal for stores selling varied types of products, as it provides flexibility in how stock quantities are communicated to customers, enhancing clarity and professionalism.</p>
        <h3>Settings</h3>
        <p>Just enter the text you want to display after the stock quantity.</p>
        <h3>Appearance</h3>
        <p>There are no customization options for this module.</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("woocommerce_format_stock_quantity", [$this, "wn_add_stock_quantity_suffix"], 10, 2);
    }

    function wn_add_stock_quantity_suffix($stock_quantity, $product) {
        $stock_quantity = $stock_quantity . " " . $this->stock_suffix;
        return $stock_quantity;
    }
}
