<?php

namespace Webnestors\Wsn\Snippets;

class CheckoutChangeSendToShippingHeading extends \Webnestors\Wsn\Snippet {
    public $heading_text = "Ship to a different address?";

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

    public function title(): string {
        return __("Shipping Heading", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return __("Replace the heading of the (Ship to a different address) text.", "enhancements-for-woocommerce");
    }

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

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Shipping Heading module allows you to replace or customize the default "Ship to a different address" heading on your WooCommerce checkout page. This feature enables you to personalize the shipping section by renaming the heading to better suit your store’s branding, provide clearer instructions, or offer a more user-friendly experience. Instead of the default WooCommerce wording, you can use a heading that resonates with your customers and fits the tone of your business.</p>
        <p>This module is especially useful for stores looking to enhance the clarity of their checkout process, align with specific business needs, or create a more engaging and customized experience for their shoppers.</p>
        <h3>Settings</h3>
        <h4>Heading Text</h4>
        <p>Write the text to replace the Shipping heading</p>
        <h3>Appearance</h3>
        <p>There is no appearence options for this module</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("gettext", [$this, "wn_change_ship_address_heading"], 20, 2);
    }

    function wn_change_ship_address_heading($translated_text, $text) {
        if ($text == "Ship to a different address?") {
            $translated_text = $this->heading_text;
        }

        return $translated_text;
    }
}
