% layout 'AdminLTE', title => "Sme server 2 - datetime";

% content_for 'module' => begin

<div class="card-body">

    % if (config->{debug} == 1) {
        <pre>
            <%= dumper $c->current_route %>
            <%= dumper $dat_data %>
        </pre>
    % }


    % if ($c->stash('first')) {
        <div>
            <%= $c->render_to_string(inline =>$c->l($c->stash('first'))) %>
        </div>
    % } elsif ($c->stash('success')) {
        <div class='text-success'>
            <%= $c->l($c->stash('success')); %>
        </div>
    % } elsif ($c->stash('error')) {
        <div class='text-danger'>
            <%= $c->l($c->stash('error')); %>
        </div>
    % }


    <h1><%= $title %></h1>
    <br>
    <%= $modul %>

   <br><br>

   <div div class="row g-3 align-items-center">
        <div class="col-md-2">
            <%= $c->l('dat_The_time_is_currently') %>
        </div>
        <br>
        <div>
            <%= text_field 'clock', id => 'real-time-clock', readonly => 'readonly', class => 'col-md-2' , value => $dat_data->{currentdatetime} %>
        </div>
    </div>

    <br>

    % if ($dat_data->{ntpstatus} eq 'disabled') {
        <div class='datetime-set-ntp'>
            <%= l 'dat_NTP_ENABLE_DESC' %>
        </div>
    % } else {

        % my $current_year = $dat_data->{year};
        % my $year_options  = [ map { [ $_, $_ ] } ($current_year..($current_year+30)) ];
        % my $month_options = [ map { [ sprintf('%02d', $_), sprintf('%02d', $_) ] } (1..12) ];
        % my $hour_options  = [ map { [ sprintf('%02d', $_), sprintf('%02d', $_) ] } (0..23) ];
        % my $minute_options = [ map { [ sprintf('%02d', $_), sprintf('%02d', $_) ] } (0..60) ];
        % my $second_options = [ map { [ sprintf('%02d', $_), sprintf('%02d', $_) ] } (0..60) ];
        % my $mode_options = [
        %   [ $c->l('dat_ntp_server'),   'dat_ntp_server' ],
        %   [ $c->l('dat_manually_set'), 'dat_manually_set' ]
        % ];

        <br>

        <h2><%= $c->l('Time Configuration') %></h2>


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

            <br>

            <div class="row g-3 align-items-center">
                <div class="col-md-2">
                    <%= label_for time_mode => $c->l('Time Setting Mode:') %>
                </div>
                <div class="col-auto">
                    % param 'time_mode' => $dat_data->{time_mode} unless param 'time_mode';
                    <%= select_field time_mode => ($mode_options, id => 'time_mode_select'), class => "form-select" %>
                </div>
            </div>

            <br><br>

            <div id='ntp_section'>
                <div>
                    <%= $c->l('dat_NTP_CONFIGURE_DESC') %>
                </div>

                <br>

                <div class="row g-3 align-items-center">
                    <div class="col-md-2">
                        <label for="inputNTPServerURL" class="col-form-label"><%=$c->l('dat_NTP_Server_URL') %></label>
                    </div>
                    <div class="col-auto">
                        % my $server_check = '^([a-zA-Z0-9][a-zA-Z0-9\.\-]{0,253}[a-zA-Z0-9]|(\d{1,3}\.){3}\d{1,3})$';
                        % param 'ntpserver' => $dat_data->{ntpserver} unless param 'ntpserver';
                        <input type="text" name="ntpserver" id="inputNTPServerURL" class="form-control" aria-describedby="NTP Server URL" pattern="<%= $server_check %>" value="<%= $dat_data->{ntpserver} %>">

                    </div>
                    <div class="col-auto">
                        <button type="button" id="test-ntp-btn" class="btn btn-primary btn-sm ml-2">Test Server</button>
                        <span id="ntp-test-result" class="ntp-test-result ml-2"></span>
                    </div>
                </div>
            </div>

            <br>

            <div id='manual_section'>

                <div>
                    <%= $c->l('dat_NTP_DISABLE_DESC') %>
                </div>

                <br>

                <div>
                    <h3><%= $c->l('dat_set_manually') %></h3>
                </div>

                <br>

                <div class="row g-3 align-items-center">

                    <div class="col-md-1">
                        <legend><%= $c->l('Date') %><legend>
                    </div>

                    <div class="col-auto">
                        <%= $c->l('Year:') %>
                    </div>

                    <div class="col-auto">
                        % param 'year' => ($dat_data->{year}) unless param 'year';
                        <%= select_field year => ($year_options, id => 'year'), required => 'required', class=> "form-select" %>
                    </div>

                    <div class="col-auto">
                        <%= $c->l('Month:') %>
                    </div>

                    <div class="col-auto">
                        % param 'month' => ($dat_data->{month}) unless param 'month';
                        <%= select_field month => ($month_options, id => 'month'), required => 'required', class=> "form-select" %>
                    </div>

                    <div class="col-auto">
                        <label for="inputDay" class="col-form-label"><%= $c->l('Day:') %></label>
                    </div>

                    <div class="col-auto">
                        % param 'day' => ($dat_data->{day}) unless param 'day';
                        <input type="text" name="day" id="inputDay" class="form-control" aria-describedby="Day" placeholder="<%= $dat_data->{day} %>" pattern="^(0[1-9]|[12][0-9]|3[01])$" size="2" maxlength="2" required="required" inputmode = "numeric" autcomplete="off">
                    </div>

                </div>

                <br>

                <div class="row g-3 align-items-center">

                    <div class="col-md-1">
                        <legend><%= $c->l('Time') %></legend>
                    </div>

                    <div class="col-auto">
                        <%= $c->l('Hour:') %>
                    </div>
                    <div class="col-auto">
                        % param 'hour' => ($dat_data->{hour}) unless param 'hour';
                        <%= select_field hour => ($hour_options, id => 'hour'), required => 'required', class=> "form-select" %>
                    </div>

                    <div class="col-auto">
                        %= label_for minute => $c->l('Minute:')
                    </div>
                    <div class="col-auto">
                        % param 'minute' => ($dat_data->{minute}) unless param 'minute';
                        <%= select_field minute => ($minute_options, id => 'minute'), required => 'required', class=> "form-select", inputmode => 'numeric' %>

                        %#= text_field minute => id => 'minute', size => 2, maxlength => 2, placeholder => 'MM', pattern => '^[0-5][0-9]$', title => 'Minute (00-59)', required => 'required', inputmode => 'numeric', autocomplete => 'off'
                    </div>

                    <div class="col-auto">
                        %= label_for second => $c->l('Second:')
                    </div>
                    <div class="col-auto">
                        % param 'second' => ($dat_data->{second}) unless param 'second';
                        <%= select_field minute => ($second_options, id => 'minute'), required => 'required', class=> "form-select" , inputmode => 'numeric' %>

                    </div>

                </div>


                <br>

                <div class="row g-3 align-items-center">
                    <div class="col-md-1">
                        <%= l 'dat_TZ' %>
                    </div>
                    <div class="col-auto">
                        % param 'Timezone' => $c->getTimezone() unless param 'Timezone';
                        <%= select_field 'Timezone' =>  $c->getZone_list(), class => "form-select" %>
                    </div>
                </div>

            </div>

            <br>

            <%= hidden_field 'Old_ntpstatus' => $dat_data->{ntpstatus}; %>
            <%= hidden_field 'trt' => $dat_data->{trt}; %>

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

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

    % }

</div>
% end
1;