<?php

namespace Webnestors\Wsn\Snippets;

class CartChangeYourCartIsEmptyText extends \Webnestors\Wsn\Snippet {
    public $empty_cart = "";

    public function is_pro(): bool {
        return true;
    }

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

    public function title(): string {
        return esc_html__("Change (Your Cart Is Currently Empty) Text", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return esc_html__("Show your own message when the cart is empty", "enhancements-for-woocommerce");
    }

    public function meta(): array {
        return [
            [
                "label" => esc_html__("Message to Show", "enhancements-for-woocommerce"),
                "name" => "empty_cart",
                "type" => "text",
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Change (Your Cart Is Currently Empty) Text module gives you full control over the default WooCommerce message displayed when a customer’s cart is empty. Instead of the generic “Your Cart is Currently Empty” text, this feature allows you to customize the message to better align with your store’s brand, tone, and marketing goals. This can be used to engage customers, direct them back to your shop, highlight special promotions, or simply add a touch of personality to the empty cart page.</p>
        <p>This module is a great way to turn a potentially negative moment (an empty cart) into an opportunity to engage your customers and encourage them to explore more of your store. Whether you want to use humor, urgency, or information, this module enables you to customize the messaging that resonates best with your audience.</p>
        <h3>Settings</h3>
        <h4>Message to Show</h4>
        <p>Write the text that will be shown on empty cart.</p>
        <h3>Appearance</h3>
        <p>You can customize the appearence of the module by using custom css and the class "p.cart-empty.woocommerce-info".</p>
        <?php return ob_get_clean();
    }

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

    function wn_change_empty_cart_text() {
        echo '<p class="cart-empty woocommerce-info">' . wp_kses_post($this->empty_cart) . "</p>";
    }
}
