<div class="status-menus">
% for my $status (keys %menus) {
<div class="status-menu" data-status="<% $status %>">
% my $menu = $menus{$status};
<& /Elements/Menu, menu => $menu &>
</div>
% }
</div>

<%INIT>
my $Lifecycle = $Ticket->LifecycleObj;
my $id = $Ticket->Id;
my %menus;

# largely borrowed from /Elements/Tabs
my $current = $Ticket->Status;
my $hide_resolve_with_deps = RT->Config->Get('HideResolveActionsWithDependencies')
    && $Ticket->HasUnresolvedDependencies;
my $query_string = sub {
    my %args = @_;
    my $u    = URI->new();
    $u->query_form(map { $_ => $args{$_} } sort keys %args);
    return $u->query;
};

for my $status ($Lifecycle->Valid) {
    $menus{$status} = RT::Interface::Web::Menu->new();
}

my %seen_status;

my $add_menu = sub {
    my $next = shift;
    my $info = shift || {};
    my @class;
    my $include_url = 1;

    $seen_status{$next}++;

    if (!$Lifecycle->IsTransition( $current => $next )) {
        push @class, 'no-transition';
        $include_url = 0;
    }
    else {
        my $check = $Lifecycle->CheckRight( $current => $next );
        if (!$Ticket->CurrentUserHasRight($check)) {
            push @class, 'no-permission';
            $include_url = 0;
        }
    }

    if ($hide_resolve_with_deps
        && $Lifecycle->IsInactive($next)
        && !$Lifecycle->IsInactive($current)) {
        push @class, 'hide-resolve-with-deps';
        $include_url = 0;
    }

    my $action = $info->{'update'} || '';
    my $url = '/Ticket/';
    $url .= "Update.html?". $query_string->(
        $action
            ? (Action        => $action)
            : (SubmitTicket  => 1, Status => $next),
        DefaultStatus => $next,
        id            => $id,
    );
    my $key = $info->{'label'} || ucfirst($next);
    $menus{$next}->child(
        $key =>
        title => loc( $key ),
        ($include_url ? (path => $url) : ()),
        class => (join " ", @class),
    );
};

foreach my $info ( $Lifecycle->Actions($current) ) {
    $add_menu->($info->{to}, $info);
}

for my $status ($Lifecycle->Valid) {
    next if $seen_status{$status};
    $add_menu->($status);
}

$m->callback( CallbackName => 'StatusMenus', TicketObj => $Ticket, LifecycleObj => $Lifecycle, Menus => \%menus);

</%INIT>
<%ARGS>
$Ticket => undef
</%ARGS>
