<div>

    % my $retref = $c->stash("ret");
    % my %ret = $retref ? %$retref : (ret => "");
    % my @vars = split(/,/, $ret{vars} // '');
    % my ($var1, $var2, $var3, $var4, $var5, $var6, $var7) = @vars;

    % my $numtcpforwards = @$tcpforwards;
    % my $numudpforwards = @$udpforwards;

    % if ($c->app->config->{debug}) {
        <pre>
            <%= dumper { ret_data => \%ret } %>
        </pre>
    % }

    % if ($ret{ret} eq "") {
        <div>
            <%= $c->render_to_string(inline => l('pf_FIRST_PAGE_DESCRIPTION')); %>
        </div>
    % } elsif (index($ret{ret},"SUCCESS") != -1) {

        <div>
           <h2> Operation Status Report</h2>
            <%= $c->render_to_string(inline => l($ret{ret}, @vars[0..6])) %>
        </div>
    % } else {
        <br>
        <div class="text-danger">
           <h2> Operation Status Report - Error</h2>
           <%= $c->render_to_string(inline => l($ret{ret}, @vars[0..6])) %>
        </div>
    % }

    <br>

    <form action="/smanager/portforwardinga" method="POST">

    % my $btn = l('pf_CREATE_RULE');

    <div class="row g-3 align-items-center">
        <div class="col-md-2">
            <button type="submit" class="btn btn-primary btn-sm"><%= $btn %></button>
        </div>
    </div>

    </form>

    <br>

    % if ($empty) {
            <br>
            <%= l 'pf_NO_FORWARDS' %>
    % } else {
        <br>
        <%= l 'pf_SHOW_FORWARDS' %>
        <br><br>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th><%= l 'pf_LABEL_PROTOCOL' %></th>
                <th><%= l 'pf_LABEL_SOURCE_PORT' %></th>
                <th><%= l 'pf_LABEL_DESTINATION_HOST' %></th>
                <th><%= l 'pf_LABEL_DESTINATION_PORT' %></th>
                <th><%= l 'pf_ALLOW_HOSTS' %></th>
                <th><%= l 'pf_RULE_COMMENT' %></th>
                <th class="text-center"><%= l 'ACTION' %></th>
            </tr>
            </thead>
            <tbody>
                % my %forwards = ();
                % $forwards{TCP} = $tcpforwards;
                % $forwards{UDP} = $udpforwards;

                % foreach my $proto (sort keys %forwards) {

                    % if (@{ $forwards{$proto} }) {
                        % foreach my $entry (@{ $forwards{$proto} }) {
                            <tr class="align-middle">
                                % my $sport = $entry->key;
                                % my $dhost = $entry->prop('DestHost');
                                % my $dport = $entry->prop('DestPort') || '';
                                % my $cmmnt  = $entry->prop('Comment') || '';
                                % my $allow  = $entry->prop('AllowHosts') || '';
                                <td><%= $proto %></td>
                                <td><%= $sport %></td>
                                <td><%= $dhost %></td>
                                <td><%= $dport %></td>
                                <td><%= $allow %></td>
                                <td><%= $cmmnt %></td>
                                % my $remove_text = l('REMOVE');  # Localized text
                                % my $csrf_token = "TOKEN";  # CSRF token for security
                                % my $actionRemove = qq{
                                % <a href="portforwardingd?CsrfDef=$csrf_token&trt=DEL&sport=$sport&proto=$proto">
                                %   <button type='button' class="btn btn-primary btn-sm" title='$remove_text' >
                                %       $remove_text
                                %   </button>
                                % </a>
                                % };

                                <td class="text-center"><%= $c->render_to_string(inline => $actionRemove) %></td>
                            </tr>
                            % }
                        % }
                    % }
                % }
            </tbody>
        </table>
    <%= hidden_field 'trt' => $pf_datas->{trt} %>

</div>
