{% extends "orgapy/layout/skeleton.html" %}
{% load static %}

{% block title %}Orgapy{% endblock title %}

{% block head %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'orgapy/css/objectives.css' %}" />
<link rel="stylesheet" href="{% static 'orgapy/css/projects.css' %}" />
<link rel="stylesheet" href="{% static 'orgapy/css/mood.css' %}" />
<script src="{% static 'orgapy/js/dragrank.js' %}"></script>
<script src="{% static 'orgapy/js/objectives.js' %}"></script>
<script src="{% static 'orgapy/js/projects.js' %}"></script>
<script src="{% static 'orgapy/js/mood.js' %}"></script>
{% endblock head %}

{% block menu_create %}
<li class="menu-item"><form id="createTaskForm" action="{% url 'orgapy:tasks' %}" method="post">{% csrf_token %}<input type="hidden" name="title"><input type="hidden" name="next" value="{{ request.get_full_path }}"><button tabindex="3"><i class="ri-task-line"></i> Task</button></form></li>
<li class="menu-item"><form id="createObjectiveForm" action="{% url 'orgapy:objectives' %}" method="post">{% csrf_token %}<input type="hidden" name="title"><button tabindex="3"><i class="ri-focus-2-line"></i> Objective</button></form></li>
<li class="menu-item"><button id="buttonCreateProject" tabindex="3"><i class="ri-briefcase-line"></i> Project</button></li>
<hr>
{{ block.super }}
{% endblock menu_create %}

{% block menu %}
<li class="menu-item"><form action="{% url 'orgapy:calendars' %}" method="post">{% csrf_token %}<input type="hidden" name="next" value="{{ request.get_full_path }}"><button type="submit" name="action" value="refresh"><i class="ri-reset-left-line"></i> Refresh events</button></form></li>
{{ block.super }}
{% endblock menu %}

{% block column_main %}

{% if event_groups %}
<div class="card">
    <div class="card-body">
        <div id="eventsContainer" class="coll spaced-lines">
            {% for group_date, group_events in event_groups %}
            <details open>
                <summary class="minititle">{{ group_date | date }}</summary>
                {% for event in group_events %}
                <div class="row row--nowrap {% if event.over %}muted{% endif %}" title="{{ event.title }}{% if event.location %} @ {{ event.location }}{% endif %}" style="width: 100%">
                    <a class="event-dot"></a>
                    {% if event.time %}<div>{{ event.time | date:'H:i' }}</div>{% endif %}
                    <div class="ellipsis">{{ event.title }}</div>
                </div>
                {% endfor %}
            </details>
            {% endfor %}
        </div>
    </div>
</div>
{% endif %}

{% if pending_mood_logs %}{% include 'orgapy/partials/mood_log_forms.html' %}{% endif %}

{% if settings.beach_mode %}
<div class="card">
    <h2 class="card-header">🏖️ Beach Mode On 🌞</h2>
    <div class="card-body">
        <p>
            Tasks, objectives and projects are hidden.<br>
            <span class="hint">Change this in <a href="{% url 'orgapy:settings' %}?ref={{ request.get_full_path | urlencode }}">settings</a>.</span>
        </p>
    </div>
</div>
{% else %}
{% if task_groups %}
<div class="card">
    <div class="card-body">
        <div id="tasksContainer" class="coll spaced-lines">
            {% for task_group in task_groups %}
            <details {% if task_group.open %}open{% endif %}>
                <summary class="minititle">{{ task_group.label }}</summary>
                {% for task in task_group.tasks %}
                <div class="task {% if task.overdue %}task-overdue{% endif %}">
                    <form action="{% url 'orgapy:task' task.id %}" method="post">
                        {% csrf_token %}
                        <input type="hidden" name="next" value="{{ request.get_full_path }}" />
                        <button type="submit" name="action" value="complete" title="Complete" class="task-button-complete submit-confirm" message="Complete '{{ task.title }}'?"><i class="ri-check-line"></i></button>
                    </form>
                    <a class="link-hidden" href="{{ task.get_absolute_url }}?next={{ request.get_full_path | urlencode }}" title="Start date: {{ task.start_date | date }}{% if task.due_date %} Due date: {{ task.due_date | date }}{% endif %}">{{ task.title }}</a>
                </div>
                {% endfor %}
            </details>
            {% endfor %}
        </div>
    </div>
</div>
{% endif %}
{% if objectives %}
{{ objectives | json_script:"objectivesData" }}
<div id="objectivesContainer" class="objectives" tabindex="-1"></div>
<script type="text/javascript">loadAndInflateObjectives({{ settings.objective_start_hours }}, objectivesData, objectivesContainer, "{% url 'orgapy:objectives' %}", false);</script>
{% endif %}
<div id="projectsContainer" class="projects coll" tabindex="-1">
{% for project in projects %}
<div id="project{{ project.id }}" class="project-container" href="{{ project.get_absolute_url }}">{{ project.to_json_dict | json_script }}</div>
<script type="text/javascript">bindProject(project{{ project.id }}, "{% url 'orgapy:suggestions' %}")</script> 
{% endfor %}
</div>
{% endif %}
{% endblock %}

{% block body_scripts %}
<script type="text/javascript">
bindCreateProjectButton(buttonCreateProject, projectsContainer, "{% url 'orgapy:projects' %}", "{% url 'orgapy:suggestions' %}");
bindCreateForm(createTaskForm, "task");
bindCreateForm(createObjectiveForm, "objective");
</script>
{% endblock %}