export interface WikiPage {
  slug: string
  title: string
  category: string
  content: string
}

export interface WikiCategory {
  name: string
  pages: WikiPage[]
}

const pages: WikiPage[] = [
  {
    slug: 'getting-started',
    title: 'Getting Started',
    category: 'General',
    content: `
# Getting Started with LunarFront

Welcome to LunarFront — your small business management platform.

## Signing In

1. Open LunarFront in your browser
2. Enter your email and password
3. Click **Sign in**

If you don't have an account, ask your admin to create one for you.

## Navigation

Use the sidebar on the left to navigate between sections:

- **Accounts** — manage customer accounts and their members
- **Members** — find and manage individual people across all accounts
- **Repairs** — track repair tickets
- **Repair Batches** — manage bulk school repair jobs
- **Help** — you're here!

## Need Help?

If you can't find what you're looking for, contact your admin or system administrator.
    `.trim(),
  },
  {
    slug: 'accounts-overview',
    title: 'Accounts Overview',
    category: 'Accounts',
    content: `
# Accounts

An **account** is an organizational entity — it could be a family, a business, a school, or an individual person. Members, repairs, and lessons are all linked to an account.

## Creating an Account

1. Go to **Accounts** in the sidebar
2. Click **New Account** in the top right
3. Fill in the account name (e.g. "Smith Family" or "Lincoln Elementary")
4. Optionally add email, phone, and address
5. Add the **primary contact** — this is the main person on the account
6. Click **Create Account**

**Tip:** If you leave the account name blank and fill in the primary contact, the account name will be automatically set to the person's name.

## Account Details

Click any account in the list to see its details. The detail page has tabs:

- **Overview** — edit account name, contact info, billing mode
- **Members** — people on the account (family members, students, etc.)
- **Payment Methods** — cards on file
- **Tax Exemptions** — tax-exempt certificates
- **Processor Links** — payment processor connections

## Searching

Use the search bar to find accounts by name, email, phone, or account number. You can also find accounts by searching for a member's name.

## Account Numbers

Every account gets a unique 6-digit number automatically. This number appears in the account list and can be used for quick lookup.
    `.trim(),
  },
  {
    slug: 'members-overview',
    title: 'Members Overview',
    category: 'Accounts',
    content: `
# Members

A **member** is an individual person associated with an account. This could be a parent, a child, a student, a staff member — anyone who takes lessons, uses services, or needs to be tracked.

## Adding a Member

1. Go to an account's **Members** tab
2. Click **Add Member**
3. Enter first and last name (required)
4. Optionally add email, phone, date of birth
5. Click **Add Member**

**Tip:** If you don't provide email, phone, or address, the member will automatically inherit these from the account.

## Minor Flag

If a member is under 18, they're flagged as a **Minor**. This happens automatically if you enter a date of birth. If the family prefers not to share a birthday, you can check the "This person is a minor" box instead.

## Member Numbers

Like accounts, every member gets a unique 6-digit number for quick reference.

## Finding Members

Use the **Members** page in the sidebar to search across all members in all accounts. Click a member to go to their account.

## Moving a Member

If a member needs to be moved to a different account (e.g. a student aging out and getting their own account), ask your administrator — members can be reassigned between accounts.
    `.trim(),
  },
  {
    slug: 'payment-methods',
    title: 'Payment Methods',
    category: 'Accounts',
    content: `
# Payment Methods

Payment methods are cards on file for an account. These are used for recurring billing (rentals, lessons) and in-store purchases.

## Adding a Payment Method

1. Go to an account's **Payment Methods** tab
2. Click **Add Method**
3. Select the processor (Stripe or Global Payments)
4. Enter the payment method ID from the processor
5. Optionally enter card brand, last four digits, and expiration
6. Click **Add Payment Method**

**Note:** Card details are stored securely with the payment processor — LunarFront only keeps a reference and display info (last 4 digits, brand).

## Default Payment Method

One payment method can be marked as the **default**. Click the star icon next to a method to make it the default. The previous default is automatically unset.

## Needs Update Flag

If a payment method was migrated from an old system, it may show a "Needs Update" badge. This means the customer needs to re-enter their card information.
    `.trim(),
  },
  {
    slug: 'tax-exemptions',
    title: 'Tax Exemptions',
    category: 'Accounts',
    content: `
# Tax Exemptions

Schools, churches, and resellers may be exempt from sales tax. LunarFront tracks tax exemption certificates per account.

## Adding a Tax Exemption

1. Go to an account's **Tax Exemptions** tab
2. Click **Add Exemption**
3. Enter the certificate number (required)
4. Optionally add certificate type (e.g. "resale"), issuing state, and expiration date
5. Click **Add Tax Exemption**

The exemption starts in **Pending** status.

## Approving an Exemption

A manager must verify the certificate and approve it:

1. Click the **check mark** icon next to a pending exemption
2. The status changes to **Approved**

## Revoking an Exemption

If a certificate expires or is no longer valid:

1. Click the **X** icon next to an approved exemption
2. Enter a reason for revoking
3. The status changes back to **None**

All approvals and revocations are logged with who did it and when.
    `.trim(),
  },
  {
    slug: 'member-ids',
    title: 'Identity Documents',
    category: 'Accounts',
    content: `
# Identity Documents

You can store identity documents (driver's license, passport, school ID) for any member. This is useful for verifying identity during pickups, rentals, or trade-ins.

## Adding an ID

1. Go to an account's **Members** tab
2. Click the arrow next to a member to expand their row, or click the three-dot menu and choose **Edit**
3. In the Identity Documents section, click **Add ID**
4. Select the ID type
5. Enter the ID number
6. Optionally add issuing authority, dates, and upload images of the front and back
7. Click **Add ID**

## ID Types

- **Driver's License / State ID** — most common for adult customers
- **Passport** — for international customers or as secondary ID
- **School ID** — for student members

## Images

You can upload photos of the front and back of the ID. These are stored securely and are only visible to staff. Use your phone's camera or a scanner.

## Primary ID

If a member has multiple IDs, mark one as **Primary** — this is the one shown by default in quick lookups.
    `.trim(),
  },
  {
    slug: 'users-roles',
    title: 'Users & Roles',
    category: 'Admin',
    content: `
# Users & Roles

LunarFront uses a permission-based access control system. **Permissions** are specific actions (like "view accounts" or "edit inventory"). **Roles** are named groups of permissions that you assign to users.

## Managing Users

Go to **Users** in the Admin section of the sidebar.

- View all staff accounts with their assigned roles
- Click the three-dot menu on a user to:
  - **Manage Roles** — add or remove roles
  - **Reset Password Link** — generates a secure one-time link (expires in 1 hour) that you can send to the user

## Managing Roles

Go to **Roles** in the Admin section.

- View all roles (system defaults + custom roles you've created)
- **System roles** (Admin, Manager, Sales Associate, etc.) come pre-configured but you can modify their permissions
- Click a role to edit its permissions
- Click **New Role** to create a custom role

## How Permissions Work

Permissions are organized by area:

- **Accounts** — view, edit, admin
- **Inventory** — view, edit, admin
- **Lessons, Repairs** — each has view, edit, admin

**Permission inheritance:** If a role has **admin** permission for an area, it automatically includes **edit** and **view** too. If it has **edit**, it includes **view**.

## Creating a Custom Role

1. Go to **Roles** → **New Role**
2. Enter a name (e.g. "School Sales Rep")
3. Check the permissions this role needs
4. Click **Create Role**
5. Go to **Users** → assign the new role to staff members

## Multiple Roles

A user can have multiple roles. Their effective permissions are the combination of all their roles. For example, a user with "Sales Associate" + "Repair Viewer" can do everything a sales associate can, plus view repair tickets.
    `.trim(),
  },
  {
    slug: 'profile-settings',
    title: 'Your Profile',
    category: 'General',
    content: `
# Your Profile

Click your name at the bottom of the sidebar to access your profile.

## Editing Your Name

You can update your first and last name. Click **Save** to apply changes.

## Changing Your Password

1. Enter your current password
2. Enter a new password (at least 12 characters)
3. Confirm the new password
4. Click **Change Password**

## Appearance

Choose your preferred mode and color theme:

- **Mode** — Light, Dark, or System (follows your device setting)
- **Color Theme** — Slate, Emerald, Violet, Amber, or Rose

Your preferences are saved in your browser and persist across sessions.
    `.trim(),
  },
  {
    slug: 'repairs-overview',
    title: 'Repairs Overview',
    category: 'Repairs',
    content: `
# Repairs

The Repairs module tracks repair tickets from intake through completion. It supports walk-in customers, account-linked repairs, and bulk school batch jobs.

## Creating a Repair Ticket

1. Go to **Repairs** in the sidebar
2. Click **New Repair**
3. Search for an existing account or enter customer details manually for walk-ins
4. Describe the item and the problem
5. Optionally add line items for the estimate (use templates for common services)
6. Add intake photos to document the item's condition
7. Click **Create Ticket**

## Ticket Status Flow

Each ticket moves through these stages:

- **New** — ticket just created, not yet examined
- **In Transit** — item being transported to the shop (for pickups or shipped items)
- **Intake** — item received, condition documented
- **Diagnosing** — technician examining the item
- **Pending Approval** — estimate provided, waiting for customer OK
- **Approved** — customer authorized the work
- **In Progress** — actively being repaired
- **Pending Parts** — waiting on parts order
- **Ready** — repair complete, awaiting pickup
- **Picked Up** — customer collected the item
- **Delivered** — item returned via delivery (for school batches)

Click the status buttons on the ticket detail page to advance through the workflow. You can also click steps on the progress bar.

## Ticket Detail Page

The ticket detail has four tabs:

- **Details** — customer info, item, condition, costs. Click **Edit** to modify.
- **Line Items** — labor, parts, flat-rate services, and misc charges. Use the template picker for common repairs.
- **Notes** — running journal of notes. Choose **Internal** (staff only) or **Customer Visible**. You can attach photos to notes.
- **Photos & Docs** — photos organized by repair phase (intake, in progress, completed) plus a documents section for signed approvals, quotes, and receipts.

## Generating a PDF

Click the **PDF** button in the ticket header to generate a customer-facing document:

1. Choose whether to include line items
2. Select which customer-visible notes to include
3. Select which photos to include
4. Click **Generate & Download PDF**

The PDF is both downloaded and automatically saved to the ticket's Documents section.
    `.trim(),
  },
  {
    slug: 'repair-templates',
    title: 'Repair Templates',
    category: 'Repairs',
    content: `
# Repair Service Templates

Templates are pre-defined common repairs (e.g. "Bow Rehair — Violin — 4/4") that staff can quickly add to tickets instead of typing everything manually.

## Managing Templates

1. Go to **Repair Templates** in the sidebar (admin only)
2. Click **New Template**
3. Fill in:
   - **Name** — e.g. "Bow Rehair", "String Change", "Valve Overhaul"
   - **Item Category** — e.g. "Violin", "Guitar", "Trumpet"
   - **Size** — e.g. "4/4", "3/4", "Full"
   - **Type** — Labor, Part, Flat Rate, or Misc
   - **Default Price** — the customer-facing price
   - **Internal Cost** — your cost (for margin tracking)
4. Click **Create Template**

## Using Templates

When creating a ticket or adding line items, type in the **Quick Add from Template** search box. Select a template to auto-fill the type, description, and price. You can modify the values after selection.

## Examples

- Bow Rehair — Violin — 4/4 — $65
- Bow Rehair — Cello — $80
- String Change — Guitar — $25
- Valve Overhaul — Trumpet — $85
- Pad Replacement — Clarinet — $120
- Cork Replacement — Clarinet — $45
    `.trim(),
  },
  {
    slug: 'repair-batches',
    title: 'Repair Batches',
    category: 'Repairs',
    content: `
# Repair Batches

Batches group multiple repair tickets under one job — typically for schools bringing in many items at once.

## Creating a Batch

1. Go to **Repair Batches** in the sidebar
2. Click **New Batch**
3. Select the school's account
4. Enter contact info, item count, and any notes
5. Click **Create Batch**

## Adding Tickets to a Batch

When creating new repair tickets, select the batch in the form. Each item gets its own ticket linked to the batch.

## Batch Approval

Batches have a separate approval workflow:

- **Pending** — batch created, not yet approved
- **Approved** — work authorized (click **Approve** on the batch detail page)
- **Rejected** — work declined

Only admins can approve or reject batches.

## Batch Status

- **Intake** — receiving items
- **In Progress** — work underway
- **Completed** — all repairs done
- **Delivered** — items returned to customer

## Filtering

On the Repairs list, use the **Filters** panel to:

- Toggle **Batch only** to see only batch tickets
- Toggle **Individual only** to see only non-batch tickets
    `.trim(),
  },
  {
    slug: 'repair-notes-photos',
    title: 'Notes & Photos',
    category: 'Repairs',
    content: `
# Repair Notes & Photos

## Notes

Notes are a running journal on each repair ticket. Every note records who wrote it, when, and what status the ticket was in at the time.

**Visibility options:**

- **Internal** — only visible to staff. Use for technician observations, internal discussions, customer contact notes (e.g. "Called customer, approved via phone").
- **Customer Visible** — will appear in PDFs and (eventually) the customer portal. Use for lesson summaries, work completed descriptions, and pickup instructions.

**Attaching photos to notes:**

1. Click **Attach Photo** in the note form
2. Select one or more images
3. Preview appears below the text area
4. Click **Post Note** — photos upload with the note

Photos appear inline in the note entry. Click to view full size.

## Photos by Phase

The Photos & Docs tab organizes photos into categories:

- **Intake Photos** — document item condition when received
- **Work in Progress** — during the repair
- **Completed** — final result after repair
- **Documents** — signed approvals, quotes, receipts (accepts PDFs)

The active category highlights based on the ticket's current status, so the most relevant section is always prominent.

## Signed Approvals

For pending approval tickets, you can:

1. Generate a PDF quote (via the PDF button)
2. Send it to the customer
3. When they approve, upload the signed copy to Documents
4. Or add a note: "Customer approved via phone call on [date]"
5. Then move the ticket to **Approved** status
    `.trim(),
  },
  {
    slug: 'lessons-overview',
    title: 'Lessons Overview',
    category: 'Lessons',
    content: `
# Lessons

The Lessons module manages music instruction — instructors, schedules, student enrollments, individual sessions, and lesson plans with grading.

## Module Setup

Before using Lessons, an admin must enable the module in **Admin → Modules**.

## Core Concepts

- **Lesson Types** — the kinds of lessons you offer (e.g. "30-min Piano", "1-hr Guitar"). Each has default rates.
- **Instructors** — staff members who teach. Each instructor has their own schedule slots.
- **Schedule Slots** — recurring time blocks when an instructor is available (e.g. Mondays 3–5 PM). Slots can override the lesson type's default rates.
- **Enrollments** — a student (member) assigned to a specific slot with agreed billing terms.
- **Sessions** — individual lesson occurrences generated from enrollments. Each session is marked attended, missed, cancelled, or makeup.
- **Lesson Plans** — per-student curriculum tracking with goals, notes, and graded progress.

## Typical Workflow

1. Create **Lesson Types** with default rates
2. Add **Instructors**
3. Create **Schedule Slots** for each instructor
4. **Enroll** students into slots — set billing cycle and rate
5. Sessions are created automatically on a weekly basis
6. After each lesson, mark the session **Attended** (or Missed/Cancelled) and add notes
7. Track progress via the student's **Lesson Plan**
    `.trim(),
  },
  {
    slug: 'lesson-types',
    title: 'Lesson Types',
    category: 'Lessons',
    content: `
# Lesson Types

Lesson types define what you teach and your default rates. Examples: "30-min Piano", "1-hr Guitar", "Group Drum — 45 min".

## Creating a Lesson Type

1. Go to **Lessons → Lesson Types**
2. Click **New Lesson Type**
3. Enter a name and optional description
4. Set default rates for each billing cycle:
   - **Weekly** — billed every week
   - **Monthly** — billed once a month
   - **Quarterly** — billed every 3 months
5. Click **Create**

Rates here are defaults — individual schedule slots (and enrollments) can override them.

## Editing Rates

Click any lesson type to edit it. Rate changes only affect new enrollments — existing enrollments keep their agreed rate unless you manually update them.
    `.trim(),
  },
  {
    slug: 'instructors',
    title: 'Instructors',
    category: 'Lessons',
    content: `
# Instructors

Instructors are the teachers in your system. Each instructor has a display name, contact info, and their own set of schedule slots.

## Adding an Instructor

1. Go to **Lessons → Instructors**
2. Click **New Instructor**
3. Enter the display name (shown everywhere in the UI), email, and optional phone
4. Click **Create**

## Instructor Detail

Click an instructor to see their profile and all their schedule slots.

## Deactivating an Instructor

If an instructor leaves, you can mark them inactive. Their existing enrollments and session history are preserved — they just won't appear in dropdowns for new enrollments.
    `.trim(),
  },
  {
    slug: 'schedule-slots',
    title: 'Schedule Slots',
    category: 'Lessons',
    content: `
# Schedule Slots

A schedule slot is a recurring time block when an instructor teaches — for example, "Mondays 4:00–4:30 PM with Sarah Chen, Piano".

## Creating a Slot

1. Go to **Lessons → Instructors** → click an instructor
2. Click **Add Slot**, or go to **Lessons → Schedule** → **New Slot**
3. Select:
   - **Lesson Type**
   - **Day of week**
   - **Start time** and **End time**
4. Optionally set **instructor rate overrides** for this specific slot:
   - These override the lesson type's default rates for students in this slot
   - Leave blank to use the lesson type defaults
5. Click **Create**

## Rate Override Logic

When enrolling a student, the rate auto-fills based on this priority:

1. Slot's rate for the chosen billing cycle (if set)
2. Lesson type's rate for that cycle
3. Manual entry (if neither is set)

## Blocked Dates

Use **Lessons → Blocked Dates** to mark days when lessons don't occur (holidays, school breaks). Sessions on blocked dates are automatically marked cancelled.
    `.trim(),
  },
  {
    slug: 'enrollments',
    title: 'Enrollments',
    category: 'Lessons',
    content: `
# Enrollments

An enrollment connects a student (member) to a schedule slot with agreed billing terms.

## Creating an Enrollment

1. Go to **Lessons → Enrollments → New Enrollment**
2. Select the **member** (student)
3. Select the **instructor** and **schedule slot**
4. Set the **billing cycle**:
   - Choose the interval (e.g. 1) and unit (week / month / quarter / year)
   - The rate field auto-fills from the slot or lesson type — you can override it manually
5. Set the **start date**
6. Click **Create Enrollment**

## Enrollment Statuses

- **Active** — student is actively taking lessons; sessions are being generated
- **Paused** — temporarily on hold (e.g. summer break); no new sessions generated
- **Cancelled** — permanently ended
- **Completed** — finished the curriculum

## Changing Status

Open the enrollment and use the status dropdown. Adding a note when pausing or cancelling is recommended.

## Billing Terms

The **rate** and **billing cycle** represent what the customer agreed to pay. These don't connect to payment processing automatically — they're for reference when generating invoices.
    `.trim(),
  },
  {
    slug: 'sessions',
    title: 'Sessions',
    category: 'Lessons',
    content: `
# Sessions

A session is one instance of a lesson. Sessions are generated automatically from active enrollments based on their schedule slot's day and time.

## Viewing Sessions

- **Lessons → Sessions** — list view with search and filters, or week view showing all sessions on a calendar grid
- Use the **instructor filter** in the week view to focus on one teacher's schedule
- Use the **status filter** in list view to find missed or upcoming sessions

## Session Statuses

- **Scheduled** — upcoming, not yet occurred
- **Attended** — lesson took place
- **Missed** — student didn't show
- **Cancelled** — lesson was cancelled (instructor unavailable, holiday, etc.)
- **Makeup** — a makeup session for a previously missed lesson

## Recording a Session

1. Click on a session (from the list or week view)
2. Update the status (Attended, Missed, etc.)
3. Add session notes — these feed into the student's lesson plan
4. Click **Save**

## Makeup Sessions

If a student misses a session, you can schedule a makeup:

1. Open the missed session
2. Click **Schedule Makeup**
3. Choose a date and time
4. A new session is created with status **Makeup** linked to the original

## Notes

Session notes are visible on the session detail page and also appear in the student's lesson plan history. Use them to record what was covered, what to practice, and any concerns.
    `.trim(),
  },
  {
    slug: 'lesson-plans',
    title: 'Lesson Plans & Grading',
    category: 'Lessons',
    content: `
# Lesson Plans & Grading

Lesson plans track a student's curriculum, goals, and progress over time.

## Grading Scales

Before using grading, set up a grading scale in **Lessons → Grading Scales**. A scale defines the grades available (e.g. 1–5, A–F, or custom labels like "Needs Work / Developing / Proficient / Mastered").

## Lesson Plan Templates

Templates define a standard curriculum that can be applied to students. Go to **Lessons → Plan Templates** to create reusable outlines with goals organized by category.

## Student Lesson Plans

Each active enrollment can have a lesson plan. To view or edit a student's plan:

1. Go to the member's detail page → **Enrollments** tab
2. Click the enrollment → **Lesson Plan** tab

Or go to **Lessons → Lesson Plans** and search by student name.

## Recording Progress

On the lesson plan detail page:

1. Click **Add Grade Entry**
2. Select the goal or skill being assessed
3. Choose the grade from your scale
4. Add optional notes
5. Click **Save**

Grade history is shown as a timeline so you can see improvement over time.

## Goals

Goals are the specific skills or pieces being tracked (e.g. "C Major Scale", "Correct bow hold", "Sight reading level 2"). Goals come from the plan template but can be customized per student.
    `.trim(),
  },
]

export function getWikiPages(): WikiPage[] {
  return pages
}

export function getWikiPage(slug: string): WikiPage | undefined {
  return pages.find((p) => p.slug === slug)
}

export function getWikiCategories(): WikiCategory[] {
  const categoryMap = new Map<string, WikiPage[]>()
  for (const page of pages) {
    const existing = categoryMap.get(page.category) ?? []
    existing.push(page)
    categoryMap.set(page.category, existing)
  }
  return Array.from(categoryMap.entries()).map(([name, pages]) => ({ name, pages }))
}
