<?php

namespace Webnestors\Wsn\Snippets;

class CartCustomMessage extends \Webnestors\Wsn\Snippet {
    public $cart_message = "";
    public $cart_position = "woocommerce_after_cart_contents";

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

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

    public function description(): string {
        return esc_html__(
            "Show a custom message in the cart. For example, a warning to your customers for something, or a general message that applies to all orders.",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [
            [
                "label" => esc_html__("Cart Message", "enhancements-for-woocommerce"),
                "description" => esc_html__("Write you message here", "enhancements-for-woocommerce"),
                "name" => "cart_message",
                "type" => "text",
            ],
            [
                "label" => esc_html__("Select Position", "enhancements-for-woocommerce"),
                "description" => esc_html__("The message's position on the page.", "enhancements-for-woocommerce"),
                "name" => "cart_position",
                "type" => "select",
                "options" => [
                    "woocommerce_before_cart_table",
                    "woocommerce_before_cart_contents",
                    "woocommerce_after_cart_contents",
                    "woocommerce_after_cart_table",
                    "woocommerce_cart_totals_before_shipping",
                    "woocommerce_before_shipping_calculator",
                    "woocommerce_after_shipping_calculator",
                    "woocommerce_cart_totals_after_shipping",
                    "woocommerce_cart_totals_before_order_total",
                    "woocommerce_cart_totals_after_order_total",
                    "woocommerce_proceed_to_checkout",
                    "woocommerce_after_cart_totals",
                ],
                "option_labels" => [
                    "Before cart table",
                    "Before cart contents",
                    "After cart contents",
                    "After cart table",
                    "Before totals shipping",
                    "Before shipping calculator",
                    "After shipping calculator",
                    "After totals shipping",
                    "Before order total",
                    "After order total",
                    "Before checkout button",
                    "After cart totals",
                ],
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Custom Cart Message module allows you to display personalized messages on your WooCommerce cart page, giving you the flexibility to communicate important information, promotions, or warnings to customers before they proceed to checkout. Whether you want to inform your customers about shipping policies, current promotions, order deadlines, or other vital information, this module ensures that your message is prominently displayed when it matters most — in the cart.</p>
        <p>This feature is ideal for delivering important updates or reminders that apply universally across all orders. With the ability to create custom messages, you can tailor the communication to your store's unique needs, ensuring that customers are always informed and aware of any important details that might affect their purchase.</p>
        <h3>Settings</h3>
        <h4>Cart Message</h4>
        <p>The text that will appear to the cart.</p>
        <h4>Select Position</h4>
        <p>Choose where you want to place the notification</p>
        <h4>Note: The select position may not always work if your theme is not using the standard WooCommerce cart Positions</h4>
        <h3>Appearance</h3>
        <p>You can customize this module using custom css and the class "p.woocommerce-message.wn-cart-message".</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_action($this->cart_position, [$this, "cart_message"]);
    }

    function cart_message() {
        echo '<p class="woocommerce-message wn-cart-message">' . esc_html($this->cart_message) . "</p>";
    }
}
