{% load static %}
{% include 'dashboard/admin_dashboard/header.html' %}
{% include 'dashboard/admin_dashboard/body.html' %}

<div class="content-wrapper">
    <div style="padding: 10px;">
        {% if messages %}
            {% for message in messages %}
                <div class="alert {% if 'success' in message.tags %}alert-success{% elif 'danger' in message.tags %}alert-danger{% endif %}" role="alert">
                    {{ message }}
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
            {% endfor %}
        {% endif %}
    </div>

    <section class="content-header text-center">
        <h1>Gate Pass Management <small>Edit Gate Pass</small></h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Edit Gate Pass</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-lg-12">
                <div class="box box-primary">
                    <div class="box-header">
                        <h3 class="box-title">Edit Gate Pass</h3>
                    </div>

                    <form method="POST" enctype="multipart/form-data">
                        {% csrf_token %}
                        <div class="form-group col-lg-12">
                            <label>Gate Pass Name <span style="color:red">*</span></label>
                            <input type="text" name="gate_pass_name" required class="form-control" value="{{ all_gate_pass_template.gate_pass_name }}">
                        </div>

                        <div class="form-group col-lg-12">
                            <label>Gate Pass Template <span style="color:red">*</span></label>
                            <textarea name="gate_pass_template" class="form-control summernote" rows="5" required>{{ all_gate_pass_template.gate_pass_template }}</textarea>
                        </div>

                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">Update</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>

{% include 'dashboard/visitors_dashboard/footer.html' %}

<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>

<script>
    $(document).ready(function() {
        $('.summernote').summernote({
            height: 200,
            toolbar: [
                ['style', ['style']],
                ['font', ['bold', 'italic', 'underline', 'clear']],
                ['fontname', ['fontname']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ]
        });

        // ✅ Ensure the Summernote content is synced when submitting
        $('form').on('submit', function() {
            $('.summernote').each(function() {
                var code = $(this).summernote('code');
                $(this).val(code);  // this updates the <textarea>
            });
        });
    });
</script>

