<?php

namespace Webnestors\Wsn\Snippets;

class CartEmptyCartCustomMessage extends \Webnestors\Wsn\Snippet {
    public $cart_message = "Your cart is empty";
    public $select_products = "products";

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

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

    public function description(): string {
        return esc_html__(
            "Show a custom message when the cart is empty. You can chose also to display some products for example products on sale. Attention this doesn't effect the standard woocommerce message of empty cart.",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [
            [
                "label" => esc_html__("Message", "enhancements-for-woocommerce"),
                "description" => esc_html__("A message to be shown on the cart when it's empty.", "enhancements-for-woocommerce"),
                "name" => "cart_message",
                "type" => "text",
            ],
            [
                "label" => esc_html__("Products", "enhancements-for-woocommerce"),
                "description" => esc_html__("Which product to be shown when the cart is empty", "enhancements-for-woocommerce"),
                "name" => "select_products",
                "type" => "select",
                "options" => [
                    "",
                    "products limit=4",
                    "sale_products limit=4",
                    "recent_products limit=4",
                    "featured_products limit=4",
                ],
                "option_labels" => [
                    "Without Products",
                    "All Products",
                    "Products on Sale",
                    "Recent Products",
                    "Featured Products",
                ],
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Message on Empty Cart module adds a customized, engaging message to your WooCommerce store when the customer's cart is empty. Rather than leaving customers with just the default "Your cart is currently empty" message, this feature allows you to display a personalized message that can encourage further browsing, suggest popular products, or promote special offers. You can even highlight products that are on sale, giving customers an incentive to continue shopping.</p>
        <p>This module enhances the user experience by providing helpful suggestions and calls to action when the cart is empty, ensuring that customers are not left at a dead end. It’s an effective way to keep customers engaged and prevent them from leaving your site without exploring other products or offers.</p>
        <h3>Settings</h3>
        <h4>Message Field</h4>
        <p>Write the text that will be shown on empty cart.</p>
        <h4>Products Selection</h4>
        <p>You can choose which product you like to show when the cart is empty, like products on sale etc.</p>
        <h3>Appearance</h3>
        <p>You can customize the appearence of the module by using custom css.</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_action("woocommerce_cart_is_empty", [$this, "wn_change_empty_cart_text"]);
    }

    function wn_change_empty_cart_text() {
        if ($this->select_products !== "") {
            echo "<h4>" . esc_html($this->cart_message) . "</h4>";
            echo do_shortcode("[$this->select_products]");
        } else {
            echo "<h4>" . esc_html($this->cart_message) . "</h4>";
        }
    }
}
