%# 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 }}}
<div class="row pagelayout-editor">
  <div class="pagelayout-widget-menu boxcontainer col-md-3">
    <&| /Widgets/TitleBox, title => loc('Available Widgets') &>
      <div class="filters">
        <div class="row">
          <div class="col-12">
            <input type="search" class="m-1 field form-control" name="search" placeholder="<&|/l&>Search...</&>" autocomplete="off">
          </div>
        </div>
      </div>
      <div class="d-block text-center">
% my $section = '';
% for my $item ( @AvailableWidgets ) {
%   my $value;
%   if ( ref $item ) {
%       $value = {%$item};
%       delete $value->{$_} for qw/section label tooltip/;
%   } else {
%       $value = $item;
%   }

%   if ( ref $item && ($item->{section} // '') ne $section ) {
%     $section = $item->{section};
      <h5><% $section %></h5>
%   }
%       my $id;
%       if ( ref $item ) {
%           if ( $id = $item->{component} ) {
%               $id =~ s!/!-!g; # / is not valid in id attr.
%           } else {
%               $id = "$item->{portlet_type}-$item->{id}";
%           }
%       } else {
%           $id = $item;
%       }
        <div id="pagelayout-widget-<% $id %>" class="pagelayout-widget" draggable="true" data-value="<% JSON($value) %>">
          <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
          <p class="m-1 p-2 border rounded">
            <span class="content"><% ref $item ? $item->{label} : $item %></span>
            <span class="float-end">
%           if ( ref $item && $item->{tooltip} ) {
                <% GetSVGImage( Name => 'info', Title => $item->{tooltip} ) |n %>
%           } elsif ( $item eq 'CustomFieldCustomGroupings' ) {
              <% GetSVGImage( Name => 'info', Title => ' ' ) |n %>
              <a href="#" class="edit" data-bs-toggle="modal" data-bs-target="#pagelayout-widget-<% $item %>-modal">
                <% GetSVGImage( Name => 'pencil', Title => loc('Edit') ) |n %></a>
%           } elsif ( ( $item eq 'History' && $Page !~ /^SelfService / ) || ( $Class eq 'RT::Ticket' && ( $item =~ /^(?:People|Basics)$/ || ( $Page eq 'Create' && $item eq 'Message' ) ) ) ) {
              <a href="#" class="edit" data-bs-toggle="modal" data-bs-target="#pagelayout-widget-<% $item %>-modal">
                <% GetSVGImage( Name => 'pencil', Title => loc('Edit') ) |n %></a>
%           }
              <a href="#" class="remove">
                <% GetSVGImage( Name => 'close-circle', Title => loc('Remove') ) |n %>
              </a>
            </span>
          </p>
        </div>
%       if ( $item eq 'CustomFieldCustomGroupings' ) {
        <& SELF:EditWidgetCustomFieldCustomGroupings, Widget => $item, Groupings => \@groupings &>
%       } elsif ( $item eq 'Message' && $Class eq 'RT::Ticket' && $Page eq 'Create' ) {
        <& SELF:EditWidgetMessage, Widget => $item, Class => $Class, Page => $Page &>
%       } elsif ( $item eq 'People' && $Class eq 'RT::Ticket' ) {
        <& SELF:EditWidgetPeople, Widget => $item, Class => $Class, Page => $Page &>
%       } elsif ( $item eq 'Basics' && $Class eq 'RT::Ticket' ) {
        <& SELF:EditWidgetBasics, Widget => $item, Class => $Class, Page => $Page &>
%       } elsif ( $item eq 'History' && $Page !~ /^SelfService / ) {
        <& SELF:EditWidgetHistory, Widget => $item, Class => $Class &>
%       }
% }
      </div>
    </&>
  </div>
  <div class="pagelayout-form boxcontainer col-md-9">
  <&| /Widgets/TitleBox,
    title     => loc('Page Layout'),
    icons_ref => [
        $Class eq 'RT::Dashboard'
        ? ()
        : {
                icon_name    => 'pencil',
                tooltip_text => loc('Edit'),
                icon_href    => 'javascript:void(0)',
                modal        => "#pagelayout-edit-name-modal",
          },
        {
            icon_name    => 'plus',
            tooltip_text => loc('Add Row'),
            icon_href    => 'javascript:void(0)',
            modal        => "#pagelayout-create-row-modal",
        }
    ],
  &>
    <div class="my-3 alert alert-warning pending-changes hidden">
      <&|/l&>New changes pending. Click "Save Changes" to update the form.</&>
    </div>

% my $i = 0;
% for my $row_index ( 0 .. $#rows ) {
%   my $row = $rows[$row_index];
    <div class="row-container"
%   if ( ref $row eq 'ARRAY' && ref $row->[0] ) {
      data-title="<% $row->[0]{Title} // '' %>" data-layout="<% $row->[0]{Layout} // '' %>" data-separated-columns="1"
%   } elsif ( ref $row eq 'HASH' ) {
      data-title="<% $row->{Title} // '' %>" data-layout="<% $row->{Layout} // '' %>" data-separated-columns="0"
%   }
    >
%   if ( ref $row eq 'ARRAY' ) {
%     if ( ref $row->[0] ) {
      <& SELF:EditRow, Row => $row->[0], Index => $row_index, SeparatedColumns => 1 &>
      <&| /Widgets/TitleBox,
        title     => $row->[0]{Title} // '',
        icons_ref => [
            {
                icon_name    => 'pencil',
                tooltip_text => loc('Edit'),
                icon_href    => 'javascript:void(0)',
                class        => 'edit-row',
                modal        => "#pagelayout-edit-row-$row_index-modal",
            },
            {
                icon_name    => 'close',
                tooltip_text => loc('Delete Row'),
                icon_href    => 'javascript:void(0)',
                class        => 'delete-row'
            },
        ],
      &>
        <div class="row">
%       for my $row ( @$row ) {
          <div class="<% $row->{Class} %>">
            <div class="pagelayout-content w-100 border rounded mt-3">
%           for my $item ( @{$row->{Elements}} ) {
              <& SELF:EditWidget, Widget => $item, Index => $i, Groupings => \@groupings, Class => $Class, Page => $Page &>
%             $i++;
%           }
              <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
              <div class="pagelayout-widget-empty-room"></div>
            </div>
          </div>
%       }
        </div>
      </&>
%   } else {
      <div class="pagelayout-content w-100 border rounded mt-3">
%     for my $item ( @$row ) {
        <& SELF:EditWidget, Widget => $item, Index => $i, Groupings => \@groupings, Class => $Class, Page => $Page &>
%       $i++;
%     }
        <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
        <div class="pagelayout-widget-empty-room"></div>
      </div>
%   }
% } else {
      <& SELF:EditRow, Row => $row, Index => $row_index, SeparatedColumns => 0 &>
      <&| /Widgets/TitleBox,
        title     => $row->{Title} // '',
        icons_ref => [
            {
                icon_name    => 'pencil',
                tooltip_text => loc('Edit'),
                icon_href    => 'javascript:void(0)',
                class        => 'edit-row',
                modal        => "#pagelayout-edit-row-$row_index-modal",
            },
            {
                icon_name    => 'close',
                tooltip_text => loc('Delete Row'),
                icon_href    => 'javascript:void(0)',
                class        => 'delete-row',
            },
        ],
      &>
        <div class="pagelayout-content w-100 border rounded mt-3">
          <div class="row">
%         for my $index ( 0 .. $#{$row->{Elements}} ) {
            <div class="<% $row->{Classes}[$index % @{$row->{Classes} }] %>">
              <& SELF:EditWidget, Widget => $row->{Elements}[$index], Index => $i, Groupings => \@groupings, Class => $Class, Page => $Page &>
            </div>
%           $i++;
%         }
          </div>
          <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
          <div class="pagelayout-widget-empty-room"></div>
        </div>
      </&>
%   }
    </div>
% }

    <form method="POST" action="<% RT->Config->Get('WebPath') . $m->request_path %>" id="pagelayout-form-modify">
%   for my $item (@PassArguments) {
      <input type="hidden" name="<% $item %>" value="<% $ARGS{$item} // '' %>">
%   }
      <input type="hidden" name="Content">
      <& /Elements/Submit, Name => 'Update', Label => loc('Save Changes'), FullWidth => 1 &>
    </form>
  </&>
  </div><!-- row -->

  <& SELF:EditRow, Create => 1 &>

  <div id="pagelayout-separated-columns-template" class="hidden">
    <div>
      <div class="pagelayout-content w-100 border rounded mt-3">
        <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
        <div class="pagelayout-widget-empty-room"></div>
      </div>
    </div>
  </div>

  <div id="pagelayout-connected-columns-template" class="hidden">
    <div class="pagelayout-content w-100 border rounded mt-3">
      <div class="row"></div>
      <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
      <div class="pagelayout-widget-empty-room"></div>
    </div>
  </div>

% if ( $Class ne 'RT::Dashboard' ) {
  <div class="modal fade" id="pagelayout-edit-name-modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <form method="post" hx-boost="false" class="pagelayout-name-form" action="">
          <div class="modal-header">
            <h5 class="modal-title"><% loc('Edit Page Layout Name') %></h5>
            <a href="javascript:void(0)" class="close" data-bs-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </a>
          </div>
          <div class="modal-body">
            <&| /Elements/LabeledValue, Label => loc('Name') &>
              <input required type="text" name="NewName" value="<% $Name %>" class="form-control" />
            </&>
          </div>
          <div class="modal-footer">
            <& /Elements/Submit, Name => 'UpdatePage', Label => loc('Update') &>
          </div>
        </form>
      </div>
    </div>
  </div>
% }

</div>
<%INIT>
my $widget_key = sub {
    my $widget = shift;
    return
        ref $widget
        ? ( $widget->{Name} || join( '-', grep defined, $widget->{portlet_type}, $widget->{component} || $widget->{id} ) )
        : $widget =~ /^([^:]*)/ && $1;
};

my %available_widgets = map { $widget_key->($_)  => $_ } @AvailableWidgets;
my $canonicalize_widget = sub {
    my $widget = shift;
    my $key = $widget_key->($widget);
    return unless $available_widgets{$key};

    # For references, %available_widgets contains full info.
    # For strings, use the original version as it might contain argument.
    if ( ref $available_widgets{$key} ) {
        return $available_widgets{$key};
    }
    else {
        return $widget;
    }
};

my @rows;
my @items;
for my $item (@$Content) {
    if ( ref $item ) {
        if (@items) {
            push @rows, \@items;
            @items = ();
        }

        $item->{Layout} ||= 'col-12';
        my @column_classes = split /\s*,\s*/, $item->{Layout};
        if ( ref $item->{Elements}[0] eq 'ARRAY' ) {
            my $new_row = [];
            for my $col ( 0 .. $#{ $item->{Elements} } ) {
                push @$new_row,
                    {
                        Title    => $item->{Title},
                        Layout   => $item->{Layout},
                        Class    => $column_classes[ $col % @column_classes ],
                        Elements => [ map { $canonicalize_widget->($_) } @{ $item->{Elements}[$col] } ],
                    };
            }
            push @rows, $new_row;
        }
        else {
            push @rows,
                {
                    Title    => $item->{Title},
                    Layout   => $item->{Layout},
                    Classes  => \@column_classes,
                    Elements => [ map { $canonicalize_widget->($_) } @{ $item->{Elements} } ],
                };
        }
    }
    else {
        push @items, $canonicalize_widget->($item);
    }
}
push @rows, \@items if @items;

my %groupings;
if ( RT->Config->Get('CustomFieldGroupings')->{$Class} ) {
    for my $queue ( %{ RT->Config->Get('CustomFieldGroupings')->{$Class} } ) {
        $groupings{$_} = 1 for RT::CustomField->CustomGroupings( $Class, $queue );
    }
}
my @groupings = sort( { lc $a cmp lc $b } keys %groupings, 'Default' );

</%INIT>
<%ARGS>
$Class => undef
$Page => undef
$Name => undef
$Content => []
@AvailableWidgets => ()
@PassArguments => ()
</%ARGS>

<%METHOD EditWidget>
<div id="pagelayout-widget-<% $Index %>" class="pagelayout-widget" draggable="true" data-value="<% JSON($value) %>">
  <p class="pagelayout-widget-placeholder m-1 p-2 border rounded"><% loc('Place here') %></p>
  <p class="m-1 p-2 border rounded">
    <span class="content"><% ref $Widget ? $Widget->{Name} || $Widget->{label} : $Widget =~ /(.+):/ ? $1 : $Widget %></span>
    <span class="float-end">
% my $widget_name = ( ref $Widget && $Widget->{Name} ) || $Widget;
%   if ( ref $Widget && $Widget->{tooltip} ) {
      <% GetSVGImage( Name => 'info', Title => $Widget->{tooltip} ) |n %>
%   } elsif ( $widget_name =~ /^CustomFieldCustomGroupings\b/ ) {
%     # Support legacy "Name:Groupings" string format and current hash format
%     my $grouping_text = ref $Widget ? $Widget->{Groupings} : ($Widget =~ /.*:(.+)/ ? $1 : undef);
      <% GetSVGImage( Name => 'info', $grouping_text ? ( Title => $grouping_text ) : ( Title => ' ', ExtraClasses => 'hidden' ) ) |n %>
      <a href="#" class="edit" data-bs-toggle="modal" data-bs-target="#pagelayout-widget-<% $Index %>-modal">
        <% GetSVGImage( Name => 'pencil', Title => loc('Edit') ) |n %></a>
%   } elsif ( ( $widget_name eq 'History' && $Page !~ /^SelfService / ) || ( $Class eq 'RT::Ticket' && ( $widget_name =~ /^(?:People|Basics)$/ || ( $Page eq 'Create' && $widget_name eq 'Message' ) ) ) ) {
      <a href="#" class="edit" data-bs-toggle="modal" data-bs-target="#pagelayout-widget-<% $Index %>-modal">
        <% GetSVGImage( Name => 'pencil', Title => loc('Edit') ) |n %></a>
%   }
      <a href="#" class="remove">
        <% GetSVGImage( Name => 'close-circle', Title => loc('Remove') ) |n %>
      </a>
    </span>
  </p>
% if ( $widget_name =~ /^CustomFieldCustomGroupings\b/ ) {
  <& SELF:EditWidgetCustomFieldCustomGroupings, %ARGS &>
% } elsif ( $widget_name eq 'History' && $Page !~ /^SelfService / ) {
  <& SELF:EditWidgetHistory, %ARGS, Class => $Class &>
% } elsif ( $Class eq 'RT::Ticket' && $Page eq 'Create' && $widget_name eq 'Message' ) {
  <& SELF:EditWidgetMessage, %ARGS, Class => $Class, Page => $Page &>
% } elsif ( $Class eq 'RT::Ticket' && $widget_name eq 'People' ) {
  <& SELF:EditWidgetPeople, %ARGS, Class => $Class, Page => $Page &>
% } elsif ( $Class eq 'RT::Ticket' && $widget_name eq 'Basics' ) {
  <& SELF:EditWidgetBasics, %ARGS, Class => $Class, Page => $Page &>
% }
</div>
<%INIT>
my $value;
if ( ref $Widget ) {
    $value = {%$Widget};
    delete $value->{$_} for qw/section label tooltip/;
}
else {
    $value = $Widget;
}
</%INIT>
<%ARGS>
$Widget => undef
$Index => undef
$Groupings => undef
$Class => undef
$Page => undef
</%ARGS>
</%METHOD>

<%METHOD EditWidgetCustomFieldCustomGroupings>
<div class="modal fade pagelayout-widget-modal" id="pagelayout-widget-<% $Index // $Widget %>-modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form hx-boost="false" class="pagelayout-widget-form">
        <div class="modal-header">
          <h5 class="modal-title"><% loc('Modify Element') %></h5>
          <a href="javascript:void(0)" class="close" data-bs-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">
          <&| /Elements/LabeledValue, Label => loc("Groupings"), LabelTooltip => loc('Nothing selected means to show all') &>
            <select name="Groupings" multiple class="form-select <% defined $Index ? 'selectpicker' : '' %>">
%           for my $grouping ( @$Groupings ) {
              <option value="<% $grouping %>" <% $selected{$grouping} ? 'selected' : '' %>><% $grouping %></option>
%           }
            </select>
          </&>
          <& /Widgets/Form/Select,
             Name => 'ColumnWidth',
             Description => loc('Column Width'),
             Tooltip => loc('Minimum width for each column in the multi-column layout'),
             CurrentValue => ( ref $Widget && $Widget->{ColumnWidth} ) // '',
             DefaultLabel => loc('Medium (default)'),
             Values => [qw(xs sm lg xl)],
             ValuesLabel => {
                 xs => loc('Extra narrow'),
                 sm => loc('Narrow'),
                 lg => loc('Wide'),
                 xl => loc('Extra wide'),
             },
             LabeledValue => 1,
             defined $Index ? () : ( InputClass => 'form-select' ),
          &>
        </div>
        <div class="modal-footer">
          <& /Elements/Submit, Label => loc('Update') &>
        </div>
      </form>
    </div>
  </div>
</div>
<%INIT>
my %selected;
# Support legacy "Name:Groupings" string format and current hash format
my $groupings = ref $Widget ? $Widget->{Groupings} : ($Widget =~ /^CustomFieldCustomGroupings\b:(.+)/ ? $1 : undef);
if ( $groupings ) {
    %selected = map { $_ => 1 } split /\s*,\s*/, $groupings;
}
</%INIT>
<%ARGS>
$Widget => undef
$Index => undef
$Groupings => undef
</%ARGS>
</%METHOD>


<%METHOD EditRow>
<div class="modal fade" id="<% $Create ? "pagelayout-create-row-modal" : "pagelayout-edit-row-$Index-modal" %>" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form method="post" <% $Create ? '' : 'hx-boost="false"' |n %> class="pagelayout-row-form" action="">
        <div class="modal-header">
          <h5 class="modal-title"><% $Create ? loc('Add Row') : loc('Modify Row') %></h5>
          <a href="javascript:void(0)" class="close" data-bs-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">
          <&| /Elements/LabeledValue, Label => loc("Title"), LabelTooltip => loc('Optional. If blank, no wrapper box is rendered.') &>
            <input name="Title" class="form-control" value="<% $Create ? '' : $Row->{Title} // '' %>" />
          </&>
          <&| /Elements/LabeledValue, Label => loc("Columns") &>
            <select name="Columns" class="form-select selectpicker">
%           for my $i ( 1..4 ) {
              <option value="<% $i %>"><% $i %></option>
%           }
            </select>
          </&>
          <&| /Widgets/TitleBox, title => loc('Advanced Layout'), rolledup => 1, title_class => 'title-sm' &>
            <&| /Elements/LabeledValue, Label => loc("Layout"), LabelTooltip => loc('Col numbers must add up to 12') &>
              <input name="Layout" class="form-control" placeholder="col-12" value="<% $Create ? '' : $Row->{Layout} // '' %>" />
            </&>
            <div class="form-check mt-2 separated-columns-option d-none">
              <input type="checkbox" class="checkbox form-check-input" value="1" id="SeparatedColumns<% $Create ? '' : "-$Index" %>" name="SeparatedColumns" <% $SeparatedColumns ? 'checked' : '' %>>
              <label class="form-check-label" for="SeparatedColumns<% $Create ? '' : "-$Index" %>">
                <% loc('Separated Columns') %> <% GetSVGImage( Name => 'info', ExtraClasses => 'icon-helper', Title => loc('Choose widgets of each column separatedly'), Size => 12 ) |n %>
              </label>
            </div>
          </&>
        </div>
        <div class="modal-footer">
          <& /Elements/Submit, Name => $Create ? 'AddRow' : 'UpdateRow', Label => $Create ? loc('Add') : loc('Update') &>
        </div>
      </form>
    </div>
  </div>
</div>

<%ARGS>
$Row => undef
$Index => undef
$SeparatedColumns => 1
$Create => undef
</%ARGS>

</%METHOD>

<%METHOD EditWidgetHistory>
<div class="modal fade pagelayout-widget-modal" id="pagelayout-widget-<% $Index // $Widget %>-modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form hx-boost="false" class="pagelayout-widget-form">
        <div class="modal-header">
          <h5 class="modal-title"><% loc('Modify Element') %></h5>
          <a href="javascript:void(0)" class="close" data-bs-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">
          <&| /Elements/LabeledValue, Label => loc("Default Transaction Types"), LabelTooltip => loc('Configure which transaction types are shown by default in the history') &>
            <& /Elements/TransactionTypeFilterDropdown,
               Object => $Class,
               ShowSelectActions => 0,
               AllChecked => 1,
               RenderAsDropdown => 1,
               For => $Index,
               ref $Widget && $Widget->{FilterTxnTypes} ? ( FilterTxnTypes => $Widget->{FilterTxnTypes} ) : (),
            &>
          </&>
          <& $show_history_meta->{Widget} || '/Widgets/Form/Select',
             Name => 'ShowHistory',
             Tooltip => loc('Configure how history is displayed on this page'),
             CurrentValue => ( ref $Widget && $Widget->{ShowHistory} ) // '',
             DefaultLabel => loc('Use system default'),
             %{ $show_history_meta->{WidgetArguments} || {} },
             Description => loc('Show History'),
             LabeledValue => 1,
             $Index ? () : ( InputClass => 'form-select' ),
          &>

          <& /Widgets/Form/Integer,
             Name => 'PerPage',
             Description => loc('Transactions Per Page'),
             Tooltip => loc('Number of transactions to show per page for paged history'),
             CurrentValue => ( ref $Widget && $Widget->{PerPage} ) // '',
             DefaultValue => 10,
             Min => 1,
             Max => 100,
             LabeledValue => 1
          &>
        </div>
        <div class="modal-footer">
          <& /Elements/Submit, Label => loc('Update') &>
        </div>
      </form>
    </div>
  </div>
</div>
<%INIT>
# Get ShowHistory configuration metadata from RT::Config
my $show_history_meta = RT->Config->Meta('ShowHistory');
# For assets, limit ShowHistory options to just "page" mode
if ( $Class && $Class eq 'RT::Asset' ) {
    # Override the widget arguments to show only relevant options for assets
    $show_history_meta->{WidgetArguments}{Values}      = [qw(page)];
    $show_history_meta->{WidgetArguments}{ValuesLabel} = {
        page => "one page at a time",    #loc
    };
}
</%INIT>
<%ARGS>
$Widget => undef
$Index => undef
$Class => undef
</%ARGS>
</%METHOD>


<%METHOD EditWidgetCustomRoles>
<div class="modal fade pagelayout-widget-modal" id="pagelayout-widget-<% $Index // $Widget %>-modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form hx-boost="false" class="pagelayout-widget-form">
        <div class="modal-header">
          <h5 class="modal-title"><% loc('Modify Element') %></h5>
          <a href="javascript:void(0)" class="close" data-bs-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">
% my $custom_roles = RT::CustomRoles->new( $session{CurrentUser} );
% if ( $Class ) {
%   $custom_roles->LimitToLookupType( $Class->CustomFieldLookupType );
% }
% if ( $WidgetName eq 'Basics' ) {
%   $custom_roles->LimitToSingleValue;
% } elsif ( $WidgetName eq 'Message' )  {
%   $custom_roles->LimitToMultipleValue;
% }
% $custom_roles->UnLimit;
% if ( $custom_roles->Count > 0 ) {
          <&| /Elements/LabeledValue, Label => loc("Custom Role Visibility"), LabelTooltip => loc('Configure which custom roles are visible in this [_1] widget', $WidgetName) &>
% while ( my $role = $custom_roles->Next ) {
            <div class="row mb-2">
              <div class="col-sm-4">
                <label class="form-label"><% $role->Name %></label>
              </div>
              <div class="col-sm-8">
                <div class="form-check form-check-inline">
% my $is_hidden = 1 if ref $Widget && grep { $role->Name eq $_ } @{ $Widget->{HiddenRoles} || [] };
                  <input class="form-check-input" type="radio" name="Role-<% $role->Name %>" id="<% $Index %>-Role-<% $role->Id %>-Show" value="show" <% $is_hidden ? '' : 'checked' %>>
                  <label class="form-check-label" for="<% $Index %>-Role-<% $role->Id %>-Show">
                    <% loc('Show') %>
                  </label>
                </div>
                <div class="form-check form-check-inline">
                  <input class="form-check-input" type="radio" name="Role-<% $role->Name %>" id="<% $Index %>-Role-<% $role->Id %>-Hide" value="hide" <% $is_hidden ? 'checked' : '' %>>
                  <label class="form-check-label" for="<% $Index %>-Role-<% $role->Id %>-Hide">
                    <% loc('Hide') %>
                  </label>
                </div>
              </div>
            </div>
% }
          </&>
% } else {
          <div class="alert alert-info">
            <% loc('Add a custom role to configure it in the [_1] widget.', $WidgetName) %>
          </div>
% }
        </div>
        <div class="modal-footer">
          <& /Elements/Submit, Label => loc('Update') &>
        </div>
      </form>
    </div>
  </div>
</div>
<%ARGS>
$Widget => undef
$Index => undef
$Class => undef
$Page => undef
$WidgetName => undef
</%ARGS>
</%METHOD>

<%METHOD EditWidgetMessage>
<& SELF:EditWidgetCustomRoles, %ARGS, WidgetName => 'Message' &>
</%METHOD>

<%METHOD EditWidgetPeople>
<& SELF:EditWidgetCustomRoles, %ARGS, WidgetName => 'People' &>
</%METHOD>

<%METHOD EditWidgetBasics>
<& SELF:EditWidgetCustomRoles, %ARGS, WidgetName => 'Basics' &>
</%METHOD>
