<div>

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

        <br>

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

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

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

        <br><br>

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

        <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>

        <br>

        % my $numlocalnetworks = @$localnetworks;
        % if ($numlocalnetworks == 0) {
            <%= l 'ln_LOCAL_NETWORK_NONE' %>
        % } else {
            <br>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th><%= l 'NETWORK' %></th>
                        <th><%= l 'ln_SUBNET_MASK' %></th>
                        <th><%= l 'ln_NUMBER_OF_HOSTS' %></th>
                        <th><%= l 'ROUTER' %></th>
                        <th class="text-center"><%= l 'ACTION' %></th>
                    </tr>
                </thead>
                <tbody>
                    % foreach my $localnetwork (@$localnetworks ) {
                        % my ($num_hosts) = esmith::util::computeHostRange( $localnetwork->key, $localnetwork->prop('Mask') );
                        % my $removable = $localnetwork->prop('Removable') || "yes";
                        % my $system = $localnetwork->prop('SystemLocalNetwork') || "no";
                        % if ( $system eq "yes" ) { $removable = "no"; }
                            <tr class="align-middle">
                                <td><%= $localnetwork->key %></td>
                                <td><%= $localnetwork->prop('Mask') %></td>
                                <td><%= $num_hosts %></td>
                                <td><%= $localnetwork->prop('Router') %></td>
                                % my $actionRemove = '&nbsp;';
                                % if ($removable eq "yes") {
                                    %my $remove_text = l('REMOVE');  # Localized text
                                    %my $local_network_entry = $localnetwork->key;
                                    %my $csrf_token = "TOKEN";  # CSRF token for security
                                    %$actionRemove = qq{
                                    % <a href="localnetworksd?CsrfDef=$csrf_token&trt=DEL&localnetwork=$local_network_entry">
                                    %   <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' => $ln_datas->{trt} %>
        % }

    </form>
</div>
