%# BEGIN BPS TAGGED BLOCK {{{
%#
%# COPYRIGHT:
%#
%# This software is Copyright (c) 1996-2024 Best Practical Solutions, LLC
%#                                          <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
%#
%#
%# LICENSE:
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
%#
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%#
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
<div class="modal search-results-filter">
  <div class="modal-dialog <% $Attribute eq 'Owner' ? '' : 'modal-dialog-scrollable' %> <% $modal_class %>" role="document">
    <form name="search-results-filter">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title"><&|/l&>Filter Results</&></h5>
          <a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">
%       if ( $Attribute eq 'Subject' ) {
          <div class="form-row">
            <div class="label col-3">
                <&|/l&>Subject</&>:
            </div>
            <div class="value col-9">
                <input class="form-control" name="Subject" value="<% $filter->{Subject} // '' %>" />
            </div>
          </div>
%       } elsif ( $Attribute eq 'Status' ) {
          <div class="form-row">
            <div class="label col-3">
                <&|/l&>Status</&>:
            </div>
            <div class="value col-9">
              <ul class="list-group list-group-compact">
%           for my $status ( sort { lc $a cmp lc $b } keys %$status  ) {
                <li class="list-group-item">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" id="Status-<% $status %>" name="Status" class="custom-control-input" value="<% $status %>" <% $filter->{Status}{$status} ? 'checked="checked"' : '' |n %> />
                    <label class="custom-control-label" for="Status-<% $status %>"><% $status %></label>
                  </div>
                </li>
%           }
              </ul>
            </div>
          </div>
%       } elsif ( $Attribute eq 'Queue' ) {
          <div class="form-row">
            <div class="label col-3">
                <&|/l&>Queue</&>:
            </div>
            <div class="value col-9">
              <ul class="list-group list-group-compact">
%             for my $queue ( sort { lc $a->Name cmp lc $b->Name } @$queues ) {
                <li class="list-group-item">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" id="Queue-<% $queue->Id %>" name="Queue" class="custom-control-input" value="<% $queue->Id %>" <% $filter->{Queue}{$queue->Id} ? 'checked="checked"' : '' |n %> />
                    <label class="custom-control-label" for="Queue-<% $queue->Id %>"><% $queue->Name %></label>
                  </div>
                </li>
%             }
              </ul>
            </div>
          </div>
%       } elsif ( $Attribute eq 'Owner' ) {
          <div class="form-row">
            <div class="label col-3">
              <&|/l&>Owner</&>:
            </div>
            <div class="value col-9">
              <& /Elements/SelectOwner, Name => 'Owner', Default => $filter->{Owner}, Size => 6 &>
            </div>
          </div>
%       } elsif ( $Attribute eq 'SLA' ) {
          <div class="form-row">
            <div class="label col-3">
              <&|/l&>SLA</&>:
            </div>
            <div class="value col-9">
              <ul class="list-group list-group-compact">
%             for my $sla ( sort( keys %{RT->Config->Get('ServiceAgreements')->{'Levels'}} ), 'NULL'  ) {
                <li class="list-group-item">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" class="custom-control-input checkbox" id="SLA_<% $sla %>" name="SLA" value="<% $sla %>" <% $filter->{SLA}{$sla} ? 'checked="checked"' : '' |n %> />
                      <label class="custom-control-label" for="SLA_<% $sla %>"><% $sla eq 'NULL' ? loc('(no value)') : $sla %></label>
                  </div>
                </li>
%             }
              </ul>
            </div>
          </div>
%       } elsif ( $Attribute =~ /^(?:Creator|LastUpdatedBy)$/) {
          <div class="form-row">
            <div class="label col-3">
              <% loc(join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-9">
              <input class="form-control" data-autocomplete="Users" name="<% $Attribute %>" value="<% $filter->{$Attribute} %>" data-autocomplete-return="Name" />
            </div>
          </div>
%       } elsif ( $Attribute eq 'Type' ) {
          <div class="form-row">
            <div class="label col-3">
                <&|/l&>Type</&>:
            </div>
            <div class="value col-9">
              <ul class="list-group list-group-compact">
%           for my $type ( qw/approval reminder ticket/ ) {
                <li class="list-group-item">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" id="Type-<% $type %>" name="Type" class="custom-control-input" value="<% $type %>" <% $filter->{Type}{$type} ? 'checked="checked"' : '' |n %> />
                    <label class="custom-control-label" for="Type-<% $type %>"><% $type %></label>
                  </div>
                </li>
%           }
              </ul>
            </div>
          </div>
%       } elsif ( $Attribute =~ /(?:Initial|Final)?Priority/ ) {
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] equal to', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectPriority, Name => "${Attribute}EqualTo", Default => $filter->{$Attribute}{'='}, Queues => { map { $_->Id => 1 } @$queues }, ValueAsString => 1, ShowEmptyOption => 1 &>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] greater than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectPriority, Name => "${Attribute}GreaterThan", Default => $filter->{$Attribute}{'>'}, Queues => { map { $_->Id => 1 } @$queues }, ValueAsString => 1, ShowEmptyOption => 1 &>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] less than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectPriority, Name => "${Attribute}LessThan", Default => $filter->{$Attribute}{'<'}, Queues => { map { $_->Id => 1 } @$queues }, ValueAsString => 1, ShowEmptyOption => 1 &>
            </div>
          </div>
%       } elsif ( $Attribute eq 'id' ) {
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] equal to', $Attribute) %>:
            </div>
            <div class="value col-6">
              <input type="text" class="form-control" name="<% $Attribute %>EqualTo" size="5" value="<% $filter->{$Attribute}{'='} %>" />
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] greater than', $Attribute) %>:
            </div>
            <div class="value col-6">
              <input type="text" class="form-control" name="<% $Attribute %>GreaterThan" size="5" value="<% $filter->{$Attribute}{'>'} %>" />
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] less than', $Attribute) %>:
            </div>
            <div class="value col-6">
              <input type="text" class="form-control" name="<% $Attribute %>LessThan" size="5" value="<% $filter->{$Attribute}{'<'} %>" />
            </div>
          </div>
