%# BEGIN BPS TAGGED BLOCK {{{
%#
%# COPYRIGHT:
%#
%# This software is Copyright (c) 1996-2026 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 }}}
<%args>
$Ticket => undef
$id => undef
$ShowCompleted => 0
$Edit => 0
$ShowSave => 1
</%args>
<%init>

$Ticket = LoadTicket($id) if ($id);
my $resolve_status = $Ticket->LifecycleObj->ReminderStatusOnResolve;

my $count_reminders = RT::Reminders->new($session{'CurrentUser'});
$count_reminders->Ticket($Ticket->id);
my $count_tickets = $count_reminders->Collection;
if (!$ShowCompleted) {
    # XXX: don't break encapsulation if we can avoid it
    $count_tickets->FromSQL(q{Type = "reminder" AND RefersTo = "} .  $Ticket->id . qq{" AND Status != "$resolve_status" });
}
my $has_reminders = $count_tickets->Count;

# We've made changes, let's reload our search
my $reminder_collection = $count_reminders->Collection;
</%init>
<input type="hidden" class="hidden" name="id" value="<% $Ticket->id %>" />
<input type="hidden" class="hidden" name="update-reminders" value="1" />
% my $editable = 0;
% if ($has_reminders) {
<div class="row reminder-headers p-2">
% if ( $Edit ) {
  <h5><&|/l&>Current Reminders</&></h5>
% } else {
  <div class="col-4">
    <&|/l&>Reminder</&>
  </div>
  <div class="col-4">
    <&|/l&>Due</&>
  </div>
  <div class="col-4">
    <&|/l&>Owner</&>
  </div>
% }
</div>
% my $i = 0;
% while ( my $reminder = $reminder_collection->Next ) {
<div class="row">
% $i++;
% if ( $reminder->Status eq $resolve_status && !$ShowCompleted ) {
  <input type="hidden" class="hidden" name="Complete-Reminder-<% $reminder->id %>" value="1" />
% $i++;
% }
% else {
%   $editable = 1 if !$editable && $reminder->CurrentUserHasRight( 'ModifyTicket' );
%   if ($Edit) {
<& SELF:EditEntry, Reminder => $reminder, Ticket => $Ticket, Index => $i &>
%   } else {
<& SELF:ShowEntry, Reminder => $reminder, Ticket => $Ticket, Index => $i &>
%   }
% }
</div>
% }
% if ( $editable ) {
<div class="row">
  <i class="mt-2 ms-2"><&|/l&>(Check box to complete)</&></i>
</div>
% }
<hr class="mt-2 mb-2">
% } else {

%# we must always include resolved reminders due to the browser
%# checkbox-with-false-value issue
% while ( my $reminder = $reminder_collection->Next ) {
% if ( $reminder->Status eq $resolve_status && !$ShowCompleted ) {
<input type="hidden" class="hidden" name="Complete-Reminder-<% $reminder->id %>" value="1" />
% }
% }
% }

% if (lc $Ticket->Status ne "deleted" and $Ticket->QueueObj->CurrentUserHasRight('CreateTicket') and $Ticket->CurrentUserHasRight('ModifyTicket') ) {
<& SELF:NewReminder, Ticket => $Ticket &>
% $editable = 1;
% }

% if ( $editable && $ShowSave ) {
<& /Elements/Submit, Name => 'SaveReminder', Label => loc('Save'), FullWidth => 1 &>
% }
<%method NewReminder>
<%args>
$Ticket
</%args>
<div class="row mt-2">
  <div class="col">
    <h5><&|/l&>New reminder</&></h5>
    <div class="row mt-2">
      <div class="col-12">
        <&| /Elements/LabeledValue, Label => loc("Subject"), LabelFor => "NewReminder-Subject", ReadOnly => 0 &>
          <input type="text" class="form-control reminder-subject" name="NewReminder-Subject" id="NewReminder-Subject" placeholder="" />
        </&>
      </div>
    </div>
    <div class="row mt-2">
      <div class="col-6">
        <&| /Elements/LabeledValue, Label => loc("Owner"), LabelFor => "NewReminder-Owner", ReadOnly => 0 &>
          <& /Elements/SelectOwner, Name => 'NewReminder-Owner', QueueObj => $Ticket->QueueObj, Default=>$session{'CurrentUser'}->id, DefaultValue => 0 &>
        </&>
      </div>
      <div class="col-6">
        <&| /Elements/LabeledValue, Label => loc("Due"), LabelFor => "NewReminder-Due", ReadOnly => 0 &>
          <& /Elements/SelectDate, Name => "NewReminder-Due", Default => "" &>
        </&>
      </div>
    </div>
  </div>
