<div class="row mt-4">

    <!-- Navigation -->
    <div class="col-lg-3 col-md-4 col-12 mb-md-0 mb-3">
        <div class="d-flex justify-content-between flex-column mb-2 mb-md-0">
            <ul class="nav nav-align-left nav-pills flex-column">
                <li class="nav-item">
                    <button class="nav-link active" data-bs-toggle="tab" data-bs-target="#general">
                        <i class="ti ti-sitemap me-1 ti-sm"></i>
                        <span class="align-middle fw-semibold"><?=lang("App.settings_label_general")?></span>
                    </button>
                </li>
                <li class="nav-item">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#email">
                        <i class="ti ti-mail me-1 ti-sm"></i>
                        <span class="align-middle fw-semibold"><?=lang("App.settings_label_email")?></span>
                    </button>
                </li>
                <?php /*
                <li class="nav-item">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#backup">
                        <i class="ti ti-server me-1 ti-sm"></i>
                        <span class="align-middle fw-semibold"><?=lang("App.settings_label_backup")?></span>
                    </button>
                </li>

                <li class="nav-item">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#logs">
                        <i class="ti ti-archive me-1 ti-sm"></i>
                        <span class="align-middle fw-semibold"><?=lang("App.settings_label_logs")?></span>
                    </button>
                </li>
                <li class="nav-item">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#cron">
                        <i class="ti ti-rotate-clockwise me-1 ti-sm"></i>
                        <span class="align-middle fw-semibold"><?=lang("App.settings_label_cron")?></span>
                    </button>
                </li>
                */ ?>
            </ul>
        </div>
    </div>
    <!-- /Navigation -->

    <!-- System Settings -->
    <div class="col-lg-9 col-md-8 col-12">
        <form class="form" action="<?= $formAction  ?>" method="post">
            <?= csrf_field() ?>
            <div class="tab-content py-0">
                <!-- General Settings -->
                <div class="tab-pane fade show active" id="general" role="tabpanel">
                    <div class="d-flex mb-3 gap-3">
                        <div>
                              <span class="badge bg-label-primary rounded-2 p-2">
                                <i class="ti ti-sitemap ti-lg"></i>
                              </span>
                        </div>
                        <div>
                            <h4 class="mb-0">
                                <span class="align-middle"><?=lang("App.settings_label_general_title")?></span>
                            </h4>
                        </div>
                    </div>
                    <div class="card">
                        <div class="row card-body">
                            DETALLES ESPECIFICOS DEL ERP (TBD)
                        </div>
                    </div>
                </div>
                <!-- /General Settings -->

                <!-- Email Settings -->
                <div class="tab-pane fade show" id="email" role="tabpanel">
                    <div class="d-flex mb-3 gap-3">
                        <div>
                              <span class="badge bg-label-primary rounded-2 p-2">
                                <i class="ti ti-mail ti-lg"></i>
                              </span>
                        </div>
                        <div>
                            <h4 class="mb-0">
                                <span class="align-middle"><?=lang("App.settings_label_email_title")?></span>
                            </h4>
                        </div>
                    </div>
                    <div class="card">
                        <div class="row card-body">
                            <div class="col-lg-12 mb-3">
                                <label class="text-primary"><?=lang("App.settings_label_email_subtitle_1")?></label>
                            </div>
                            <div class="col-lg-3 mb-3">
                                <label for="email_gateway" class="form-label"><?=lang("App.settings_field_email_gateway")?></label>
                                <?php $id_select = (isset($obj)) ? $obj['email_gateway'] : set_value('email_gateway');?>
                                <select name="email_gateway" id="email_gateway" class="select2 form-control">
                                    <option value="smtp" <?= $id_select == "smtp" ? 'selected' : '' ?>><?=lang("App.settings_field_email_gateway_smtp")?></option>
                                </select>
                            </div>
                            <div class="col-lg-3 mb-3">
                                <label for="email_smtp" class="form-label"><?=lang("App.settings_field_email_smtp")?></label>
                                <input
                                        type="text"
                                        id="email_smtp"
                                        name="email_smtp"
                                        class="form-control"
                                        placeholder="<?=lang("App.settings_field_email_smtp_ph")?>"
                                        value="<?= old('email_smtp', $settingsEntity->email_smtp) ?>"
                                >
                            </div>
                            <div class="col-lg-3 mb-3">
                                <label for="email_port" class="form-label"><?=lang("App.settings_field_email_port")?></label>
                                <input
                                        type="number"
                                        id="email_port"
                                        name="email_port"
                                        class="form-control"
                                        placeholder="<?=lang("App.settings_field_email_port_ph")?>"
                                        value="<?= old('email_port', $settingsEntity->email_port) ?>"
                                >
                            </div>
                            <div class="col-lg-3 mb-3">
                                <label for="email_cert" class="form-label"><?=lang("App.settings_field_email_cert")?></label>
                                <?php $id_select = (isset($settingsEntity)) ? $settingsEntity->email_cert : 'none';?>
                                <select name="email_cert" id="email_cert" class="select2 form-control">
                                    <option value="none" <?= $id_select == "none" ? 'selected' : '' ?>><?=lang("App.settings_field_email_cert_none")?></option>
                                    <option value="ssl" <?= $id_select == "ssl" ? 'selected' : '' ?>><?=lang("App.settings_field_email_cert_ssl")?></option>
                                    <option value="tls" <?= $id_select == "tls" ? 'selected' : '' ?>><?=lang("App.settings_field_email_cert_tls")?></option>
                                </select>
                            </div>
                            <div class="col-lg-6 mb-3">
                                <label for="email_address" class="form-label"><?=lang("App.settings_field_email_address")?></label>
                                <input
                                        type="text"
                                        id="email_address"
                                        name="email_address"
                                        class="form-control"
                                        placeholder="<?=lang("App.settings_field_email_address_ph")?>"
                                        value="<?= old('email_address', $settingsEntity->email_address) ?>"
                                >
                            </div>
                            <div class="col-lg-6 mb-3">
                                <label for="email_pass" class="form-label"><?=lang("App.settings_field_email_pass")?></label>
                                <input
                                        type="password"
                                        id="email_pass"
                                        name="email_pass"
                                        class="form-control"
                                        placeholder="<?=lang("App.settings_field_email_pass_ph")?>"
                                        value="<?= old('email_pass', $settingsEntity->email_pass) ?>"
                                >
                            </div>

                            <div class="col-lg-6 mb-3">
                                <label for="email_name" class="form-label"><?=lang("App.settings_field_email_name")?></label>
                                <input
                                        type="text"
                                        id="email_name"
                                        name="email_name" class="form-control"
                                        placeholder="<?=lang("App.settings_field_email_name_ph")?>"
                                        value="<?= old('email_name', $settingsEntity->email_name) ?>"
                                >
                            </div>
                            <?php /*
                            <div class="col-lg-12 mt-4 mb-3">
                                <label class="text-primary"><?=lang("App.settings_field_test_send")?></label>
                            </div>
                            <div class="col-lg-6 mb-3">
                                <label class="form-label"><?=lang("App.settings_field_email_address")?></label>
                                <div class="input-group">
                                    <input
                                            type="email"
                                            id="send_email_test"
                                            name="send_email_test"
                                            class="form-control"
                                            placeholder="<?=lang("App.settings_field_email_address_ph")?>"
                                    >
                                    <div class="input-group-append">
                                        <button type="button" class="btn btn-outline-primary" onclick="send_test()"><?=lang("App.settings_field_test_send_btn")?></button>
                                    </div>
                                </div>
                                <p class="text-primary" id="msg_email_test" style="display: none;"><i class="fas fa-spinner fa-pulse"></i> <?= lang("App.login_wait") ?></p>
                            </div>
                            */ ?>
                        </div>
                    </div>
                </div>
                <!-- /Email Settings -->

                <?php /*
                <!-- Backup Settings -->
                <div class="tab-pane fade show" id="backup" role="tabpanel">
                    <div class="d-flex mb-3 gap-3">
                        <div>
                              <span class="badge bg-label-primary rounded-2 p-2">
                                <i class="ti ti-server ti-lg"></i>
                              </span>
                        </div>
                        <div>
                            <h4 class="mb-0">
                                <span class="align-middle"><?=lang("App.settings_label_backup_title")?></span>
                            </h4>
                        </div>
                    </div>
                    <div class="card">
                        <div class="row card-body">
                            <div class="row">
                                <div class="col-lg-12 mb-3">
                                    <label class="text-primary"><?=lang("App.settings_label_backup_subtitle_1")?></label>
                                </div>
                                <div class="col-lg-4 mb-3">
                                    <label for="backup_storage" class="form-label"><?=lang("App.settings_field_backup_storage")?></label>
                                    <?php $id_select = (isset($obj)) ? $obj['backup_storage'] : set_value('backup_storage');?>
                                    <select name="backup_storage" id="backup_storage" class="select2 form-control">
                                        <option value="local" <?= $id_select == "local" ? 'selected' : '' ?>><?=lang("App.settings_field_storage_gateway_local")?></option>
                                    </select>
                                </div>
                                <div class="col-lg-4 mb-3">
                                    <label for="backup_table" class="form-label"><?=lang("App.settings_field_backup_table")?></label>
                                    <?php $select = (isset($obj)) ? $obj['backup_table'] : set_value('backup_table');?>
                                    <select name="backup_table[]" id="backup_table" class="select2 form-control" multiple="multiple">
                                        <?php
                                        $select = explode(',',$select);
                                        foreach($select??[] as $id_select){
                                            if ($id_select == "all"){
                                                $all = 'selected';
                                            }
                                        }
                                        ?>
                                        <option value="all" <?=$all??''?>><?=lang("App.settings_field_backup_table_all")?></option>
                                        <?php foreach ($tables??[] as $item) : ?>
                                            <?php foreach ($select??[] as $id_select) : ?>
                                                <?php
                                                if ($id_select == $item){
                                                    $selItem = 'selected';
                                                }
                                                ?>
                                            <?php endforeach; ?>
                                            <option value="<?=$item?>" <?=$selItem??''?>><?=lang("App.settings_field_backup_table")?> (<?=$item?>)</option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="col-lg-4 mb-3">
                                    <label for="backup_time" class="form-label"><?=lang("App.settings_field_backup_time")?></label>
                                    <?php $id_select = (isset($obj)) ? $obj['backup_time'] : set_value('backup_time');?>
                                    <select name="backup_time" id="backup_time" class="select2 form-control">
                                        <?php for ($i = 0; $i <= 23; $i++) : ?>
                                            <option value="<?= $i < 10 ? '0'.$i.':00:00':$i.':00:00' ?>" <?= $id_select == "<?= $i < 10 ? '0'.$i.':00:00':$i.':00:00' ?>" ? 'selected' : '' ?>><?= $i < 10 ? '0'.$i.':00':$i.':00' ?></option>
                                            <option value="<?= $i < 10 ? '0'.$i.':30:00':$i.':30:00' ?>" <?= $id_select == "<?= $i < 10 ? '0'.$i.':30:00':$i.':30:00' ?>" ? 'selected' : '' ?>><?= $i < 10 ? '0'.$i.':30':$i.':30' ?></option>
                                        <?php endfor; ?>
                                    </select>
                                </div>
                                <div class="col-lg-12 mb-3">
                                    <label for="backup_email" class="form-label"><?=lang("App.settings_field_backup_email")?></label>
                                    <input
                                            type="text"
                                            id="backup_email"
                                            min="1"
                                            name="backup_email"
                                            class="form-control"
                                            placeholder="<?=lang("App.settings_field_backup_email_ph")?>"
                                            value="<?= (isset($obj)) ? $obj['backup_email'] : set_value('backup_email');?>"
                                    />
                                </div>
                                <div class="col-lg-3 mb-3">
                                    <div class="small mb-3"><?=lang("App.settings_field_backup_notification_email")?></div>
                                    <label class="switch">
                                        <input
                                                type="checkbox"
                                                id="backup_notification_email"
                                                name="backup_notification_email"
                                                class="switch-input"
                                            <?= $obj['backup_notification_email']??false ? 'checked' : ''?>
                                        />
                                        <span class="switch-toggle-slider">
                                            <span class="switch-on"></span>
                                            <span class="switch-off"></span>
                                        </span>
                                        <span class="switch-label"><?=lang("App.global_activate")?></span>
                                    </label>
                                </div>
                                <div class="col-lg-3 mb-3">
                                    <div class="small mb-3"><?=lang("App.settings_field_backup_automatic")?></div>
                                    <label class="switch">
                                        <input
                                                type="checkbox"
                                                id="backup_automatic"
                                                name="backup_automatic"
                                                class="switch-input"
                                            <?= $obj['backup_automatic']??false ? 'checked' : ''?>
                                        />
                                        <span class="switch-toggle-slider">
                                            <span class="switch-on"></span>
                                            <span class="switch-off"></span>
                                        </span>
                                        <span class="switch-label"><?=lang("App.global_activate")?></span>
                                    </label>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-12 text-right mb-3">
                                    <a href="<?=site_url("integration/create_backup/1")?>" class="btn btn-primary mt-2">
                                        <i class="fas fa-download"></i> <?=lang("App.settings_label_backup_btn_1")?>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Backup Settings -->

                <!-- Logs Settings -->
                <div class="tab-pane fade show" id="logs" role="tabpanel">
                    <div class="d-flex mb-3 gap-3">
                        <div>
                              <span class="badge bg-label-primary rounded-2 p-2">
                                <i class="ti ti-archive ti-lg"></i>
                              </span>
                        </div>
                        <div>
                            <h4 class="mb-0">
                                <span class="align-middle"><?=lang("App.settings_label_logs_title")?></span>
                            </h4>
                        </div>
                    </div>
                    <div class="card">
                        <div class="row card-body">
                            <div class="row">
                                <div class="col-lg-12 mb-3">
                                    <label class="text-primary"><?=lang("App.settings_label_logs_subtitle_1")?></label>
                                </div>
                                <div class="col-lg-3 mb-3">
                                    <div class="small mb-3"><?=lang("App.settings_field_remove_log")?></div>
                                    <label class="switch">
                                        <input
                                                type="checkbox"
                                                id="remove_log"
                                                name="remove_log"
                                                class="switch-input"
                                            <?= $obj['remove_log']??false ? 'checked' : ''?>
                                        />
                                        <span class="switch-toggle-slider">
                                            <span class="switch-on"></span>
                                            <span class="switch-off"></span>
                                        </span>
                                        <span class="switch-label"><?=lang("App.global_activate")?></span>
                                    </label>
                                </div>
                                <div class="col-lg-3 mb-3">
                                    <label for="remove_log_time" class="form-label"><?=lang("App.settings_field_remove_log_time")?></label>
                                    <div class="input-group">
                                        <input
                                                type="number"
                                                id="remove_log_time"
                                                min="1"
                                                name="remove_log_time"
                                                class="form-control"
                                                placeholder="<?=lang("App.settings_field_remove_log_time_ph")?>"
                                                value="<?= (isset($obj)) ? $obj['remove_log_time'] : set_value('remove_log_time');?>"
                                        />
                                        <span class="input-group-text"><?=lang("App.global_days")?></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Logs Settings -->

                <!-- Cron Settings -->
                <div class="tab-pane fade show" id="cron" role="tabpanel">
                    <div class="d-flex mb-3 gap-3">
                        <div>
                              <span class="badge bg-label-primary rounded-2 p-2">
                                <i class="ti ti-rotate-clockwise ti-lg"></i>
                              </span>
                        </div>
                        <div>
                            <h4 class="mb-0">
                                <span class="align-middle"><?=lang("App.settings_label_cron_title")?></span>
                            </h4>
                        </div>
                    </div>
                    <div class="card">
                        <div class="row card-body">
                            <div class="row">
                                <div class="col-lg-12 mb-3">
                                    <label class="text-primary"><?=lang("App.settings_label_cron_subtitle_1")?></label>
                                </div>

                                <div class="col-lg-12 mb-3">
                                    <p class="form-label">
                                        <b><?=lang("App.settings_label_cron_timer")?></b>
                                        <br><?=lang("App.settings_label_cron_timer_time")?>
                                        <br><?=getenv('app.baseURL').'/cron'?>
                                    </p>
                                </div>
                                <div class="col-lg-12 mb-3">
                                    <label class="text-primary"><?=lang("App.settings_label_cron_subtitle_2")?></label>
                                    <!-- CSRF token -->
                                    <input type="hidden" class="txt_csrfname" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
                                    <!-- Table -->
                                    <table id='table-grid' class="table table-striped nowrap" style="width:100%">
                                        <thead>
                                        <tr>
                                            <th><?=lang("App.settings_grid_routine")?></th>
                                            <th><?=lang("App.settings_group_grid_error")?></th>
                                            <th><?=lang("App.settings_group_grid_created_at")?></th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Cron Settings -->
                */ ?>

            </div>
            <div class="tab-content pt-4">
                <button type="submit" class="btn btn-primary float-start me-sm-3 me-1">
                    <?= lang("App.global_save") ?>
                </button>
                <a href="<?= site_url('/') ?>" class="btn btn-secondary">
                    <?= lang("App.global_come_back") ?>
                </a>
            </div>
        </form>
    </div>
    <!-- /System Settings -->

</div>
