<div>
    % my $btn = l('ln_LOCALNETWORK_ADD');

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

        <br>

        % my $retref= $c->stash("ret");
        % my %ret;
        % unless (length($retref)) {%ret = (ret=>"");}
        % else {%ret = %$retref;}

        % if (config->{debug} == 1) {
            <div>
                %= dumper "Ret:".$ret{ret};
            </div>
        % }

        % my @vars = split(",",$ret{vars});
        % my $var1 = @vars[0];
        % my $var2 = @vars[1];
        % my $var3 = @vars[2];
        % my $var4 = @vars[3];
        % my $var5 = @vars[4];
        % my $var6 = @vars[5];
        % my $var7 = @vars[6];

        %if ($ret{ret} eq "") {
            <%= l "ln_FIRSTPAGE_DESC" %>
        % } elsif (index($ret{ret},"SUCCESS") != -1) {
            <br>
            <div>
                <h2> Operation Status Report</h2>
                <%= $c->render_to_string(inline => l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6,$var7)); %>
            </div>
        % } else {
            <div>
                <h2> Operation Status Report - Error</h2>
                <%= $c->render_to_string(inline => l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6,$var7)); %>
            </div>
        % }

        <br><br>

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

    </form>

    <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><%= 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>
                            <td><%= $localnetwork->key %>
                            <td><%= $localnetwork->prop('Mask') %>
                            <td><%= $num_hosts %>
                            <td><%= $localnetwork->prop('Router') %>
                            % 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" title='$remove_text' >
                                %       $remove_text
                                %   </button>
                                % </a>
                                %};
                            % }
                            <td><%= $c->render_to_string(inline => $actionRemove) %></td>
                        </tr>
                    % }
            </tbody>
        </table>
        <%= hidden_field 'trt' => $ln_datas->{trt} %>
    % }
</div>
