<?php
namespace FuseCommerce\Views\Admin\Settings;
if ( ! defined( 'ABSPATH' ) ) exit;

use FuseCommerce\Views\Admin\Settings\BaseView;
use FuseCommerce\Views\Admin\Settings\IView;
use FuseCommerce\Utils\OptionUtils;
use FuseCommerce\Views\Admin\Settings\Indexing;
use FuseCommerce\Views\Admin\Settings\Filters;
use FuseCommerce\Views\Admin\Settings\Shortcodes;

class MainSettings extends BaseView implements IView {

    public function render(): void {
        $options_group_slug = OptionUtils::OPTION_GROUP_SLUG;

        if (!function_exists('is_plugin_active')) {
            include_once(ABSPATH . 'wp-admin/includes/plugin.php');
        }

        $is_woocommerce_active = is_plugin_active('woocommerce/woocommerce.php');
        
        ?>
        <form method="post" action="options.php">
            <?php settings_fields($options_group_slug); ?>
            <div class="container-fluid mt-4">
                <?php if (!$is_woocommerce_active): ?>
                <div class="row requires-woocommerce">
                    <div class="col-md-12">
                        <div class="alert alert-danger" role="alert">
                            <strong><?php esc_html_e('WooCommerce Required', 'ftlcommerce-instant-product-search'); ?></strong>
                            <?php esc_html_e('This plugin requires WooCommerce to be installed and activated. Please install WooCommerce to use FtlCommerce.', 'ftlcommerce-instant-product-search'); ?>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
                <ul class="nav main-nav-tabs nav-tabs" id="settingsTab" role="tablist">
                    <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="general" data-bs-toggle="tab" data-bs-target="#indexing-pane" type="button" role="tab" aria-controls="indexing-pane" aria-selected="true"><?php esc_html_e('Indexing', 'ftlcommerce-instant-product-search') ?></button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="languages-tab" data-bs-toggle="tab" data-bs-target="#filters-pane" type="button" role="tab" aria-controls="filters-tab-pane" aria-selected="false"><?php esc_html_e('Filters', 'ftlcommerce-instant-product-search') ?></button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="shortcodes-tab" data-bs-toggle="tab" data-bs-target="#shortcodes-pane" type="button" role="tab" aria-controls="shortcodes-tab-pane" aria-selected="false"><?php esc_html_e('Shortcodes', 'ftlcommerce-instant-product-search') ?></button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="docs-tab" data-bs-toggle="tab" data-bs-target="#docs-pane" type="button" role="tab" aria-controls="docs-pane" aria-selected="false"><?php esc_html_e('Documentation', 'ftlcommerce-instant-product-search') ?></button>
                    </li>
                </ul>

                <div class="tab-content px-3 py-4" id="settingsTabContent">
                    <div class="tab-pane fade show active" id="indexing-pane" role="tabpanel" aria-labelledby="general" tabindex="0">
                        <?php (new Indexing())->render() ?>
                    </div>
                    <div class="tab-pane fade show" id="filters-pane" role="tabpanel" aria-labelledby="filters" tabindex="1">
                        <?php (new Filters())->render() ?>
                    </div>
                    <div class="tab-pane fade show" id="shortcodes-pane" role="tabpanel" aria-labelledby="shortcodes" tabindex="2">
                        <?php (new Shortcodes())->render() ?>
                    </div>
                    <div class="tab-pane fade" id="docs-pane" role="tabpanel" aria-labelledby="docs-tab" tabindex="2">
                        <div class="row">
                        <div class="col-md-12 mb-2">
                            <h5><?php esc_html_e('Documentation', 'ftlcommerce-instant-product-search'); ?></h5>
                            <div class="alert alert-info" role="alert">
                                <span><?php esc_html_e("Full documentation can be found at", 'ftlcommerce-instant-product-search') ?> <a href="https://sakuraleaf.com/showcase/fusecommerce/documentation/" target="_blank"><?php esc_html_e("FltCommerce Docs", 'ftlcommerce-instant-product-search') ?></a></span>.
                                <span><?php esc_html_e("Pro version can be found at", 'ftlcommerce-instant-product-search') ?> <a href="https://sakuraleaf.com/products/ftlcommerce-instant-product-search-for-woocommerce/" target="_blank"><?php esc_html_e("FltCommerce Pro", 'ftlcommerce-instant-product-search') ?></a></span>. 
                                <span><?php esc_html_e("Demo can be found at", 'ftlcommerce-instant-product-search') ?> <a href="https://sakuraleaf.com/showcase/fusecommerce/" target="_blank"><?php esc_html_e("FltCommerce Showcase", 'ftlcommerce-instant-product-search') ?></a></span>.
                            </div>
                        </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <?php
    }
}