{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-end">
        <button type="submit" form="form-api" title="{{ button_save }}" class="btn btn-primary"><i class="fa-solid fa-floppy-disk"></i></button>
        <a href="{{ back }}" title="{{ button_back }}" class="btn btn-light"><i class="fa-solid fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    <div class="card">
      <div class="card-header"><i class="fa-solid fa-pencil"></i> {{ text_form }}</div>
      <div class="card-body">
        <form id="form-api" action="{{ save }}" method="post" data-oc-toggle="ajax">
          <ul class="nav nav-tabs">
            <li class="nav-item"><a href="#tab-general" data-bs-toggle="tab" class="nav-link active">{{ tab_general }}</a></li>
            <li class="nav-item"><a href="#tab-ip" data-bs-toggle="tab" class="nav-link">{{ tab_ip }}</a></li>
            <li class="nav-item"><a href="#tab-history" data-bs-toggle="tab" class="nav-link">{{ tab_history }}</a></li>
          </ul>
          <div class="tab-content">
            <div id="tab-general" class="tab-pane active">
              <div class="row mb-3">
                <label for="input-username" class="col-sm-2 col-form-label">{{ entry_username }}</label>
                <div class="col-sm-10">
                  <input type="text" name="username" value="{{ username }}" placeholder="{{ entry_username }}" id="input-username" class="form-control" required/>
                  <div id="error-username" class="invalid-feedback"></div>
                </div>
              </div>
              <div class="row mb-3">
                <label for="input-key" class="col-sm-2 col-form-label">{{ entry_key }}</label>
                <div class="col-sm-10">
                  <textarea name="key" placeholder="{{ entry_key }}" rows="5" id="input-key" class="form-control mb-1" required>{{ key }}</textarea>
                  <button type="button" id="button-generate" class="btn btn-primary"><i class="fa-solid fa-rotate"></i> {{ button_generate }}</button>
                  <div id="error-key" class="invalid-feedback"></div>
                </div>
              </div>
              <div class="row mb-3">
                <label class="col-sm-2 col-form-label">{{ entry_status }}</label>
                <div class="col-sm-10">
                  <div class="col-sm-10">
                    <x-switch name="status" value="1" checked="{{ status }}" input-id="input-status" input-class="form-switch form-switch-lg"></x-switch>
                  </div>
                </div>
              </div>
            </div>
            <div id="tab-ip" class="tab-pane">
              <div class="alert alert-info"><i class="fa-solid fa-info-circle"></i> {{ text_ip }}</div>
              <div class="table-responsive">
                <table id="ip" class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <th>{{ entry_ip }}</th>
                      <th class="text-end"></th>
                    </tr>
                  </thead>
                  <tbody>
                    {% set ip_row = 0 %}
                    {% for api_ip in api_ips %}
                      <tr id="ip-row-{{ ip_row }}">
                        <td><input type="text" name="api_ip[]" value="{{ api_ip }}" placeholder="{{ entry_ip }}" class="form-control"/></td>
                        <td class="text-end"><button type="button" onclick="$('#ip-row-{{ ip_row }}').remove()" title="{{ button_remove }}" class="btn btn-danger"><i class="fa-solid fa-minus-circle"></i></button></td>
                      </tr>
                      {% set ip_row = ip_row + 1 %}
                    {% endfor %}
                  </tbody>
                  <tfoot>
                    <tr>
                      <td></td>
                      <td class="text-end"><button type="button" id="button-ip" title="{{ button_ip_add }}" class="btn btn-primary"><i class="fa-solid fa-plus-circle"></i></button></td>
                    </tr>
                  </tfoot>
                </table>
              </div>
            </div>
            <div id="tab-history" class="tab-pane">
              <fieldset>
                <legend>{{ text_history }}</legend>
                <div id="history">{{ history }}</div>
              </fieldset>
            </div>
          </div>
          <input type="hidden" name="api_id" value="{{ api_id }}" id="input-api-id"/>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript" src="view/javascript/api.js"></script>
{{ footer }}