{% extends "./master.njk" %}

{% block content %}
{# Input Section #}
<div class="container">

<div class="row row-cols-2 g-4">
    <div class="col-12 d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-4 mb-3 border-bottom">
        <h1 class="h2 m-0">
            <i class="ti ti-toilet-paper me-5"></i>Media Settings
        </h1>
        <div class="btn-toolbar mb-2 mb-md-0">
            <a class="btn btn-outline-primary" @click="CreateMedium()">
                <i class="me-2 ti ti-playlist-add"></i>Add Media
            </a>
        </div>
    </div>
    {# Media List #}
    <div class="col-12">
        <div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 g-4">
            <div :class="['col', medium.id == null ? 'd-none': '']" v-for="(medium, index) in mediaList">
                <div class="col card border-primary shadow">
                    <div class="card-header py-3">
                        <p class="text-primary m-0 fw-bold">{% raw %}{{ medium.name }}{% endraw %}</p>
                    </div>
                    <div class="card-body">
                        <table class="table table-middle table-borderless my-0">
                            <tbody>
                                <tr title="number of columns in a row">
                                    <td class="py-2" title="Number of Columns">
                                        <i class="ti ti-columns-2 me-2"></i>Columns:
                                    </td>
                                    <td class="py-2" title="Number of Columns">
                                        {% raw %}{{ medium.columns }}{% endraw %}
                                    </td>
                                </tr>
                                <tr title="spacing between columns in mm">
                                    <td class="py-2" title="Spacing between Columns">
                                        <i class="ti ti-spacing-horizontal me-2"></i>Spacing:
                                    </td>
                                    <td class="py-2" title="Spacing between Columns">
                                        {% raw %}{{ medium.spacing }}{% endraw %} mm
                                    </td>
                                </tr>
                                <tr title="width of a row in mm">
                                    <td class="py-2" title="Spacing between Columns">
                                        <i class="ti ti-arrow-autofit-width me-2"></i>Row Width:
                                    </td>
                                    <td class="py-2" title="Spacing between Columns">
                                        {% raw %}{{ medium.width }}{% endraw %} mm
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="card-footer text-body-secondary">
                        <div class="d-flex justify-content-end" style="gap: 0.6rem">
                            <a class="btn btn-outline-primary" @click="EditMedium(index)">
                                <i class="ti ti-printer me-2"></i>Edit
                            </a>
                            <a class="btn btn-outline-danger" @click="DeleteMedium(index)">
                                <i class="ti ti-trash me-2"></i>Delete
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

{# add Media Modal #}
<div class="modal fade" id="addMediaModal" data-bs-backdrop="static" aria-hidden="true" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content" v-if="mediaIndex != null">
            <div class="modal-header">
                <h1 class="modal-title fs-5" id="labelModalLabel" v-if="mediaList[mediaIndex].id == null">Create Media</h1>
                <h1 class="modal-title fs-5" id="labelModalLabel" v-if="mediaList[mediaIndex].id != null">Media {% raw %}{{ mediaList[mediaIndex].id }}{% endraw %}</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body mx-2 d-flex flex-column" style="gap: 1rem">
                <div class="col-12">
                    <label class="form-label">Media Name</label>
                    <input type="text" class="form-control label-input" placeholder="Media Name" v-model="mediaList[mediaIndex].name">
                </div>
                <div class="row">
                    <div class="col-6" title="number of columns in a row">
                        <label class="form-label">Number of Columns</label>
                        <div class="col-6 input-group">
                            <input type="text" class="form-control" placeholder="3" v-model="mediaList[mediaIndex].columns">
                        </div>
                    </div>
                    <div class="col-6" title="spacing between columns in mm">
                        <label class="form-label">Column Spacing</label>
                        <div class="col-6 input-group">
                            <input type="text" class="form-control" placeholder="2" v-model="mediaList[mediaIndex].spacing">
                            <span class="input-group-text">mm</span>
                        </div>
                    </div>
                    <div class="col-6" title="width of a row in mm">
                        <label class="form-label">Row Width</label>
                        <div class="col-6 input-group">
                            <input type="text" class="form-control" placeholder="2" v-model="mediaList[mediaIndex].width">
                            <span class="input-group-text">mm</span>
                        </div>
                    </div>
                </div>
                <div class="col-12 d-flex" style="gap: 1rem">
                    <a class="btn btn-outline-primary" @click="SaveMedium(mediaIndex)">
                        <i class="me-2 ti ti-device-floppy"></i>Save
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

{# delete Media Confirmation Modal #}
<div class="modal fade" id="deleteMediaModal" data-bs-backdrop="static" aria-hidden="true" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content" v-if="mediaIndex != null">
            <div class="modal-body mx-2 d-flex flex-column" style="gap: 1rem">
                <h5 class="mb-0">Delete Media</h5>
                <p class="mb-0">Are you sure you want to delete Media {% raw %}{{ mediaList[mediaIndex].name }}{% endraw %}?</p>
            </div>
            <div class="modal-footer flex-nowrap p-0">
                <a class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0 border-end" @click="DeleteMedium(mediaIndex, true)">
                    <strong>Delete</strong>
                </a>
                <a class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0" data-bs-dismiss="modal">
                    Cancel
                </a>
            </div>
        </div>
    </div>
</div>

<script src="/api.js"></script>
<script src="/app.media.js"></script>
{% endblock %}