<?php

use Tami\WooCommerce\TamiAdminSettings;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$saved_settings = TamiAdminSettings::get_module_settings();

?>
<form
        method="post"
        action="admin-ajax.php"
        name="tami-module-settings-form"
        id="tami-module-settings-form"
        class="tami-text-tami tami-ajax-form"
>
    <input type="hidden" name="action" value="tami_module_settings_save"/>
	<?php wp_nonce_field( 'tami_save_module_settings' ); ?>
    <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">
                <table class="tami-table tami-table-striped tami-table-borderless">
                    <tbody>
                    <tr>
                        <th width="40%">
                            <label
                                    style="width: auto !important;"
                                    data-tamibs-toggle="tooltip"
                                    title="<?php esc_attr_e( 'Please enable for activate this payment gateway.', 'tami-payment' ); ?>"
                                    class="tami-text-tami tami-fw-normal tami-w-100"
                                    for="form-ModuleSettings-Enabled">
                                <?php esc_attr_e( 'Activate Tami Gateway', 'tami-payment' ) ?>
                                <i class="fa fa-info-circle"></i>
                            </label>
                        </th>
                        <td class="user-select-none">
                            <div class="tami-checkbox-custom tami-mt-1">
                                <input id="form-ModuleSettings-Enabled"
                                       value="yes"
                                       type="checkbox"
                                       name="enabled"
                                       class="tami-custom-switch"<?php echo ( esc_attr($saved_settings['enabled']) == 'yes' ) ? ' checked' : ''; ?>
                                />
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <th width="40%">
                            <label
                                    style="width: auto !important;"
                                    data-tamibs-toggle="tooltip"
                                    title="<?php esc_attr_e( 'Network traffic between TAMI and your server is stored when debug mode is enable. You can see the stored data in the `WooCommerce / Status / Logs`', 'tami-payment' ); ?>"
                                    class="tami-text-tami tami-fw-normal tami-w-100"
                                    for="form-ModuleSettings-1">
			                    <?php esc_attr_e( 'Debug Mode', 'tami-payment' ) ?>
                                <i class="fa fa-info-circle"></i>
                            </label>
                        </th>
                        <td class="user-select-none">
                            <div class="tami-checkbox-custom tami-mt-1">
                                <input id="form-ModuleSettings-1"
                                       value="1"
                                       type="checkbox"
                                       name="debug_mode"
                                       class="tami-custom-switch"<?php echo ( esc_attr($saved_settings['debug_mode']) == '1' ) ? ' checked' : ''; ?>
                                />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th width="40%">
                            <label class="tami-text-tami tami-fw-normal tami-w-100"
                                   style="width: auto !important;"
                                   for="form-ModuleSettings-2"><?php esc_attr_e( 'Failed Transaction Logs', 'tami-payment' ) ?></label>
                        </th>
                        <td class="user-select-none">
                            <div class="tami-checkbox-custom tami-mt-1">
                                <input id="form-ModuleSettings-2"
                                       value="yes"
                                       type="checkbox"
                                       name="save_failed_transactions"
                                       class="tami-custom-switch"<?php echo ( esc_attr($saved_settings['save_failed_transactions']) == 'yes' ) ? ' checked' : ''; ?>
                                />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th width="40%">
                            <label
                                    data-tamibs-toggle="tooltip"
                                    style="width: auto !important;"
                                    title="<?php esc_attr_e( 'Enter gateway title for checkout page.', 'tami-payment' ); ?>"
                                    class="tami-text-tami tami-fw-normal tami-w-100"
                                    for="form-ModuleSettings-Title">
                                <?php esc_attr_e( 'Payment Gateway Title', 'tami-payment' ) ?>
                                <i class="fa fa-info-circle"></i>
                            </label>
                        </th>
                        <td class="user-select-none">
                            <input
                                    style="max-width: 20rem;"
                                    name="title"
                                    class="tami-form-control" type="text"
                                    value="<?php echo esc_attr($saved_settings['title']) ?? esc_attr__('Credit/Debit Card Payment','tami-payment'); ?>" id="form-ModuleSettings-Title"
                            />
                        </td>
                    </tr>
                    <!--<tr>
                        <th width="40%">
                            <label
                                    data-tamibs-toggle="tooltip"
                                    title="<?php /*echo __( 'Enter gateway description for checkout page.', 'tami-payment' ); */?>"
                                    class="tami-text-tami tami-fw-normal tami-w-100"
                                    for="form-ModuleSettings-Description">
                                <?php /*_e( 'Description', 'tami-payment' ) */?>
                                <i class="fa fa-info-circle"></i>
                            </label>
                        </th>
                        <td class="user-select-none">
                            <input
                                    name="description"
                                    class="tami-form-control" type="text"
                                    value="<?php /*echo $saved_settings['description'] ?? __('Make online payment with your credit or debit card.','tami-payment'); */?>" id="form-ModuleSettings-Description"
                            />
                        </td>
                    </tr>-->
                    <tr>
                        <th width="40%">
                            <label
                                    style="width: auto !important;"
                                    class="tami-text-tami tami-fw-normal tami-w-100"
                                    for="form-ModuleSettings-0"><?php esc_attr_e( 'Paid Order Status', 'tami-payment' ) ?></label>
                        </th>
                        <td>
                            <select
                                    style="max-width: 20rem;"
                                    name="order_status"
                                    type="select"
                                    class="tami-form-select" autocomplete="off"
                                    id="form-ModuleSettings-0"
                            >
								<?php
								$all_statuses = array_merge( array( 'default' => esc_attr__( 'Default', 'tami-payment' ) ), wc_get_order_statuses() );
								foreach ( $all_statuses as $order_status_key => $order_status_label ) {
									echo sprintf( '<option value="%s"%s>%s</option>', esc_attr($order_status_key), ( esc_attr($order_status_key) === esc_attr($saved_settings['order_status']) ? ' selected' : '' ), esc_attr($order_status_label) );
								}
								?>
                            </select>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="tami-text-end">
                    <button
                            type="submit" class="tami-btn tami-btn tami-btn-primary"
                            form="tami-module-settings-form">
                        <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>
    </div>
</form>
