<&| /Widgets/TitleBox, title => loc("Attach Reports") &>
<& /Elements/TicketList,
    Collection     => $siblings,
    DisplayFormat  => "__CheckBox.{$Name}__, $Format",
    Format         => $Format,
    ShowHeader     => 1,
    ShowNavigation => 0,
&>
</&>
<%ARGS>
$Ticket => undef
$Name   => 'AttachTickets'
</%ARGS>
<%INIT>
my @Ticket = grep defined, ref($Ticket) eq 'ARRAY'? @$Ticket : $Ticket;
return unless @Ticket;

my @parents;
foreach my $e ( @Ticket ) {
    if ( RT::IR::TicketType( Ticket => $e ) eq 'Incident' ) {
        push @parents, $e->id;
    } else {
        push @parents, map $_->id, @{ RT::IR->Incidents( $e )->ItemsArrayRef || [] };
    }
}
return unless @parents;

my $siblings = RT::Tickets->new( $Ticket[0]->CurrentUser );
$siblings->FromSQL( RT::IR->Query(
    Queue    => 'Incident Reports',
    MemberOf => \@parents,
    Exclude  => \@Ticket,
) );
$siblings->_DoSearch;
return unless $siblings->Count;

my $Format = q{
    '<b><a HREF="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></b>/TITLE:#',
    '<b><a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></b>/TITLE:Subject',
    '__Status__',
    __LastUpdatedRelative__, __CreatedRelative__
};
</%INIT>
