[% PROCESS _header.tt %]
[% PROCESS _message.tt %]

  [% PROCESS _infobox.tt %]

  <h1 class="mt-5">Broadcasts</h1>

  <div class="card w-full min-w-[420px] mt-2">
    <div class="head justify-between">
      <div>
        [% PROCESS _table_search_field.tt ids=["statusTable"] %]
      </div>
      <div class="flex justify-end">
        <a href="broadcast.cgi?action=edit&amp;id=new" class="button green">Create broadcast</a>
      </div>
    </div>

    <div class="mainTable [% IF main_table_full %]fullsize[% END %] border-t-0">
      <table class="mainTable striped" id="statusTable">
        <thead>
          <tr>
            <th>Name</th>
            <th>Author</th>
            <th class="text-center">Hide Before</th>
            <th class="text-center">Expires After</th>
            <th class="text-center">Public</th>
            <th>Contacts</th>
            <th>Contactgroups</th>
            <th class="text-center">Actions</th>
          </tr>
        </thead>
        <tbody>
          [% IF all_broadcasts.size == 0 %]
          <tr>
            <td colspan="8" class="textALERT text-center">No broadcasts defined</td>
          </tr>
          [% ELSE %]
            [% FOREACH b = all_broadcasts %]
              <tr>
                <td>
                  <a href="broadcast.cgi?id=[% b.basefile | uri %]&amp;action=edit">
                    [% IF b.name %]
                      [% b.name | html %]
                    [% ELSE %]
                      [% b.raw_text.split('<br>').0.substr(0, 100) | html %]
                    [% END %]
                    [% IF b.template %]<span class="textALERT">(TEMPLATE)</span>[% END %]
                  </a>
                </td>
                <td>[% b.author %]</td>
                <td class="text-center">[% IF b.hide_before_ts > 0; date_format(c, b.hide_before_ts); END %]</td>
                <td class="text-center">[% IF b.expires_ts > 0; date_format(c, b.expires_ts); END %]</td>
                <td class="text-center">[% IF b.loginpage %]Yes[% END %]</td>
                <td class="max-w-sm truncate">[% b.contacts.join(', ') | html %]</td>
                <td class="max-w-sm truncate">[% b.contactgroups.join(', ') | html %]</td>
                <td>
                  <div class="flex gap-1 justify-center">
                    <a href="broadcast.cgi?id=[% b.basefile | uri %]&amp;action=clone">
                      <i class="fa-solid fa-copy small" title='Clone Broadcast'></i>
                    </a>
                    <a href="broadcast.cgi?id=[% b.basefile | uri %]&amp;action=edit">
                      <i class="fa-solid fa-pencil small" title='Edit Broadcast'></i>
                    </a>
                    <form action="broadcast.cgi" method="POST">
                      <input type="hidden" name="id" value="[% b.basefile | html %]">
                      <input type="hidden" name="action" value="delete">
                      <input type="hidden" name="CSRFtoken" value="[% get_user_token(c) %]">
                      <button type="submit" onclick="return confirm('Do you really want to delete this broadcast?')" title="Delete broadcast" class="iconOnly">
                        <i class="fa-solid fa-trash small"></i>
                      </button>
                    </form>
                  </div>
                </td>
              </tr>
            [% END %]
          [% END %]
        </tbody>
      </table>
    </div>

    <div class="mainTableFooter">
      <div class="flex-1 self-center">
        [% PROCESS _pager_total_items.tt pager = { total_items => all_broadcasts.size } data=all_broadcasts %]
      </div>
    </div>
  </div>

<script>
<!--
  jQuery(document).ready(function() {
    table_search("table_search_input", ["statusTable"], 1);
  });
-->
</script>

[% PROCESS _footer.tt %]
