{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-end">
        <button type="submit" form="form-user" data-bs-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa-solid fa-floppy-disk"></i></button>
        <a href="{{ back }}" data-bs-toggle="tooltip" 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-user" 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-authorize" data-bs-toggle="tab" class="nav-link">{{ tab_authorize }}</a></li>
            <li class="nav-item"><a href="#tab-login" data-bs-toggle="tab" class="nav-link">{{ tab_login }}</a></li>
          </ul>
          <div class="tab-content">
            <div id="tab-general" class="tab-pane active">
              <fieldset>
                <legend>{{ text_user }}</legend>
                <div class="row mb-3 required">
                  <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"/>
                    <div id="error-username" class="invalid-feedback"></div>
                  </div>
                </div>
                <div class="row mb-3">
                  <label for="input-user-group" class="col-sm-2 col-form-label">{{ entry_user_group }}</label>
                  <div class="col-sm-10">
                    <select name="user_group_id" id="input-user-group" class="form-select">
                      {% for user_group in user_groups %}
                        <option value="{{ user_group.user_group_id }}"{% if user_group.user_group_id == user_group_id %} selected{% endif %}>{{ user_group.name }}</option>
                      {% endfor %}
                    </select>
                  </div>
                </div>
                <div class="row mb-3 required">
                  <label for="input-firstname" class="col-sm-2 col-form-label">{{ entry_firstname }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="firstname" value="{{ firstname }}" placeholder="{{ entry_firstname }}" id="input-firstname" class="form-control"/>
                    <div id="error-firstname" class="invalid-feedback"></div>
                  </div>
                </div>
                <div class="row mb-3 required">
                  <label for="input-lastname" class="col-sm-2 col-form-label">{{ entry_lastname }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="lastname" value="{{ lastname }}" placeholder="{{ entry_lastname }}" id="input-lastname" class="form-control"/>
                    <div id="error-lastname" class="invalid-feedback"></div>
                  </div>
                </div>
                <div class="row mb-3 required">
                  <label for="input-email" class="col-sm-2 col-form-label">{{ entry_email }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="email" value="{{ email }}" placeholder="{{ entry_email }}" id="input-email" class="form-control"/>
                    <div id="error-email" class="invalid-feedback"></div>
                  </div>
                </div>
                <div class="row mb-3">
                  <label for="input-image" class="col-sm-2 col-form-label">{{ entry_image }}</label>
                  <div class="col-sm-10">
                    <div class="card image">
                      <img src="{{ thumb }}" alt="" title="" id="thumb-image" data-oc-placeholder="{{ placeholder }}" class="card-img-top"/> <input type="hidden" name="image" value="{{ image }}" id="input-image"/>
                      <div class="card-body">
                        <button type="button" data-oc-toggle="image" data-oc-target="#input-image" data-oc-thumb="#thumb-image" class="btn btn-primary btn-sm btn-block"><i class="fa-solid fa-pencil"></i> {{ button_edit }}</button>
                        <button type="button" data-oc-toggle="clear" data-oc-target="#input-image" data-oc-thumb="#thumb-image" class="btn btn-warning btn-sm btn-block"><i class="fa-regular fa-trash-can"></i> {{ button_clear }}</button>
                      </div>
                    </div>
                  </div>
                </div>
              </fieldset>
              <fieldset>
                <legend>{{ text_password }}</legend>
                <div class="row mb-3 required">
                  <label for="input-password" class="col-sm-2 col-form-label">{{ entry_password }}</label>
                  <div class="col-sm-10">
                    <input type="password" name="password" value="{{ password }}" placeholder="{{ entry_password }}" id="input-password" class="form-control" autocomplete="new-password"/>
                    <div id="error-password" class="invalid-feedback"></div>
                  </div>
                </div>
                <div class="row mb-3 required">
                  <label for="input-confirm" class="col-sm-2 col-form-label">{{ entry_confirm }}</label>
                  <div class="col-sm-10">
                    <input type="password" name="confirm" value="{{ confirm }}" placeholder="{{ entry_confirm }}" id="input-confirm" class="form-control"/>
                    <div id="error-confirm" class="invalid-feedback"></div>
                  </div>
                </div>
              </fieldset>
              <fieldset>
                <legend>{{ text_other }}</legend>
                <div class="row mb-3">
                  <label class="col-sm-2 col-form-label">{{ entry_status }}</label>
                  <div class="col-sm-10">
                    <div class="form-check form-switch form-switch-lg">
                      <input type="hidden" name="status" value="0"/>
                      <input type="checkbox" name="status" value="1" id="input-status" class="form-check-input"{% if status %} checked{% endif %}/>
                    </div>
                  </div>
                </div>
              </fieldset>
              <input type="hidden" name="user_id" value="{{ user_id }}" id="input-user-id"/>
            </div>
            <div id="tab-authorize" class="tab-pane">
              <fieldset>
                <legend>{{ text_authorize }}</legend>
                <div id="authorize">{{ authorize }}</div>
              </fieldset>
            </div>
            <div id="tab-login" class="tab-pane">
              <fieldset>
                <legend>{{ text_login }}</legend>
                <div id="login">{{ login }}</div>
              </fieldset>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('#authorize').on('click', '.pagination a', function (e) {
    e.preventDefault();

    $('#authorize').load(this.href);
});

$('#authorize').on('click', '.btn', function (e) {
    e.preventDefault();

    var element = this;

    if (confirm('{{ text_confirm }}')) {
        $.ajax({
            url: $(element).attr('href'),
            dataType: 'json',
            beforeSend: function () {
                $(element).button('loading');
            },
            complete: function () {
                $(element).button('reset');
            },
            success: function (json) {
                $('.alert-dismissible').remove();

                if (json['redirect']) {
                    location = json['redirect'];
                }

                if (json['error']) {
                    $('#alert').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
                }

                if (json['success']) {
                    $('#alert').prepend('<div class="alert alert-success alert-dismissible"><i class="fa-solid fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');

                    $('#authorize').load('index.php?route=user/user.authorize&user_token={{ user_token }}&user_id={{ user_id }}');
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }
});

$('#login').on('click', '.pagination a', function (e) {
    e.preventDefault();

    $('#login').load(this.href);
});
//--></script>
{{ footer }} 