<?php

namespace Webnestors\Wsn\Snippets;

class CheckoutContinueShopping extends \Webnestors\Wsn\Snippet {
    public $continue_text = "Forgot Something?";
    public $continue_button = "Continue";

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

    public function title(): string {
        return __("Continue Shopping Message", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return __("Show a message and a continue shopping button on the checkout page.", "enhancements-for-woocommerce");
    }

    public function meta(): array {
        return [
            [
                "label" => __("Text Message", "enhancements-for-woocommerce"),
                "name" => "continue_text",
                "type" => "text",
            ],
            [
                "label" => __("Button Text", "enhancements-for-woocommerce"),
                "name" => "continue_button",
                "type" => "text",
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Continue Shopping Message module allows you to enhance your WooCommerce checkout page by adding a customizable message and a "Continue Shopping" button. This feature encourages customers to keep shopping, even after reaching the checkout page, offering an opportunity to increase average order value by prompting additional purchases.</p>
        <p>With this module, you can display a message to remind customers that they can return to the shop to add more products to their cart, while also providing a user-friendly "Continue Shopping" button that redirects them back to the store’s product pages. The module is fully customizable, allowing you to tailor the message and button to fit your store's branding and sales strategy.</p>
        <h3>Settings</h3>
        <h4>Text Message</h4>
        <p>Write the text that you want to appear before the continue shopping button</p>
        <h4>Button Text</h4>
        <p>Write the button label eg."Continue Shopping"</p>
        <h3>Appearance</h3>
        <p>You can use the class "woocommerce-message" for modifing the appearence of the module with css, the button style will follow your default settings</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_action("woocommerce_before_checkout_form", [$this, "wn_continue_shopping_button"]);
    }

    function wn_continue_shopping_button() {
        $shop_page_url = get_permalink(wc_get_page_id("shop")); ?>
        <div class="woocommerce-message">
            <a href="<?php echo esc_url($shop_page_url); ?>" class="button">
                <?php echo esc_html($this->continue_button); ?>
            </a>
            <?php echo esc_html($this->continue_text); ?>
        </div>
        <?php
    }
}