%       } elsif ( $Attribute =~ /^(?:Told|Starts|Started|Due|Resolved|Created|LastUpdated)/ ) {
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] equal to', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectDate, Name => "${Attribute}EqualTo", Default => $filter->{$Attribute}{'='} || '', ShowTime => 0 &>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] greater than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectDate, Name => "${Attribute}GreaterThan", Default => $filter->{$Attribute}{'>'} || '', ShowTime => 0 &>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] less than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <& /Elements/SelectDate, Name => "${Attribute}LessThan", Default => $filter->{$Attribute}{'<'} || '', ShowTime => 0 &>
            </div>
          </div>
%       } elsif ( $Attribute =~ /^Time/ ) {
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] equal to', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <div class="d-inline-block">
                <input type="text" class="form-control" name="<% $Attribute %>EqualTo" size="5" value="<% $filter->{$Attribute}{'='} %>" />
              </div>
              <&|/l&>Minutes</&>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] greater than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <div class="d-inline-block">
                <input type="text" class="form-control" name="<% $Attribute %>GreaterThan" size="5" value="<% $filter->{$Attribute}{'>'} %>" />
              </div>
              <&|/l&>Minutes</&>
            </div>
          </div>
          <div class="form-row">
            <div class="label col-6">
              <% loc('[_1] less than', join ' ', split /(?=[A-Z])/, $Attribute) %>:
            </div>
            <div class="value col-6">
              <div class="d-inline-block">
                <input type="text" class="form-control" name="<% $Attribute %>LessThan" size="5" value="<% $filter->{$Attribute}{'<'} %>" />
              </div>
              <&|/l&>Minutes</&>
            </div>
          </div>
%       } elsif ( $Attribute =~ /^(Requestor|Cc|AdminCc)s?$/) {
%         my $name = $1;
          <div class="form-row">
            <div class="label col-4">
              <% loc($name) %>:
            </div>
            <div class="value col-8">
              <input class="form-control" data-autocomplete="Users" name="<% $name %>" value="<% $filter->{$name} %>" />
            </div>
          </div>
%       } elsif ( $Attribute =~ /^CustomRole\.\{(.+)\}$/) {
%         my $name = $1;
          <div class="form-row">
            <div class="label col-4">
              <% loc($name) %>:
            </div>
            <div class="value col-8">
              <input class="form-control" data-autocomplete="Users" name="<% $Attribute %>" value="<% $filter->{$Attribute} %>" />
            </div>
          </div>
%       } elsif ( $Attribute =~ /^CustomField\.\{(.+)\}$/) {
%         my $name = $1;
%         my $cf = RT::CustomField->new($session{CurrentUser});
%         $cf->Load($name);
          <div class="form-row">
            <div class="label col-4">
              <% loc($name) %>:
            </div>
            <div class="value col-8">
%           if ( $cf->Type eq 'Select' ) {
%             my $cfvs = $cf->Values;
              <ul class="list-group list-group-compact">
%             while ( my $cfv = $cfvs->Next ) {
                <li class="list-group-item">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" class="custom-control-input checkbox" id="<% $name . '_' . $cfv->Name %>" name="<% $Attribute %>" value="<% $cfv->Name %>" <% $filter->{$Attribute}{$cfv->Name} ? 'checked="checked"' : '' |n %> />
                    <label class="custom-control-label" for="<% $name . '_' . $cfv->Name %>"><% $cfv->Name %></label>
                  </div>
                </li>
%             }
              </ul>
%           } else {
              <input type="text" class="form-control" name="<% $Attribute %>" size="5" value="<% $filter->{$Attribute} %>" />
%           }
            </div>
          </div>
%       }

        </div>
        <div class="modal-footer">
          <div class="form-row justify-content-end">
            <div class="col-auto">
              <input type="button" class="button btn btn-primary" data-dismiss="modal" name="Apply" value="<% loc('Cancel') %>" />
            </div>
            <div class="col-auto">
              <input type="button" class="button btn btn-primary" onclick="filterSearchResults('RT::Tickets')" name="Apply" value="<% loc('Apply') %>" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<%INIT>
return unless $ARGS{Query};

my $status = $FilterData{status};
my $queues = $FilterData{queues};
my $filter = $FilterData{filter};

my $modal_class;
if ( $Attribute =~ /^(?:Time|(?:Initial|Final)Priority|Created|LastUpdated)/ ) {
    $modal_class = 'modal-md';
}
else {
    $modal_class = 'modal-sm';
}
</%INIT>

<%ARGS>
$Attribute => ''
%FilterData => ()
</%ARGS>
