<?php

namespace Webnestors\Wsn\Snippets;

class CheckoutChangeFieldsLabels extends \Webnestors\Wsn\Snippet {
    public $billing_first_name = "First Name";
    public $billing_last_name = "Last Name";
    public $billing_company = "Company";
    public $billing_address_1 = "Address 1";
    public $billing_address_2 = "Address 2";
    public $billing_city = "City";
    public $billing_postcode = "Postal Code";
    public $billing_country = "Country";
    public $billing_state = "State";
    public $billing_phone = "Phone";
    public $shipping_first_name = "First Name";
    public $shipping_last_name = "Last Name";
    public $shipping_company = "Company";
    public $shipping_address_1 = "Address 1";
    public $shipping_address_2 = "Address 2";
    public $shipping_city = "City";
    public $shipping_postcode = "Postal Code";
    public $shipping_country = "Country";
    public $shipping_state = "State";
    public $order_comments = "Comments";

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

    public function title(): string {
        return __("Change Checkout Fields Labels", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return __(
            "Enablign this you will be able to customise your checkout field labels to meet your business needs.",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [
            [
                "label" => __("Billing First Name", "enhancements-for-woocommerce"),
                "name" => "billing_first_name",
                "type" => "text",
            ],
            [
                "label" => __("Billing Last Name", "enhancements-for-woocommerce"),
                "name" => "billing_last_name",
                "type" => "text",
            ],
            [
                "label" => __("Billing Company", "enhancements-for-woocommerce"),
                "name" => "billing_company",
                "type" => "text",
            ],
            [
                "label" => __("Billing Address 1", "enhancements-for-woocommerce"),
                "name" => "billing_address_1",
                "type" => "text",
            ],
            [
                "label" => __("Billing Address 2", "enhancements-for-woocommerce"),
                "name" => "billing_address_2",
                "type" => "text",
            ],
            [
                "label" => __("Billing City", "enhancements-for-woocommerce"),
                "name" => "billing_city",
                "type" => "text",
            ],
            [
                "label" => __("Billing Postal Code", "enhancements-for-woocommerce"),
                "name" => "billing_postcode",
                "type" => "text",
            ],
            [
                "label" => __("Billing Country", "enhancements-for-woocommerce"),
                "name" => "billing_country",
                "type" => "text",
            ],
            [
                "label" => __("Billing State", "enhancements-for-woocommerce"),
                "name" => "billing_state",
                "type" => "text",
            ],
            [
                "label" => __("Billing Phone", "enhancements-for-woocommerce"),
                "name" => "billing_phone",
                "type" => "text",
            ],
            [
                "label" => __("Shipping First Name", "enhancements-for-woocommerce"),
                "name" => "shipping_first_name",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Last Name", "enhancements-for-woocommerce"),
                "name" => "shipping_last_name",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Company", "enhancements-for-woocommerce"),
                "name" => "shipping_company",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Address 1", "enhancements-for-woocommerce"),
                "name" => "shipping_address_1",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Address 2", "enhancements-for-woocommerce"),
                "name" => "shipping_address_2",
                "type" => "text",
            ],
            [
                "label" => __("Shipping City", "enhancements-for-woocommerce"),
                "name" => "shipping_city",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Postal Code", "enhancements-for-woocommerce"),
                "name" => "shipping_postcode",
                "type" => "text",
            ],
            [
                "label" => __("Shipping Country", "enhancements-for-woocommerce"),
                "name" => "shipping_country",
                "type" => "text",
            ],
            [
                "label" => __("Shipping State", "enhancements-for-woocommerce"),
                "name" => "shipping_state",
                "type" => "text",
            ],
            [
                "label" => __("Order Commnets", "enhancements-for-woocommerce"),
                "name" => "order_comments",
                "type" => "text",
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        <h3>Description</h3>
        <p>The Change Checkout Fields Labels module gives you full control over the labels for the fields on your WooCommerce checkout page. This feature allows you to customize the default labels for any checkout field, such as billing information, shipping details, or payment methods, ensuring that the checkout process aligns with your business needs and brand voice. Whether you want to provide clearer instructions, translate labels for a multilingual audience, or adjust the field names to fit your unique requirements, this module makes it simple and flexible.</p>
        <p>This feature is particularly valuable for businesses that have specific workflows, operate in regions with different language preferences, or want to create a more intuitive checkout experience for their customers.</p>
        <h3>Settings</h3>
        <h4>Titles</h4>
        <p>Write the title that you like for each field in the checkout form</p>
        <h3>Appearance</h3>
        <p>There is no appearence options for this module</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("woocommerce_checkout_fields", [$this, "wn_change_checkout_field_labels"], 9999);
    }

    function wn_change_checkout_field_labels($f) {
        $f["billing"]["billing_first_name"]["label"] = $this->billing_first_name;
        $f["billing"]["billing_last_name"]["label"] = $this->billing_last_name;
        $f["billing"]["billing_company"]["label"] = $this->billing_company;
        $f["billing"]["billing_address_1"]["label"] = $this->billing_address_1;
        $f["billing"]["billing_address_2"]["label"] = $this->billing_address_2;
        $f["billing"]["billing_city"]["label"] = $this->billing_city;
        $f["billing"]["billing_postcode"]["label"] = $this->billing_postcode;
        $f["billing"]["billing_country"]["label"] = $this->billing_country;
        $f["billing"]["billing_state"]["label"] = $this->billing_state;
        $f["billing"]["billing_phone"]["label"] = $this->billing_phone;
        $f["shipping"]["shipping_first_name"]["label"] = $this->shipping_first_name;
        $f["shipping"]["shipping_last_name"]["label"] = $this->shipping_last_name;
        $f["shipping"]["shipping_company"]["label"] = $this->shipping_company;
        $f["shipping"]["shipping_address_1"]["label"] = $this->shipping_address_1;
        $f["shipping"]["shipping_address_2"]["label"] = $this->shipping_address_2;
        $f["shipping"]["shipping_city"]["label"] = $this->shipping_city;
        $f["shipping"]["shipping_postcode"]["label"] = $this->shipping_postcode;
        $f["shipping"]["shipping_country"]["label"] = $this->shipping_country;
        $f["shipping"]["shipping_state"]["label"] = $this->shipping_state;
        $f["order"]["order_comments"]["label"] = $this->order_comments;

        return $f;
    }
}