</div>
</%method>
<%method EditEntry>
<%args>
$Reminder
$Ticket
$Index
</%args>

  <div class="col-12 <% $Index%2 ? 'oddline' : 'evenline' %>" id="reminder-<% $Reminder->id %>">
% unless ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
      <input class="form-check-input" name="Complete-Reminder-<% $Reminder->id %>" type="hidden"
        value=<% $Reminder->Status eq $Reminder->LifecycleObj->ReminderStatusOnResolve ? 1 : 0 %>
      />
% }
    <div class="row pb-2 pt-2">
      <div class="col-1"> <!-- Column for complete checkbox -->
        <div>
          <input class="form-check-input reminder-complete" type="checkbox" value="1" id="Complete-Reminder-<% $Reminder->id %>" name="Complete-Reminder-<% $Reminder->id %>" <% $Reminder->Status eq $Reminder->LifecycleObj->ReminderStatusOnResolve ? 'checked="checked"' : '' |n %>
% unless ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
disabled="disabled"
% }
          />
        </div>
      </div>
      <div class="col-10"> <!-- Column for remaining form content -->
        <&| /Elements/LabeledValue, Label => loc("Subject"), LabelFor => "Reminder-Subject-<% $Reminder->id %>", ReadOnly => 0 &>
          <input id="Reminder-Subject-<% $Reminder->id %>" type="text" class="reminder-subject form-control" placeholder="" name="Reminder-Subject-<% $Reminder->id %>" value="<% $Reminder->Subject %>"
% unless ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
readonly="readonly"
% }
          />
        </&>
        <div class="row">
        <div class="col-6">
        <&| /Elements/LabeledValue, Label => loc("Owner"), LabelFor => "Reminder-Owner-<% $Reminder->id %>", ReadOnly => 0 &>
          <& /Elements/SelectOwner, Name => 'Reminder-Owner-'.$Reminder->id, QueueObj => $Ticket->QueueObj, Default => $Reminder->Owner, DefaultValue => 0  &>
        </&>
        </div>
        <div class="col-6">
        <&| /Elements/LabeledValue, Label => loc("Due"), LabelFor => "Reminder-Due-<% $Reminder->id %>", FormText => $Reminder->DueObj->AsString, ReadOnly => 0 &>
% if ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
                <& /Elements/SelectDate, Name => 'Reminder-Due-'.$Reminder->id, Default => $Reminder->DueObj->Unix ?  $Reminder->DueObj->ISO(Timezone => 'user') : '' &>
% }
        </&>
        </div>
        </div>
      </div> <!-- End column for remaining form content -->
    </div>
  </div>
</%method>
<%method ShowEntry>
<%args>
$Reminder
$Ticket
$Index
</%args>
% my $dueobj = $Reminder->DueObj;
% my $overdue = $dueobj->IsSet && $dueobj->Diff < 0 ? 1 : 0;

<div class="col-12 <% $Index%2 ? 'oddline' : 'evenline' %>" id="reminder-<% $Reminder->id %>">
  <div class="row mt-2 m-0 pb-2 pt-2">
% unless ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
    <div class="col-4">
      <input name="Complete-Reminder-<% $Reminder->id %>" type="hidden"
        value=<% $Reminder->Status eq $Reminder->LifecycleObj->ReminderStatusOnResolve ? 1 : 0 %>
      />
    </div>
% }
    <div class="col-4">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" value="1" id="Complete-Reminder-<% $Reminder->id %>" name="Complete-Reminder-<% $Reminder->id %>" <% $Reminder->Status eq $Reminder->LifecycleObj->ReminderStatusOnResolve ? 'checked="checked"' : '' |n %>
% unless ( $Reminder->CurrentUserHasRight('ModifyTicket') ) {
          disabled="disabled"
% }
        />
        <label class="form-check-label" for="Complete-Reminder-<% $Reminder->id %>"><% $Reminder->Subject %></label>
      </div>
    </div>

    <div class="col-4">
      <% $overdue ? '<span class="overdue">' : '' |n %><% $dueobj->AgeAsString || loc('Not set') %><% $overdue ? '</span>' : '' |n %>
    </div>
    <div class="col-4">
      <& /Elements/ShowUser, User => $Reminder->OwnerObj &>
    </div>
  </div>
</div>
</%method>

<%attr>
directly_accessible => 1
</%attr>
