{% extends "base_detail.html" %}
{% load mathfilters %}
{% load static %}
{% load naturalduration %}

{% block head_extra %}
<style>
.settings-form {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 12px 16px;
    align-items: center;
    max-width: 700px;
}

.settings-form p {
    margin: 0;
    display: contents;
}

.settings-form label {
    font-weight: 600;
    text-align: right;
    padding-right: 12px;
}

.settings-form input[type="text"],
.settings-form input[type="password"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.settings-form input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}

.settings-form .checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-form .checkbox-row label {
    font-weight: normal;
    text-align: left;
}

.settings-form input[type="checkbox"] {
    transform: scale(1.1);
}

.settings-form input[type="submit"] {
    grid-column: 1 / -1;
    margin-top: 16px;
    padding: 10px 24px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.settings-form input[type="submit"]:hover {
    background: #0056b3;
}

.widget-links {
    grid-column: 2;
    margin: 8px 0 16px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 13px;
}

.widget-links strong {
    display: block;
    margin-bottom: 8px;
}

.widget-links ul {
    margin: 0;
    padding-left: 18px;
}

.widget-links li {
    margin-bottom: 4px;
}

.settings-link {
    grid-column: 2;
    margin: 8px 0;
}
</style>



{% endblock %}

{% block title %}Settings{% endblock %}
{% block details %}
<p class="settings-link"><a href="{% url 'people:person_form' %}">Manage People</a></p>
<p class="settings-link"><a href="{% url 'profiles:bulk_visibility' %}">Scrobble Visibility Settings</a></p>
<form method="post" class="settings-form">{% csrf_token %}
    {% for field in form %}
        {% if field.name == "blog_enabled" %}
            <p class="checkbox-row">
                {{ field }}
                {{ field.label_tag }}
            </p>
            {% if profile.blog_enabled %}
            <div class="widget-links">
                <strong>Your Blog URL:</strong>
                <ul>
                    <li><a href="{% url 'scrobbles:blog' request.user.username %}">{{ request.scheme }}://{{ request.get_host }}{% url 'scrobbles:blog' request.user.username %}</a></li>
                </ul>
            </div>
            {% endif %}
        {% elif field.name == "enable_public_widgets" %}
            <p class="checkbox-row">
                {{ field }}
                {{ field.label_tag }}
            </p>
            {% if user_id %}
            <div class="widget-links">
                <strong>Available Widgets:</strong>
                <ul>
                    <li><a href="{% url 'scrobbles:embeddable-top-artists' 'week' user_id %}">Top Artists (Week)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-artists' 'month' user_id %}">Top Artists (Month)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-artists' 'year' user_id %}">Top Artists (Year)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-board-games' 'week' user_id %}">Top Board Games (Week)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-board-games' 'month' user_id %}">Top Board Games (Month)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-board-games' 'year' user_id %}">Top Board Games (Year)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-books' 'week' user_id %}">Top Books (Week)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-books' 'month' user_id %}">Top Books (Month)</a></li>
                    <li><a href="{% url 'scrobbles:embeddable-top-books' 'year' user_id %}">Top Books (Year)</a></li>
                </ul>
            </div>
            {% endif %}
        {% elif field.name == "trends_disabled" %}
            <p class="checkbox-row">
                {{ field }}
                {{ field.label_tag }}
            </p>
        {% elif field.name == "fasting_vacation_exempt" %}
            <p class="checkbox-row">
                {{ field }}
                {{ field.label_tag }}
            </p>
        {% elif field.name == "home_scrobble_limit" %}
            <p>
                {{ field.label_tag }}
                {{ field }}
            </p>
        {% else %}
            <p>
                {{ field.label_tag }}
                {{ field }}
            </p>
        {% endif %}
    {% endfor %}
    <input type="submit" value="Save">
</form>

<div class="widget-links" style="margin-top: 16px;">
    <strong>Todoist Integration:</strong>
    {% if profile.todoist_auth_key %}
        <p class="text-success"><strong>✓ Connected to Todoist</strong></p>
        <a href="{% url 'tasks:task_todoist_auth' %}" class="btn btn-sm btn-outline-secondary">Reconnect to Todoist</a>
    {% else %}
        <p>Not connected</p>
        <a href="{{todoist_oauth_url}}" class="btn btn-sm btn-primary">Connect to Todoist</a>
    {% endif %}
</div>
{% endblock %}
