%# 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 }}}
      <form action="<% RT::IR->HREFTo('Create.html') %>" id="CreateInQueue">
% if ($Incident) {
        <input type="hidden" name="Incident" value="<%$Incident%>"/>
% }
% if ($Child) {
        <input type="hidden" name="Child" value="<%$Child%>"/>
% }
        <div class="form-row">
          <div class="col-12 text-center">
            <&|/l, $ticket_type &>Create a new [_1] in the queue</&>:
              <div class="d-inline-block">
                <& /RTIR/Elements/SelectRTIRQueue,
                    Name => 'Queue',
                    Lifecycle => $Lifecycle,
                    ShowNullOption => 0,
                    ShowAll => 0,
                    LimitToConstituency => $limit_to_constituency,
                    Constituency => $m->{'RTIR_ConstituencyFilter'} || $linked_constituency
                &>
              </div>
            </div>
          </div>
        <div class="form-row">
          <div class="col-12">
            <& /Elements/Submit, Label => loc("Go"), Caption => loc("This will take you to a partially prefilled [_1] creation form.", $ticket_type) &>
          </div>
        </div>
      </form>
<%INIT>
$Lifecycle = $Lifecycle->[0] if (ref $Lifecycle eq 'ARRAY');

my ($linked_ticket, $linked_constituency);

if ($Incident) {
    $linked_ticket = RT::Ticket->new( $session{CurrentUser} );
    $linked_ticket->Load($Incident);
}

if ($Child) {
    $linked_ticket = RT::Ticket->new( $session{CurrentUser} );
    $linked_ticket->Load($Child);
}

if ($linked_ticket && $linked_ticket->id) {
    $linked_constituency = RT::IR->ConstituencyFor($linked_ticket);
}

my $limit_to_constituency =
    # Limit no matter what if we have a filter
    $m->{'RTIR_ConstituencyFilter'} ||
    # Also limit if we have a linked constituency and StrictConstituencyLinking is set
    (RT::IR->StrictConstituencyLinking && $linked_constituency)
    ? 1:0;

$ticket_type = lc $ticket_type;
</%INIT>
<%ARGS>
$Lifecycle
$Incident => undef
$Child => undef
$ticket_type => undef
</%ARGS>
