# FAQ Management Module Usage Instructions

> The `feat/admin-sub/faq` branch introduces a streamlined Frequently Asked Questions (FAQ) Management module. Built upon the secure `feat/admin` and `base` branches, it empowers administrators to quickly create, organize, and manage FAQs directly using a seamless, modal-driven interface without full-page reloads.

---

## Table of Contents

1. [Module Overview](#1-module-overview)
2. [What You Inherit](#2-what-you-inherit)
3. [Deep Dive: Features & Functionality](#3-deep-dive-features--functionality)
4. [File Paths & Architecture](#4-file-paths--architecture)
5. [Step-by-Step Usage Guide](#5-step-by-step-usage-guide)

---

## 1. Module Overview

This branch establishes the FAQ section within the Admin Portal. It provides administrators the capability to manage questions and answers, determine their display order, and quickly toggle their visibility status. The module uses a completely modal-driven workflow, ensuring the user never has to leave the main data table view when creating or updating records.

---

## 2. What You Inherit

By merging with the **Base** and **Admin** branches, this feature inherits:
- **UI Components:** Utilizes standard `<x-common.*>`, `<x-forms.*>`, and `<x-buttons.*>` Blade components.
- **Admin Security:** The `auth:admin` middleware protects all routes.
- **AJAX & Modal Architecture:** Fast, reload-free interactions powered by Alpine.js for modal logic and Server-Side Datatables (`<x-common.table-server>`).

---

## 3. Deep Dive: Features & Functionality

This branch brings specialized features for managing frequently asked questions:

- **Modal-Driven CRUD Operations:** 
  Create and Update operations are handled entirely through Alpine.js pop-up modals, keeping the administrator on the index page for a faster workflow.
- **Ordering System:** 
  Includes an `order` field to easily dictate the sequence in which FAQs appear on the public frontend.
- **Interactive Status Toggles:**
  Directly toggle FAQ statuses (Active/Inactive) right from the data table using interactive Alpine.js dropdowns.
- **Soft Deletion & Archiving:**
  Deleted FAQs are safely moved to the "Archived" tab, protecting against accidental data loss.
- **Bulk Operations:** 
  Perform bulk deletion on active FAQs and bulk restore on archived FAQs.
- **Table Filters & Searching:** 
  Robust filtering tools to find specific questions quickly within the management table.

---

## 4. File Paths & Architecture

Here are the key files introduced or modified in this branch:

### Controllers & Services (`app/Http/Controllers/Admin/Faq/`, `app/Services/Admin/`)
- **`FaqController.php`**: The central controller handling data table rendering, modal data retrieval, and CRUD operations.
- **`FaqService.php`**: Encapsulates business logic, including database transactions, ordering logic, and status modifications.
- **`FaqRequest.php`**: The Form Request handling input validation.

### Models, Migrations & Factories (`app/Models/`, `database/`)
- **`Faq.php`**: The Eloquent model configuring mass assignable fields, soft-delete rules, and mutators.
- **`*_create_faqs_table.php`**: Database migration containing question, answer, order, and status fields.
- **`FaqFactory.php` & `FaqSeeder.php`**: Tools to rapidly seed dummy FAQs for testing purposes.

### Views (`resources/views/pages/admin/faq/`)
- **`index.blade.php`**: The primary view displaying the active FAQs table and including the Create/Edit modals.
- **`archived.blade.php`**: The view for managing soft-deleted FAQs.
- **`partials/table.blade.php`**: The server-side table partial handling asynchronous data population.
- **`partials/create-modal.blade.php`**: The Alpine.js modal component for creating a new FAQ.
- **`partials/edit-modal.blade.php` / `edit-modal-body.blade.php`**: The components handling the dynamic loading of FAQ data for editing.

### JavaScript (`resources/js/admin/`)
- **`faq.js`**: Contains Alpine.js component logic for handling datatables, modal state management, status updates, and archiving.

---

## 5. Step-by-Step Usage Guide

### 1. Database Setup
Ensure your database contains the new `faqs` table. Run migrations and (optionally) the seeder:
```bash
php artisan migrate
php artisan db:seed --class=FaqSeeder
```

### 2. Accessing the Module
- Log into the Admin Portal (`/behindthescreen`).
- In the sidebar navigation, locate and click on **FAQs** under the Content category.

### 3. Managing FAQs
- **Creating an FAQ:** Click "Add New FAQ". A modal will appear. Enter the Question, Answer, assign an Order number, and Save. The table will refresh seamlessly.
- **Editing an FAQ:** Click the Edit action (pencil icon) on any record. The edit modal will dynamically load the data for that specific FAQ.
- **Status Updates:** From the `index` view, use the status dropdown in the table row to immediately activate or deactivate an FAQ.
- **Archiving/Deleting:** Use the delete action on a record or select multiple records for Bulk Deletion. They will move to the "Archived" tab.
- **Restoring Data:** Navigate to the "Archived" tab to review soft-deleted FAQs. Select them to restore them.
