<%- include('includes/header', {username: admin[0].name,email: admin[0].email } ) %>

    <div class="body-wrapper">
        <div class="container-fluid">
            <div class="card bg-info-subtle shadow-none position-relative overflow-hidden mb-4">
                <div class="card-body px-4 py-3">
                    <div class="row align-items-center">
                        <div class="col-md-8 col-sm-7">
                            <h4 class="fw-semibold mb-1">Manage Faq</h4>

                        </div>


                        <div class="col-md-4 col-sm-5 text-md-end text-sm-start mt-3 mt-md-0">
                            <button class="btn btn-primary px-4" id="addFaqBtn" data-bs-toggle="modal"
                                data-bs-target="#faqModal">
                                <i class="fa-solid fa-plus me-2"></i> Add FAQ
                            </button>
                        </div>
                    </div>

                </div>
            </div>
            <div class="card shadow-sm">
                <div class="card-body">

                    <h4 class="mb-4">Update Faq Section</h4>

                    <form id="sectionForm">

                        <!-- TYPE (HIDDEN) -->
                        <input type="hidden" name="type" value="<%= section ? section.type : 'faq' %>">

                        <!-- LABEL + TITLE (ONE LINE) -->
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Section Label</label>
                                <input type="text" class="form-control" name="badge"
                                    value="<%= section ? section.badge : '' %>" placeholder="Faq Section Label"
                                    >
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Title</label>
                                <input type="text" class="form-control" name="title"
                                    value="<%= section ? section.title : '' %>"
                                    placeholder="Custom Title for Every Requirement">
                                     <small class="text-muted">
                                    Highlight any word using <code>&lt;span&gt;word&lt;/span&gt;</code>
                                </small>
                            </div>
                        </div>

                        <!-- SHORT DESCRIPTION -->
                        <div class="mb-4">
                            <label class="form-label fw-semibold">Short Description</label>
                            <textarea class="form-control" name="shortDescription" rows="3"
                                placeholder="Write short description here..."
                                ><%= section ? section.shortDescription : '' %></textarea>
                        </div>

                        <!-- BUTTON -->
                        <button type="submit" class="btn btn-primary px-4">
                            Update Section
                        </button>

                    </form>

                </div>
            </div>
            <div class="datatables">


                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive">
                            <table id="zero_config" class="table table-striped table-bordered text-nowrap align-middle">
                                <thead>
                                    <tr>
                                        <th>Question</th>
                                        <th class="action-col">Action</th>
                                    </tr>
                                </thead>
                                <tbody id="faqTableBody"></tbody>
                            </table>
                        </div>
                    </div>
                </div>

                <!-- FAQ Modal -->
                <div class="modal fade" id="faqModal" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-md modal-dialog-top">
                        <div class="modal-content border-0 shadow-lg rounded-3">

                            <div class="modal-header bg-light-subtle">
                                <h5 class="modal-title fw-semibold" id="faqModalLabel">Add FAQ</h5>
                                <button type="button" class="btn-close btn-close-dark" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body p-4">
                                <form id="faqForm">

                                    <input type="hidden" id="faqId">

                                    <div class="mb-3">
                                        <label class="form-label fw-medium">Question<span
                                                class="text-danger">*</span></label>
                                        <input type="text" id="question" class="form-control"
                                            placeholder="Enter FAQ question" required>
                                    </div>
                                    <div class="d-flex justify-content-between align-items-center mb-2">
                                        <label class="form-label fw-semibold">
                                            Answer<span class="text-danger">*</span>
                                        </label>
                                        <button type="button" id="generateFaqAI" class="btn btn-sm btn-outline-primary">
                                            <i class="fa-solid fa-wand-magic-sparkles me-1"></i>
                                            Generate by AI
                                        </button>
                                    </div>
                                    <div class="mb-3">
                                        <textarea id="answer" class="form-control" rows="4"
                                            placeholder="Enter FAQ answer" required></textarea>
                                    </div>
                                    <div class="modal-footer border-0 pt-0">
                                        <button type="button" class="btn btn-light"
                                            data-bs-dismiss="modal">Cancel</button>
                                        <button type="submit" id="saveFaqBtn" class="btn btn-primary px-4">Save</button>
                                    </div>

                                </form>
                            </div>


                        </div>
                    </div>
                </div>

            </div>



        </div>
    </div>
    </div>

    <%- include('includes/allscripts') %>
        <script src="/js/view/faq.js"></script>
        <script src="/js/view/pagesection.js"></script>