<?php

namespace Webnestors\Wsn\Snippets;

class ArchiveCartButtonOnbackorder extends \Webnestors\Wsn\Snippet {
    public $button_text = "Pre Order";

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

    public function title(): string {
        return esc_html__("Message when on backorder", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return esc_html__(
            "Show a message on the product Add to Cart button when the product is on backorder.",
            "enhancements-for-woocommerce"
        );
    }

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

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Message When on Backorder module allows you to display a custom message directly on the "Add to Cart" button for products that are on backorder. This feature provides transparency to customers by informing them of the product’s backorder status before adding it to their cart, helping to manage expectations regarding availability and delivery times.</p>
        <p>Ideal for stores that frequently offer products on backorder, this module ensures customers are aware of potential delays and enhances communication about inventory status, reducing the likelihood of abandoned carts or customer inquiries about delayed shipments.</p>
        <h3>Settings</h3>
        <p>Just place the label that you want to replace on the Add to cart button</p>
        <h3>Appearance</h3>
        <p>The are no appearence options for this module</p>
        <?php return ob_get_clean();
    }

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

    function wn_change_backorder_button($text, $product) {
        if ($product->is_on_backorder()) {
            $text = $this->button_text;
        }

        return $text;
    }
}
