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

{% block content %}
<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-printer me-5"></i>Printer Settings
        </h1>
        <div class="btn-toolbar mb-2 mb-md-0">
            <a class="btn btn-outline-primary" @click="CreatePrinter()">
                <i class="me-2 ti ti-playlist-add"></i>Add Printer
            </a>
        </div>
    </div>
    {# Printer List #}
    <div class="col-12">
        <div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 g-4">
            <div class="col" v-for="printerData, printerIndex in printerList">
                <div class="col card border-primary shadow">
                    <div class="card-header py-3">
                        <p class="text-primary m-0 fw-bold">{% raw %}{{ printerData.name }}{% endraw %}</p>
                    </div>
                    <div class="card-body">
                        <table class="table table-middle table-borderless my-0">
                            <tbody>
                                <tr>
                                    <td class="ps-4 py-2">Type:</td>
                                    <td class="ps-0 py-2">{% raw %}{{ printerData.type }}{% endraw %}</td>
                                </tr>
                                <tr>
                                    <td class="ps-4 py-2">Density:</td>
                                    <td class="ps-0 py-2">{% raw %}{{ printerData.density }}{% endraw %} dpi</td>
                                </tr>
                                <tr>
                                    <td class="ps-4 py-2">Address:</td>
                                    <td class="ps-0 py-2">{% raw %}{{ printerData.socket_addr }}{% endraw %}</td>
                                </tr>
                                <tr>
                                    <td class="ps-4 py-2">Port:</td>
                                    <td class="ps-0 py-2">{% raw %}{{ printerData.socket_port }}{% endraw %}</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="EditPrinter(printerData.id)">
                                <i class="ti ti-printer me-2"></i>Edit
                            </a>
                            <a class="btn btn-outline-danger" @click="DeletePrinter(printerData.id)">
                                <i class="ti ti-trash me-2"></i>Delete
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

{# Printer Settings Modal #}
<div class="modal fade" id="printerSettingsModal" tabindex="-1" data-bs-backdrop="static" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h1 class="modal-title fs-5" id="labelModalLabel" v-if="printerEditor.uid == null">Create Printer</h1>
                <h1 class="modal-title fs-5" id="labelModalLabel" v-if="printerEditor.uid != null">Printer {% raw %}{{ printerEditor.id }}{% endraw %}</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body mx-2">
                <div class="mb-3">
                    <label for="printerNameInput" class="form-label">Printer Name</label>
                    <input type="text" class="form-control" id="printerNameInput" placeholder="Useful Printer 1" v-model="printerEditor.name">
                </div>
                <div class="row">
                    <div class="col-8 mb-3">
                        <label for="printerDPIInput" class="form-label">Printer IP-Address</label>
                        <input type="text" class="form-control" id="printerDPIInput" placeholder="10.0.0.1" v-model="printerEditor.socket_addr">
                    </div>
                    <div class="col-4 mb-3">
                        <label for="printerDPIInput" class="form-label">Printer Port</label>
                        <input type="text" class="form-control" id="printerDPIInput" placeholder="9100" v-model="printerEditor.socket_port">
                    </div>
                </div>
                <div class="mb-3">
                    <label for="printerDensityInput" class="form-label">Printer Density</label>
                    <select class="form-select" id="printerDensityInput" v-model="printerEditor.density">
                        <option value="203">203 dpi (8 dpmm)</option>
                        <option value="300">300 dpi (12 dpmm)</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                {# <a class="btn btn-outline-danger" @click="DeletePrinter()" title="Delete Printer">
                    <i class="me-2 ti ti-trash"></i>Delete
                </a> #}
                <a class="btn btn-outline-primary" @click="SavePrinter()" title="Save Printer">
                    <i class="me-2 ti ti-device-floppy"></i>Save
                </a>
            </div>
        </div>
    </div>
</div>

{# Printer delete Confirmation Modal #}
<div class="modal fade" id="printerDeleteModal" data-bs-backdrop="static" aria-hidden="true" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <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 Printer {% raw %}{{ printerEditor.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="DeletePrinter(printerEditor.id, 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="/app.printers.js"></script>
{% endblock %}