%# BEGIN LICENSE BLOCK
%# 
%# Copyright (c) 1996-2002 Jesse Vincent <jesse@bestpractical.com>
%# 
%# (Except where explictly superceded by other copyright notices)
%# 
%# 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.
%# 
%# 
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%# 
%# 
%# END LICENSE BLOCK

<&| /Widgets/TitleBox,
    title => loc($Queue) .': '. $q,
    class => 'tickets-list-'. lc RT::IR::TicketType( Queue => $Queue ),
    titleright_raw => $box_actions,
&>
% if ( $lookup_cf_not_applies ) {
<i><% loc("Custom field '[_1]' doesn't applies to this queue", loc($LookupType) ) %></i>
% } else {
<& /RTIR/Search/Elements/ShowResults,
    Queue         => $Queue,
    BaseQuery     => RT::IR->Query( Queue => $Queue ),
    Query         => $Query,
    Format        => $Format,
    AllowSorting  => 0,
    EmptyLabel    => loc("(no $Queue)"),
&>
% }
</&>
<%INIT>
my $lookup_cf_not_applies = 0;
if ( $LookupType && RT::IR->CustomFields( Field => $LookupType )
    && !RT::IR->CustomFields( Field => $LookupType, Queue => $Queue )
) {
    $lookup_cf_not_applies = 1;
}

my $Format = RT->Config->Get('RTIRSearchResultFormats')->{'LookupTool'};
if ( $TicketObj ) {
    my $type = RT::IR::TicketType( Ticket => $TicketObj );

    my @show;
    push @show, 'link' if ($Queue eq 'Incidents' && $type ne 'Incident')
        || ($Queue ne 'Incidents' && $type eq 'Incident');
    push @show, 'merge' if $Queue eq $TicketObj->QueueObj->Name;

    my $column = $Queue eq 'Incidents'? 'Incident' : 'Children';
    $Format .= ", '__LookupTool${column}Actions.{". join(',', $TicketObj->id, @show ) ."}__'";
}

my @box_actions;
push @box_actions, {
    title => loc('Search'),
    path => "/RTIR/Search/Refine.html?". $m->comp('/Elements/QueryString', 
        Queue => $Queue,
        Query => $Query,
    ),
};
if ( $TicketObj && RT::IR::TicketType( Ticket => $TicketObj ) eq 'Incident'
    && $Queue ne 'Incidents'
) {
    push @box_actions, {
        title => loc('Link'),
        path => "/RTIR/Link/ToIncident/?". $m->comp('/Elements/QueryString', 
            id => $TicketObj->id,
            Queue => $Queue,
            Query => $Query,
        ),
    };
    if ($Queue eq 'Investigations' && $LookupType eq 'email') {
        push @box_actions, {
            title => loc('Launch'),
            path => "/RTIR/Create.html?". $m->comp('/Elements/QueryString',
                Incident => $TicketObj->id,
                Queue => $Queue,
                Requestors => $q,
            ),
        };
    } elsif ( $Queue eq 'Blocks' && $LookupType eq 'ip' && !RT->Config->Get('RTIR_DisableBlocksQueue') ) {
        push @box_actions, {
            title => loc('Create'),
            path => "/RTIR/Create.html?". $m->comp('/Elements/QueryString',
                Incident => $TicketObj->id,
                Queue => $Queue,
                'IP-Value' => $q,
            ),
        };
    }
}
elsif ( $TicketObj && RT::IR::TicketType( Ticket => $TicketObj ) ne 'Incident'
    && $Queue eq 'Incidents'
) {
    push @box_actions, {
        title => loc('Create'),
        path => "/RTIR/Create.html?". $m->comp('/Elements/QueryString',
            Child => $TicketObj->id,
            Queue => $Queue,
        ),
    };
}
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>

<%ARGS>
$Query => undef
$Queue => undef
$TicketObj => undef

$q => undef
$LookupType => undef
</%ARGS>
