[% USE date %]
[% WRAPPER _user_profile_frame.tt
   tab = 'user'
%]

  <div class="body max-w-[900px] ">
    <table class="cellspacing w-full table-fixed">
      <tr>
        <th class="w-40">Username</th>
        <td class="font-semibold">[% remote_user %]</td>
      </tr>
      <tr class="hoverable">
        <th class="align-top">Contactgroups</th>
        <td>
          <div class="flexrow flex-nowrap gap-1 justify-between">
            <span>[% IF profile_user.groups.size > 0; profile_user.groups.sort.join(', '); ELSE %]&lt;none&gt;[% END %]</span>
            [%  IF profile_user.defined("timestamp"); cache_age = date.now - profile_user.timestamp; IF cache_age > 5 %]
              <a class="link" href="user.cgi?clear_auth_cache=1"><span class="textHINTsoft" title="auth cache last updated: [% date_format(c, profile_user.timestamp, datetime_format) %]">(auth cache updated [% duration(cache_age, 6) %] ago)</span></a>
            [% END; END %]
          </div>
        </td>
      </tr>
      <tr>
        <th class="align-top">Teams</th>
        <td>[% PROCESS _user_teams.tt %]</td>
      </tr>
      <tr>
        <th class="align-top">Effective Roles</th>
        <td>[% PROCESS _user_roles.tt %]</td>
      </tr>
      <tr class="hoverable">
        <th class="align-top">Can Submit Commands</th>
        <td>
          <div class="flexrow flex-nowrap gap-1 justify-between">
            <span>[% IF profile_user.can_submit_commands %]Yes[% ELSE %]No[% END %]</span>
            [% IF profile_user.defined("can_submit_commands_src"); %]<span class="textHINTsoft">reason: [% profile_user.can_submit_commands_src | html %]</span>[% END %]
          </div>
        </td>
      </tr>
      <tr>
        <th class="align-top">Contact Exists</th>
        <td>
          <div class="flexrow flex-nowrap gap-2">
            <div>
              [% IF profile_user.contact_src_peer.size > 0 %]
                <div>Yes</div>
                <div class="truncate max-w-[400px]">(backend: [% FOREACH peer_key IN profile_user.contact_src_peer %][% IF !loop.first %], [% END %]<span title="[% peer_key %]">[% peer_name(peer_key) %]</span>[% END %])</div>
              [% ELSE %]
                <div>No</div>
              [% END %]
            </div>
          </div>
        </td>
      </tr>
    </table>
  </div>


  <div class="head max-w-[900px]">
    <h3>Timezone</h3>
  </div>
  <div class="body max-w-[900px]">
    <table class="cellspacing w-full table-fixed">
      <tr>
        <th class="w-40 align-top">Set Timezone</th>
        <td>
          <form action="user.cgi" method="POST">
            <input type="submit" name="send" value="save" style="display:none"><!-- make enter submit the form -->
            <input type="hidden" name="CSRFtoken" value="[% get_user_token(c) %]">
            <input type="hidden" name="action" value="save">
            <div class="flexrow">
              <div class="grow">
                <select name="timezone" class="w-full">
                  [% FOR tz = timezones %]
                    <option value="[% tz.text | html %]"[% IF user_tz == tz.text %] selected[% END %]>[% tz.text | html %][% IF tz.text == "Server Setting" %]&nbsp;&nbsp;&nbsp;&nbsp;([% c.config._server_timezone %])[% END %]</option>
                  [%- END %]
                </select>
              </div>
              <div>
                <button onclick="setBtnSpinner(this);"><i class="uil uil-save"></i>Save changes</button>
              </div>
              <div class="min-w-[140px]">
                <span>Server: [% c.config._server_timezone %]</span><br>
                <span>Browser: <span id="browser_tz"></span></span>
              </div>
            </div>
          </form>
        </td>
      </tr>
    </table>
  </div>


  [% IF c.config.exists('use_feature_configtool') && c.config.use_feature_configtool && !c.config.disable_user_password_change %]
  <div class="head max-w-[900px]">
    <h3>Password</h3>
  </div>
  <div class="body max-w-[900px]">
    <table class="cellspacing w-full table-fixed">
    <tr>
      <th class="w-40">Change Password</th>
      <td>
        <a class="button w-fit" href="[% url_prefix %]cgi-bin/conf.cgi?action=user_password&referer=[% as_url_arg(short_uri(c, {referer => 'undef'})) %]"><i class="uil uil-key-skeleton"></i> Update password</a>
      </td>
    </tr>
    </table>
  </div>
  [% END %]

  <div class="head max-w-[900px]">
    <h3>Advanced Settings</h3>
  </div>
  <div class="body max-w-[900px]">
    <table class="cellspacing w-full table-fixed">
      <tr>
        <th class="w-40 align-top">Debug Profiles</th>
        <td>
          <div class="flexrow gap-1">
            <input type="radio" name="submit" value="0" id="profile_off" onClick="cookieSave('thruk_profiling', 0, 0); thruk_message(0, 'profiling disabled'); reloadPage();" [% IF !user_profiling %] checked[% END %]>
            <label for="profile_off" class="clickable mr-4">Off</label>

            <input type="radio" name="submit" value="1" id="profile_on" onClick="cookieSave('thruk_profiling', 1, 0); thruk_message(0, 'profiling enabled'); reloadPage();" [% IF user_profiling == 1 %] checked[% END %]>
            <label for="profile_on" class="clickable mr-4">On</label>

            <input type="radio" name="submit" value="2" id="profile_stack" onClick="cookieSave('thruk_profiling', 2, 0); thruk_message(0, 'profiling enabled with stacktraces'); reloadPage();" [% IF user_profiling == 2 %] checked[% END %]>
            <label for="profile_stack" class="clickable">Incl. Stacktrace</label>

            <span class="ml-10">(current browser session only)</span>
          </div>
        </td>
      </tr>
    </table>
  </div>

[% END %]
