[% WRAPPER _conf_objects_frame.tt %]
[% PROCESS _blocks.tt %]

  [% IF force_delete %]
    <form action="conf.cgi" method="POST">
  [% END %]

  <div class="card w-[800px]">
    <div class="head justify-between">
      <div class="w-20">
        <a class="button header-button" href='conf.cgi?sub=objects&amp;type=[% object.get_type() %]&amp;data.id=[% object.get_id %]'>
          <i class="uil uil-angle-double-left"></i>Back
        </a>
      </div>
      <h3>References for [% object.get_type() | ucfirst +%] [%+ object.get_name() %]</h3>
      <div class="w-[70px]"></div>
    </div>
    <table class="body cellspacing">
      [% IF force_delete %]
        <tr>
          <td colspan=3>
            [% PROCESS _button btn = {
              skipform => 1,
              data     => { sub => 'objects', 'data.id' => object.get_id(), force => 1, action => "delete", CSRFtoken => get_user_token(c) },
              button   => { class => 'mx-auto my-5 hover-red', html => "<i class='uil uil-trash-alt'></\i> Remove this " _ object.get_type().ucfirst _ " along with all selected references" },
            }%]
          </td>
        </tr>
      [% END %]
      [% IF show_incoming %]
        <tr>
          <th class='text-center pt-2 border-t borderDefault' colspan=3><h4><i class="fa-solid fa-arrow-right-to-bracket mr-1"></i>Incoming references</h4></th>
        </tr>
        [% FOREACH t = incoming.keys.sort %]
          [% first = 1 %]
            [% FOREACH inc_ref = sort_by(incoming.$t, "name") %]
            <tr>
              <th class="align-top">[% IF first %][% t | ucfirst %][% END %]</th>
              [% IF force_delete %]
                <td class="hoverable clickable" onclick="toggleCheckBox(jQuery(this).children('input[type=checkbox]').first()); jQuery('input[name=none]').prop('checked', false); return false;">
                  <input type="checkbox" name="ref" value="[% inc_ref.id %]" [% IF inc_ref.readonly %]disabled[% ELSE %]checked[% END %]>
                  [% inc_ref.name | html %]
                </td>
              [% ELSE %]
                <td><a class="link" href="conf.cgi?sub=objects&amp;data.id=[% inc_ref.id %]">[% inc_ref.name | html %]</a></td>
              [% END %]
              <td class="w-full">
                <a href="conf.cgi?sub=objects&amp;data.id=[% inc_ref.id %]" class="link">
                  <i class="fa-solid fa-link small"></i>
                  [% IF inc_ref.line %][% inc_ref.file.replace(files_root, ".../") %]:[% inc_ref.line %][% END %]
                </a>
                [% IF inc_ref.readonly %] <span class="textHINT"> (read-only)</span>[% END %]
              </td>
            </tr>
            [% first = 0 %]
          [% END %]
        [% END %]
        [% IF force_delete %]
          <tr>
            <td></td>
            <td>
              <div class="flexrow gap-1 flex-nowrap">
                <a class="button w-20" href="#" onclick="jQuery('input[name=ref]').not(':disabled').prop('checked', false); jQuery('input[name=none]').prop('checked', true); jQuery('input[name=all]').prop('checked', false); return false;">
                  <input class="mr-1" type="checkbox" name="none" value="">
                  none
                </a>
                <a class="button w-20" href="#" onclick="jQuery('input[name=ref]').not(':disabled').prop('checked', true); jQuery('input[name=none]').prop('checked', false); jQuery('input[name=all]').prop('checked', true); return false;">
                  <input class="mr-1" type="checkbox" name="all" value="" checked>
                  all
                </a>
              </div>
            </td>
          </tr>
        [% END %]
        [% IF incoming.keys.size == 0 %]
          <tr>
            <td colspan=3 class="text-center textHINT">No incoming references found</td>
          </tr>
        [% END %]
      [% END %]

      [% IF show_outgoing %]
        [% IF !force_delete %]
          <tr>
            <th class="text-center pt-2 border-t borderDefault" colspan=3><h4><i class="fa-solid fa-right-from-bracket mr-1"></i>Outgoing references</h4></th>
          </tr>
          [% FOREACH t = outgoing.keys.sort %]
            <tr>
              <th class="align-top">[% t | ucfirst | html %]</th>
              <td>
                <ul>
                [% FOREACH name = outgoing.$t.keys.sort %]
                  <li><a class="link" href="conf.cgi?sub=objects&amp;type=[% t | uri %]&amp;data.name=[% name | uri %]">[% name | html %]</a></li>
                [% END %]
                </ul>
              </td>
              <td class="w-full">
              </td>
            </tr>
          [% END %]
          [% IF outgoing.keys.size == 0 %]
            <tr>
              <td colspan=3 class="text-center textHINT">No outgoing references found</td>
            </tr>
          [% END %]
        [% END %]
      [% END %]


      [% IF other_refs.keys.size > 0 %]
        <tr>
          <th class="text-center pt-2 border-t borderDefault" colspan=3><h4><i class="fa-solid fa-arrow-turn-down mr-1"></i>Outside references</h4></th>
        </tr>
        [% IF force_delete %]
          <tr>
            <td colspan=3 class="text-center textHINT"><i class="fa-solid fa-exclamation round small yellow"></i> These references should be checked manually.</td>
          </tr>
        [% END %]
        [% IF show_renamed %]
          <tr>
            <td colspan=3 class="text-center textHINT pt-3">The [% object.get_type() | ucfirst +%] has been renamed, please manually check references.</td>
          </tr>
          <tr>
            <td style="text-align:center" colspan=3>
              <br>
              [% PROCESS _button btn = {
                form   => { action => 'conf.cgi', method => 'GET' },
                data   => { sub => 'objects', 'data.id' => object.get_id() },
                button => { class => '', text => "Continue editing " _ object.get_type().ucfirst },
              }%]
              <br>
              <br>
            </td>
          </tr>
        [% END %]
        [% FOREACH t = other_refs.keys.sort %]
          <tr>
            <th>[% t | html %]</th>
            <td>
              <ul>
              [% FOREACH r = other_refs.$t %]
                <li><a class="link" href="[% r.link %]" target="_blank"><i class="uil uil-external-link-alt text-sm"></i> [% r.name | html %] ([% r.details | html %])</a></li>
              [% END %]
              </ul>
            </td>
          </tr>
        [% END %]
      [% END %]
    </table>
  </div>

  [% IF force_delete %]
    </form>
  [% END %]

[% END %]
