{% extends "base.html" %}

{% block title %}Settings - 1D Poisson Simulator{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h2><i class="bi bi-gear"></i> Settings</h2>
        <p class="text-muted">Configure application settings</p>
        <hr>
    </div>
</div>

<div class="row">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-terminal"></i> Simulation Configuration</h5>
            </div>
            <div class="card-body">
                <form id="settingsForm">
                    <div class="mb-3">
                        <label for="executablePath" class="form-label">1D Poisson Executable Path</label>
                        <div class="input-group">
                            <input type="text" class="form-control" id="executablePath"
                                   placeholder="e.g., C:\Program Files\1D Poisson\1DPoisson.exe" required>
                            <button class="btn btn-outline-secondary" type="button" id="browseBtn">
                                <i class="bi bi-folder-open"></i> Browse
                            </button>
                        </div>
                        <small class="form-text text-muted">
                            Path to the 1D Poisson executable file
                        </small>
                        <div id="pathStatus" class="mt-2"></div>
                    </div>

                    <div class="mb-3">
                        <label for="workingDirectory" class="form-label">Working Directory</label>
                        <input type="text" class="form-control" id="workingDirectory"
                               placeholder="e.g., C:\Users\YourName\1DPoisson_simulations">
                        <small class="form-text text-muted">
                            Directory for simulation files and outputs
                        </small>
                    </div>

                    <div class="mb-3">
                        <label for="timeout" class="form-label">Simulation Timeout (seconds)</label>
                        <input type="number" class="form-control" id="timeout"
                               min="10" max="3600" value="300">
                        <small class="form-text text-muted">
                            Maximum time allowed for a simulation to run
                        </small>
                    </div>

                    <div class="form-check mb-3">
                        <input class="form-check-input" type="checkbox" id="keepTempFiles">
                        <label class="form-check-label" for="keepTempFiles">
                            Keep temporary files after simulation
                        </label>
                    </div>

                    <div class="mb-3">
                        <label for="verbosity" class="form-label">Verbosity Level</label>
                        <select class="form-select" id="verbosity">
                            <option value="0">Quiet (no output)</option>
                            <option value="1" selected>Normal</option>
                            <option value="2">Verbose (detailed)</option>
                        </select>
                    </div>

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save"></i> Save Settings
                        </button>
                        <button type="button" class="btn btn-outline-secondary" id="validateBtn">
                            <i class="bi bi-check-circle"></i> Test Configuration
                        </button>
                        <button type="button" class="btn btn-outline-warning" id="resetBtn">
                            <i class="bi bi-arrow-counterclockwise"></i> Reset to Defaults
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-info-circle"></i> System Information</h5>
            </div>
            <div class="card-body">
                <div id="systemInfo">
                    <div class="spinner-border spinner-border-sm" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                    Loading system information...
                </div>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-key"></i> License</h5>
            </div>
            <div class="card-body">
                <div id="licenseInfo">
                    <div class="spinner-border spinner-border-sm" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                    Loading license information...
                </div>
                <div class="mt-3 d-flex gap-2">
                    <button class="btn btn-outline-primary btn-sm" id="revalidateLicenseBtn">
                        <i class="bi bi-arrow-repeat"></i> Re-validate Online
                    </button>
                    <button class="btn btn-outline-danger btn-sm" id="deactivateLicenseBtn">
                        <i class="bi bi-x-circle"></i> Deactivate License
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-4">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0"><i class="bi bi-question-circle"></i> Help</h6>
            </div>
            <div class="card-body">
                <h6>Finding the 1D Poisson Executable</h6>
                <p class="small">
                    The executable path depends on your installation:
                </p>
                <ul class="small">
                    <li><strong>Windows:</strong> Usually in <code>C:\Program Files\1D Poisson\</code> or where you installed it</li>
                    <li><strong>macOS:</strong> Usually in <code>/Applications/1D Poisson/</code></li>
                    <li><strong>Linux:</strong> Usually in <code>/usr/local/bin/</code></li>
                </ul>

                <hr>

                <h6>Configuration Tips</h6>
                <ul class="small">
                    <li>Test the configuration after changing the executable path</li>
                    <li>The working directory will be created if it doesn't exist</li>
                    <li>Increase timeout for complex structures</li>
                    <li>Enable verbose mode for debugging</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script src="{{ url_for('static', filename='js/settings.js') }}"></script>
{% endblock %}
