<?php

use Tami\WooCommerce\TamiAdminSettings;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$saved_settings = TamiAdminSettings::get_api_settings(false);
$environment = $saved_settings['environment'] ?? 'test';
?>
<div class="tami-text-tami">
    <div class="tami-m-0">
        <div class="tami-card tami-rounded-4 tami-bg-white tami-m-3 tami-overflow-hidden">
            <div class="tami-card-body">
                <ul class="tami-nav tami-nav-pills tami-border-bottom" id="environmentTab" role="tablist">
                    <li class="tami-nav-item" role="presentation">
                        <button class="tami-nav-link<?php echo ($environment == 'live') ? ' tami-active' : ''; ?>" id="live-tab" data-tamibs-toggle="tamitab"
                                data-tamibs-target="#live-tab-pane" type="button" role="tab"
                                aria-controls="live-tab-pane" aria-selected="true"><?php
                            esc_attr_e('Live', 'tami-payment');
                            ?></button>
                    </li>
                    <li class="tami-nav-item" role="presentation">
                        <button class="tami-nav-link<?php echo ($environment == 'test') ? ' tami-active' : ''; ?>" id="test-tab" data-tamibs-toggle="tamitab"
                                data-tamibs-target="#test-tab-pane" type="button" role="tab"
                                aria-controls="test-tab-pane"
                                aria-selected="false"><?php esc_attr_e('Test', 'tami-payment'); ?></button>
                    </li>
                </ul>
                <br />

                <div class="tab-content tami-text-dark" id="environmentTabContent">
                    <div class="tami-text-dark tami-tab-pane <?php echo ($environment == 'live') ? ' tami-show tami-active' : ''; ?>" id="live-tab-pane"
                        <?php echo ($environment !== 'live') ? 'style="display:none"' : ''; ?>
                         role="tabpanel" aria-labelledby="live-tab" tabindex="0">
                        <form
                                id="tami-api-settings-form-live" name="tami-api-settings-form-live"
                                class="tami-text-tami tami-ajax-form"
                                method="post"
                                action="admin-ajax.php">
                            <input type="hidden" name="action" value="tami_api_settings_save"/>
                            <?php wp_nonce_field('tami_save_api_settings_live'); ?>
                            <?php \Tami\WooCommerce\TamiAdmin::getTableContent('live'); ?>
                            <input type="hidden" id="environment-live" name="environment" value="live"/>

                            <div class="tami-row">
                                <div class="tami-col">

                                </div>
                                <div class="tami-col">
                                    <div class="tami-text-end">
                                        <button type="button" class="tami-btn tami-me-2 tami-btn-outline-success tami-btn-validate-api">
                            <span style="display: none"
                                  class="tami--button-loader tami-spinner-border tami-spinner-border-sm"></span>
                                            <?php esc_attr_e('Validate', 'tami-payment') ?>
                                        </button>

                                        <button type="submit" form="tami-api-settings-form-live"
                                                class="tami-btn tami-btn-primary">
                                <span style="display: none"
                                      class="tami--button-loader tami-spinner-border tami-spinner-border-sm"></span>
                                            <?php esc_attr_e('Save Changes', 'tami-payment') ?>
                                        </button>
                                    </div>
                                </div>
                            </div>

                        </form>
                    </div>
                    <div class="tami-text-dark tami-tab-pane<?php echo ($environment == 'test') ? ' tami-show tami-active' : ''; ?>"
                        <?php echo ($environment !== 'test') ? 'style="display:none"' : ''; ?>
                         id="test-tab-pane" role="tabpanel"
                         aria-labelledby="test-tab" tabindex="0">
                        <form
                                id="tami-api-settings-form-test" name="tami-api-settings-form-test"
                                class="tami-text-tami tami-ajax-form"
                                method="post"
                                action="admin-ajax.php">
                            <input type="hidden" name="action" value="tami_api_settings_save"/>
                            <?php wp_nonce_field('tami_save_api_settings_test'); ?>
                            <?php \Tami\WooCommerce\TamiAdmin::getTableContent('test'); ?>
                            <input type="hidden" id="environment-test" name="environment" value="test"/>
                            <div class="tami-row">
                                <div class="tami-col">

                                </div>
                                <div class="tami-col">
                                    <div class="tami-text-end">

                                        <button type="button" class="tami-btn tami-me-2 tami-btn-outline-success tami-btn-validate-api">
                            <span style="display: none"
                                  class="tami--button-loader tami-spinner-border tami-spinner-border-sm"></span>
                                            <?php esc_attr_e('Validate', 'tami-payment') ?>
                                        </button>

                                        <button type="submit" form="tami-api-settings-form-test"
                                                class="tami-btn tami-btn-primary">
                                <span style="display: none"
                                      class="tami--button-loader tami-spinner-border tami-spinner-border-sm"></span>
                                            <?php esc_attr_e('Save Changes', 'tami-payment') ?>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>


            </div>
        </div>

    </div>
</div>
