<?php

namespace Webnestors\Wsn\Snippets;

class CheckoutEmailOnTop extends \Webnestors\Wsn\Snippet {
    public function tab(): string {
        return "checkout";
    }

    public function title(): string {
        return __("Move Email to Top", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return __(
            "Move the email field to the top of the checkout form. Crucial if you want to capture emails.",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Move Email to Top module allows you to prioritize email capture by moving the email address field to the top of your WooCommerce checkout form. By placing the email field at the beginning of the checkout process, you can ensure that customers provide their email early on, which is crucial for order communication, abandoned cart recovery, and marketing purposes.</p>
        <p>This is an important enhancement for stores looking to improve email collection rates, streamline the checkout process, and enhance their customer communication strategy. Capturing emails early in the checkout process ensures that even if a customer does not complete their order, you can follow up with abandoned cart emails or other marketing efforts.</p>
        <h3>Settings</h3>
        <p>There are no settings for this module, just enable it and you are good to go</p>
        <h3>Appearance</h3>
        <p>There are no appearence options for this module</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("woocommerce_billing_fields", [$this, "wn_show_email_first"]);
    }

    function wn_show_email_first($address_fields) {
        $address_fields["billing_email"]["priority"] = 1;
        return $address_fields;
    }
}
