<!-- bedrock_server_manager//web/templates/configure_service.html -->
{# Extends the base layout template #}
{% extends "base.html" %}

{# --- Page Title Block --- #}
{% block title %}{{ super() }} - Configure Service: {{ server_name }}{% endblock %}

{# --- Main Content Block --- #}
{% block content %}
    {# Main heading for the page #}
<h2>Configure Service Options</h2>

    {# Display server context and installation step if applicable #}
<p style="margin-bottom: 15px;">
    Server: <strong>{{ server_name }}</strong>
    {% if new_install %}
    {# Indicator for multi-step installation workflow #}
    {# Assuming this is the final step? Adjust number if needed. #}
    <br><span class="step-indicator">(Step 4 of 4 for New Installation)</span>
    {% endif %}
</p>

    {# --- Status Message Area --- #}
    {# Targeted by JavaScript (showStatusMessage) #}
<div id="status-message-area" class="message-box" style="opacity: 0; transition: opacity 0.5s ease-out;">
</div>

    {# Area for JavaScript-driven validation errors #}
<div id="validation-error-area" class="message-box message-error" style="margin-bottom: 15px; display: none;">
</div>

    {# Server-side flash messages (handled by base.html) #}

    {# --- Service Configuration Section --- #}
<section id="install-config-page" data-server-name="{{ server_name | e }}" data-is-new-install="{{ new_install | tojson }}" data-os="{{ os }}" class="service-config-section">

    <p>Configure automatic behavior for this server.</p>

    {# --- Auto-Update Toggle (Common to Linux/Windows) --- #}
    {# This setting controls whether the server checks for updates when started #}
    <div class="form-group form-group-toggle-container">
        <div class="form-label-group">
            {# Label linked to the actual checkbox input #}
            <label for="service-autoupdate-cb" class="form-label">Enable Auto-Update on Start:</label>
            <small class="form-help-text">
                Checks for updates when starting via the manager.
            </small>
        </div>
        <div class="toggle-switch-container">
            {# Checkbox input stores the state #}
            <input type="checkbox" id="service-autoupdate-cb" name="autoupdate-cb" class="toggle-input" value="true" {% if autoupdate %}checked{% endif %}>
            {# Visual switch linked to the checkbox #}
            <label for="service-autoupdate-cb" class="toggle-switch"></label>
        </div>
        {# Hidden input ensures 'false' is submitted if checkbox is unchecked #}
        <input type="hidden" name="autoupdate" class="toggle-hidden-false" value="false">
        {# Placeholder for validation error related to this toggle #}
        {# <div class="validation-error" data-field="autoupdate" style="grid-column: 1 / -1;"></div> #}
    </div>

    {# --- Auto-Start Toggle (Linux - Systemd | Windows - SC.exe) --- #}
    <div class="form-group form-group-toggle-container">
        <div class="form-label-group">
            <label for="service-autostart-cb" class="form-label">Enable Autostart on BSM Startup:</label>
            <small class="form-help-text">Starts the server automatically when the BSM Web Server starts using the autostart_plugin.</small>
        </div>
        <div class="toggle-switch-container">
            <input type="checkbox" id="service-autostart-cb" name="autostart-cb" class="toggle-input" value="true" {% if autostart %}checked{% endif %}>
            <label for="service-autostart-cb" class="toggle-switch"></label>
        </div>
        <input type="hidden" name="autostart" class="toggle-hidden-false" value="false">
    </div>


    {# --- Start Server after Save Toggle (New Install Only) --- #}
    {% if new_install %}
    <div class="form-group form-group-toggle-container" style="margin-top: 20px; border-top: 1px solid #555; padding-top: 15px;">
        <div class="form-label-group">
            <label for="service-start-server" class="form-label">Start Server After Saving?</label>
            <small class="form-help-text">Automatically start the server once these settings are saved.</small>
        </div>
        <div class="toggle-switch-container">
            {# This checkbox value is read directly by JS, no hidden false needed #}
            <input type="checkbox" id="service-start-server" name="start_server" class="toggle-input" value="true"> {# Default off #}
            <label for="service-start-server" class="toggle-switch"></label>
        </div>
    </div>
    {% endif %} {# End of new_install section #}

    {# --- Form Actions --- #}
    <div class="form-actions">
        {# Save button calls JS function, passing necessary data #}
        {# Use |tojson filter for boolean new_install flag #}
        <button type="button" id="save-service-settings-btn" class="action-button start-button">
            {# Green save button #}
            Save Service Settings
        </button>

        {# Navigation button/link #}
        <a href="{{ request.url_for('index') }}" class="action-link">
            {% if new_install %}
            Finish Setup & Go To Dashboard
            {% else %}
            « Back to Dashboard
            {% endif %}
        </a>
    </div>

</section> {# --- End of .service-config-section --- #}

{% endblock %}