# PROMPT 06 — Dashboard Controllers & Views

## Context
We are building the admin dashboard for **Water Rush**.
The dashboard template is already installed and working.
The `users` module already exists as a fully working example.

---

## Step 0 — Read the Users Module First (REQUIRED)

Before writing any code, read and analyze these existing files:

1. `app/Http/Controllers/Dashboard/UserController.php` (or wherever the users dashboard controller is)
2. All blade views under `resources/views/dashboard/users/` (index, create, edit, show — whatever exists)
3. The users routes in `routes/web.php`

Understand:
- How the controller is structured (index, create, store, edit, update, destroy)
- How forms are built
- How tables are built (columns, action buttons, pagination)
- How flash messages / alerts are shown
- How image uploads are handled if any
- How the layout/master blade is extended

**Use the users module as the single source of truth for UI and code style.**
Every module you create must look and work exactly like it.

---

## Step 1 — Dashboard Controllers

Create a controller under `App\Http\Controllers\Dashboard\` for each module below.
Follow the exact same structure as the existing `UserController`.

### 1. `CustomerController`
- `index` — paginated list, search by name or phone, show is_active status
- `show` — view customer details + their addresses + their orders
- `edit` / `update` — edit name, phone, is_active
- `destroy` — delete (block if has orders)
- `toggleActive` — POST route to flip is_active

### 2. `DriverController`
- `index` — paginated list, search by name or phone
- `create` / `store` — name, phone, password, vehicle_type, vehicle_number, vehicle_year
- `edit` / `update` — same fields, password optional on update
- `destroy`
- `toggleActive`

### 3. `CategoryController`
- `index` — list all with active status
- `create` / `store` — name only
- `edit` / `update`
- `destroy` — block if has products

### 4. `ProductController`
- `index` — paginated, filter by category, show price and price_before
- `create` / `store` — title, category_id (dropdown), description, price, price_before (optional), multiple images upload
- `edit` / `update` — same fields, show existing images with delete button per image, allow adding new images
- `destroy`
- `toggleActive`

### 5. `SliderController`
- `index` — list with image preview and sort_order
- `create` / `store` — image upload, link (optional), sort_order
- `edit` / `update` — show current image, allow replacing it
- `destroy`
- `toggleActive`

### 6. `PromoCodeController`
- `index` — list with code, type, discount, quantity, used_count, expires_at, status
- `create` / `store` — code, type (percent/fixed select), discount, quantity, expires_at (optional)
- `edit` / `update`
- `destroy`
- `toggleActive`

### 7. `BundleController`
- `index` — list with price, price_before, status
- `create` / `store` — title, description, price, price_before, multiple images, bundle items (dynamic rows: select product + quantity, add/remove rows with JS)
- `edit` / `update` — same, show existing images with delete, show existing items editable
- `destroy`
- `toggleActive`

### 8. `ScheduledTimeController`
- `index` — list all
- `create` / `store` — label, time_from, time_to
- `edit` / `update`
- `destroy`
- `toggleActive`

### 9. `OrderController`
- `index` — paginated, filter by status (tabs or dropdown), filter by date
- `show` — full order details: customer info, address, items (product/bundle), promo, scheduled time, driver info, status badge
- `updateStatus` — POST — change status (dropdown + submit)
- `assignDriver` — POST — assign driver (dropdown of active drivers)

### 10. `StatsController`
- `index` — dashboard home page showing:
  - Cards: total orders, today orders, total revenue, today revenue
  - Orders by status (badges or mini cards)
  - Monthly revenue chart (use Chart.js or whatever charting library is in the template)
  - Top 5 products table
  - Top 5 customers table

---

## Step 2 — Blade Views

For each module above, create blade views under `resources/views/dashboard/{module}/`.

Copy the **exact same layout** from `resources/views/dashboard/users/`:
- Same master layout `@extends`
- Same `@section` structure
- Same table style for index pages
- Same form style for create/edit pages
- Same action buttons (edit, delete, toggle active) with same styling
- Same pagination
- Same flash message display
- Same breadcrumbs if users has them

### Special UI notes:

**Products (create/edit):**
- Image upload: multiple file input
- Show existing images as thumbnails with an X/delete button each
- Deleting an image sends a separate request or marks it for deletion on submit

**Bundles (create/edit):**
- Dynamic bundle items section: a table of rows where each row has:
  - Product dropdown (populated from active products)
  - Quantity input
  - Remove row button
- "Add Item" button to append a new row
- Use vanilla JS or Alpine.js (whatever the template already uses)

**Orders (index):**
- Status filter tabs or dropdown at the top
- Color-coded status badges (pending=yellow, confirmed=blue, preparing=orange, on_the_way=purple, delivered=green, cancelled=red)

**Orders (show):**
- Two-column layout: left = order info + items table, right = customer info + address + driver + actions
- Status update form inline
- Assign driver dropdown inline

**Stats (index):**
- 4 stat cards at top
- Chart below (monthly revenue)
- Two tables side by side: top products + top customers

---

## Step 3 — Routes

Add all dashboard routes to `routes/web.php` under a prefix and middleware group.
Follow the exact same pattern as the existing users routes.

```php
Route::prefix('dashboard')->middleware(['auth'])->group(function () {
    // Stats
    Route::get('/', [StatsController::class, 'index'])->name('dashboard.index');

    // Customers
    Route::post('customers/{id}/toggle', [CustomerController::class, 'toggleActive'])->name('dashboard.customers.toggle');
    Route::resource('customers', CustomerController::class)->except(['create', 'store']);

    // Drivers
    Route::post('drivers/{id}/toggle', [DriverController::class, 'toggleActive'])->name('dashboard.drivers.toggle');
    Route::resource('drivers', DriverController::class);

    // Categories
    Route::post('categories/{id}/toggle', [CategoryController::class, 'toggleActive'])->name('dashboard.categories.toggle');
    Route::resource('categories', CategoryController::class);

    // Products
    Route::post('products/{id}/toggle', [ProductController::class, 'toggleActive'])->name('dashboard.products.toggle');
    Route::resource('products', ProductController::class);

    // Sliders
    Route::post('sliders/{id}/toggle', [SliderController::class, 'toggleActive'])->name('dashboard.sliders.toggle');
    Route::resource('sliders', SliderController::class);

    // Promo Codes
    Route::post('promo-codes/{id}/toggle', [PromoCodeController::class, 'toggleActive'])->name('dashboard.promo-codes.toggle');
    Route::resource('promo-codes', PromoCodeController::class);

    // Bundles
    Route::post('bundles/{id}/toggle', [BundleController::class, 'toggleActive'])->name('dashboard.bundles.toggle');
    Route::resource('bundles', BundleController::class);

    // Scheduled Times
    Route::post('scheduled-times/{id}/toggle', [ScheduledTimeController::class, 'toggleActive'])->name('dashboard.scheduled-times.toggle');
    Route::resource('scheduled-times', ScheduledTimeController::class);

    // Orders
    Route::post('orders/{id}/status', [OrderController::class, 'updateStatus'])->name('dashboard.orders.status');
    Route::post('orders/{id}/assign-driver', [OrderController::class, 'assignDriver'])->name('dashboard.orders.assign-driver');
    Route::resource('orders', OrderController::class)->only(['index', 'show']);
});
```

---

## Step 4 — Sidebar Navigation

Find the sidebar blade file in the template and add navigation links for all new modules.
Follow the exact same `<li>` / `<a>` / icon pattern already used for the users link.

Add these items (in this order):
1. Dashboard (stats) — home icon
2. Users — already exists
3. Customers
4. Drivers
5. Categories
6. Products
7. Sliders
8. Promo Codes
9. Bundles
10. Scheduled Times
11. Orders

---

## Rules
- Copy users module style 100% — do not invent new UI patterns
- Do not install new packages — use what is already in the project
- All image uploads go to `storage/app/public/{module}/` and display via `Storage::url()`
- All forms use CSRF `@csrf`
- All DELETE actions use a form with `@method('DELETE')` and a JS confirm dialog
- Toggle active buttons must show current state (Active = green, Inactive = red/grey)
- Run `php artisan route:clear` and `php artisan view:clear` at the end
