<?php

namespace Webnestors\Wsn\Snippets;

class GeneralCatalogAndForm extends \Webnestors\Wsn\Snippet {
    public $shortcode = "";
    public $form_text = "Heading";

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

    public function title(): string {
        return esc_html__("Catalog Mode and Enquiry Form", "enhancements-for-woocommerce");
    }

    public function description(): string {
        return esc_html__(
            "Activate catalogue mode for your shop and you can add an enquiry form with a shortcode in every single product page. You will need a shortcode from a form builder plugin like fluent forms.",
            "enhancements-for-woocommerce"
        );
    }

    public function meta(): array {
        return [
            [
                "label" => esc_html__("Form Heading", "enhancements-for-woocommerce"),
                "description" => esc_html__(
                    "Place your heading above the form, for example, (Send us an Enquiry)",
                    "enhancements-for-woocommerce"
                ),
                "name" => "form_text",
                "type" => "text",
            ],
            [
                "label" => esc_html__("Form Shortcode", "enhancements-for-woocommerce"),
                "description" => esc_html__("Use here the form builder shortcode", "enhancements-for-woocommerce"),
                "name" => "shortcode",
                "type" => "text",
            ],
        ];
    }

    public function tooltip(): ?string {
        ob_start(); ?>
        <h1><strong><?php echo esc_html($this->title()); ?></strong></h1>
        
        <h3>Description</h3>
        <p>The Catalog Mode and Enquiry Form module transforms your WooCommerce store into a powerful product catalog, removing the typical eCommerce functionalities such as "Add to Cart" or "Buy Now" buttons.</p>
        <p>Once the Catalog Mode is activated, your online store displays your products as a catalog without any purchase options. Customers can view your products, browse categories, and get detailed descriptions without the pressure of buying immediately. This can be especially useful for businesses that need to negotiate terms or pricing on a per-customer basis.</p>
        <p>Additionally, the module supports an Enquiry Form on individual product pages, enabling potential customers to reach out to you directly for more information, quotes, or custom requests. By using a shortcode from a form builder plugin, such as Fluent Forms or any compatible form builder, you can embed a fully functional inquiry form. This form allows customers to express interest in specific products, request quotes, or ask questions. It’s a highly customizable feature, giving you control over what information you collect (e.g., name, contact information, product details, or any other relevant data).</p>
        <h3>Settings</h3>
        <h4>Form Heading Field</h4>
        <p>Place a heading that indicates what the form is for. Example "Send us an Enquiry"</p>
        <h4>Form Shortcode Field</h4>
        <p>You have to create a form first and put in the field the form shortcode. Please reference to your form builder instructions</p>
        <h3>Appearance</h3>
        <p>There are no customization options for this module, the form appearance depends on your form builder plugin or your theme.</p>
        <?php return ob_get_clean();
    }

    public function run() {
        add_filter("woocommerce_is_purchasable", "__return_false");
        add_action("woocommerce_single_product_summary", [$this, "single_product_message"], 20);
        remove_action("woocommerce_single_variation", "woocommerce_single_variation");
        remove_action("woocommerce_single_variation", "woocommerce_single_variation_add_to_cart_button");
    }

    function single_product_message() {
        echo '<p class="woocommerce-message">' . esc_html($this->form_text) . "</p>";
        echo do_shortcode($this->shortcode);
    }
}
