<&| /Widgets/TitleBox, 
    title       => loc( $Queue ),
    title_href  => RT->Config->Get('WebPath') ."/RTIR/Incident/Children/?Queue=". $EscapedQueue ."&id=".$id,
    titleright_raw => $box_actions,
    class => 'tickets-list-'. lc(RT::IR::TicketType( Queue => $Queue )),
&>

<& /RTIR/Elements/ShowChildren,
    Ticket           => $IncidentObj, 
    Queue            => $Queue,
    Rows             => $Rows,
    Statuses         => \@active_statuses,
    NoTicketsCaption => loc('No active [_1]', loc( $Queue )),
&>
% if ( $active->CountAll < $Rows ) {
<& /RTIR/Elements/ShowChildren,
    Ticket           => $IncidentObj,
    Queue            => $Queue,
    Rows             => $Rows - $active->CountAll,
    Statuses         => \@inactive_statuses,
    NoTicketsCaption => loc('No inactive [_1]', loc( $Queue )),
&>
% }
</&>

<%ARGS>
$IncidentObj
$Queue

$OrderBy => 'Due'

$Rows  => 8
</%ARGS>
<%INIT>
return if $Queue eq 'Blocks' && RT->Config->Get('RTIR_DisableBlocksQueue');

my $id = $IncidentObj->id;
my $EscapedQueue = $m->interp->apply_escapes( $Queue, 'u' );

my @active_statuses = RT::IR->Statuses( Queue => $Queue );
my @inactive_statuses = RT::IR->Statuses( Queue => $Queue, Initial => 0, Active => 0, Inactive => 1 );

my $active = RT::Tickets->new( $session{'CurrentUser'} );
$active->FromSQL( RT::IR->Query(
    Queue    => $Queue,
    MemberOf => $IncidentObj,
    Status   => \@active_statuses,
));

my $inactive = RT::Tickets->new( $session{'CurrentUser'} );
$inactive->FromSQL( RT::IR->Query(
    Queue    => $Queue,
    MemberOf => $IncidentObj,
    Status   => \@inactive_statuses,
));

my $total_count = $active->CountAll + $inactive->CountAll;

my $QueueObj = RT::Queue->new($session{CurrentUser});
$QueueObj->Load($Queue);

my @box_actions;
if ( $IncidentObj->CurrentUserHasRight('ModifyTicket') ) {
    if ( $QueueObj->Id and $QueueObj->CurrentUserHasRight('CreateTicket') ) {
        push @box_actions, {
            title => $QueueObj->Name ne 'Investigations'? loc('Create') : loc('Launch'),
            path => "/RTIR/Create.html?Incident=$id&Queue=$EscapedQueue",
        };
    }
    push @box_actions, {
        title => loc('Link'),
        path  => "/RTIR/Link/FromIncident/?id=$id&Queue=$EscapedQueue",
    };
}

if ( $total_count > $Rows ) {
    push @box_actions, {
        title => loc("More... ([_1] total)", $total_count),
        path => '/RTIR/Incident/Children/?Queue='. $EscapedQueue .'&id='. $id
    };
}
my $box_actions = join '&nbsp;'x3,
    map qq{<a href="}. RT->Config->Get('WebPath') . $_->{'path'} .q{">}
        . $m->interp->apply_escapes( $_->{title}, 'h' ) . q{</a>},
    @box_actions;

</%INIT>
