{% extends "base.html" %}

{% block title %}Ubah Pengumuman{% endblock %}

{% block body %}
<main class="documentation">
    <section>
        <h1>Ubah Pengumuman</h1>

        <form method="post">
            <div class="flex five">
                <aside class="two-fifth-600 full">
                    <div class="stack">
                        <label>Dibuat pada: </label>
                        <span>
                            {{ post.created_at|date("Y-m-d") }}
                        </span>
                    </div>
                    <div class="stack">
                        <label>Dibuat oleh: </label>
                        <span>
                            {{ creator.full_name }}
                        </span>
                    </div>
                    <div class="stack">
                        <label>Diubah pada: </label>
                        <span>
                            {% if post.edited_at is empty %}
                            -
                            {% else %}
                            {{ post.edited_at|date("Y-m-d") }}
                            {% endif %}
                        </span>
                        <input type="hidden" name="edited_at" value="{{ timestamp }}">
                    </div>

                    <div class="stack">
                        <label>Diubah oleh: </label>
                        <span>
                            {% if post.editor is empty %}
                            -
                            {% else %}
                            {{ editor.full_name }}
                            {% endif %}
                        </span>
                        <input type="hidden" name="editor" value="{{ editor_now.id }}">
                    </div>
                    <div class="stack">
                        <label>Status: </label>
                        <span>
                            {% if post.status == 1 %}
                            Aktif
                            {% elseif post.status == 2 %}
                            Belum aktif
                            {% else %}
                            Nonaktif
                            {% endif %}
                        </span>
                    </div>
                </aside>

                <div class="fifth-600 full">
                    <label for="category">Kategori: </label>
                    <select name="category">
                        {% for cat in categories %}
                        <option value="{{ cat.id }}"
                        {% if post.category == cat.id %}
                        selected
                        {% endif %}
                        >
                        {{ cat.category }}
                        </option>
                        {% endfor %}
                    </select>
                    <input type="hidden" name="old_category" value="{{ post.category }}">

                    <label for="valid_at">Berlaku dari: </label>
                    <input id="left" name="valid_at" value="{{ post.valid_at|date("Y-m-d") }}">
                    <input type="hidden" name="old_valid_at" value="{{ post.valid_at|date("Y-m-d") }}">

                    <label for="expired_at">Berlaku sampai: </label>
                    <input id="right" name="expired_at" value="{{ post.expired_at|date("Y-m-d") }}">
                    <input type="hidden" name="old_expired_at" value="{{ post.expired_at|date("Y-m-d") }}">
                </div>

                <div class="two-fifth-600 full">
                    <label for="content">Konten: </label>
                    <textarea id="smde" name="content">{{ post.content }}</textarea>
                    <input type="hidden" name="old_content" value="{{ post.content }}">
                </div>

                <input type="hidden" name="_currts" value="{{ timestamp }}" disabled>
                <input type="hidden" name="_method" value="put">
                <input type="hidden" name="_token" value="{{ token }}">

                <div class="off-two-fifth-600 full">
                    <button class="full pseudo" type="submit"
                    {% if (post.status == 0 or post.status == 3 or editor_now.id != creator.id) %}
                    disabled
                    {% endif %}>
                    <i class="fa fa-edit fa-fw" aria-hidden="true"></i>
                    <span style="font-size:smaller;">Ubah</span>
                    </button>
                </div>
            </div>
        </form>
    </section>
</main>

<script>
    rome(left, {
        dateValidator: rome.val.beforeEq(right),
        time: false
    });
    rome(right, {
        dateValidator: rome.val.afterEq(left),
        time: false
    });

    var simplemde = new SimpleMDE({ element: document.getElementById("smde") });
</script>
{% endblock %}
