{% extends "base.html" %}
{% block title %}Settings{% endblock %}
{% block content %}
<h1>Settings</h1>

<form method="post" action="/settings">
    <label>
        RSS Feed URL
        <input type="url" name="feed_url" value="{{ feed_url }}" required>
    </label>

    <label>
        Fetch Interval (hours)
        <input type="number" name="fetch_interval" value="{{ fetch_interval }}" min="1" max="168" required>
    </label>

    <fieldset>
        <legend>Auto-Publish</legend>
        <label>
            <input type="checkbox" name="auto_publish_enabled" role="switch"
                   {% if auto_publish %}checked{% endif %}>
            Enable auto-publish
        </label>
        <div class="grid">
            <label>
                Day
                <select name="auto_publish_day">
                    {% for d in ['mon','tue','wed','thu','fri','sat','sun'] %}
                    <option value="{{ d }}" {% if auto_publish and auto_publish.day_of_week == d %}selected{% endif %}>
                        {{ d|capitalize }}
                    </option>
                    {% endfor %}
                </select>
            </label>
            <label>
                Hour
                <input type="number" name="auto_publish_hour"
                       value="{{ auto_publish.hour if auto_publish else 6 }}" min="0" max="23">
            </label>
            <label>
                Minute
                <input type="number" name="auto_publish_minute"
                       value="{{ auto_publish.minute if auto_publish else 0 }}" min="0" max="59">
            </label>
            <label>
                Cover
                <select name="auto_publish_cover">
                    <option value="mosaic" {% if auto_publish and auto_publish.cover_method == 'mosaic' %}selected{% endif %}>Mosaic Cover</option>
                    <option value="text" {% if not auto_publish or auto_publish.cover_method == 'text' %}selected{% endif %}>Text Cover</option>
                </select>
            </label>
        </div>
    </fieldset>

    <fieldset>
        <legend>Image Constraints</legend>
        <div class="grid">
            <label>
                Landscape Width
                <input type="number" name="landscape_w" value="{{ max_landscape[0] }}">
            </label>
            <label>
                Landscape Height
                <input type="number" name="landscape_h" value="{{ max_landscape[1] }}">
            </label>
            <label>
                Portrait Width
                <input type="number" name="portrait_w" value="{{ max_portrait[0] }}">
            </label>
            <label>
                Portrait Height
                <input type="number" name="portrait_h" value="{{ max_portrait[1] }}">
            </label>
        </div>
    </fieldset>

    <button type="submit">Save Settings</button>
</form>
{% endblock %}
