import type { Case } from '@/types'

export type FieldType = 'text' | 'date' | 'boolean' | 'select' | 'textarea'

export interface FieldConfig {
  key: keyof Case
  label: string
  type: FieldType
  colSpan?: 1 | 2
  editableBy: 'admin' | 'all'
  visibleTo?: 'admin' | 'all'
  placeholder?: string
  options?: { value: string; label: string }[]
}

export interface SectionConfig {
  title: string
  fields: FieldConfig[]
  visibleTo?: 'admin' | 'all'
}

const ANREDE_OPTIONS = [
  { value: '__none__', label: '–' },
  { value: 'Herr', label: 'Herr' },
  { value: 'Frau', label: 'Frau' },
  { value: 'Divers', label: 'Divers' },
]

export const CASE_SECTIONS: SectionConfig[] = [
  {
    title: 'Persönliche Daten',
    fields: [
      { key: 'anrede', label: 'Anrede', type: 'select', editableBy: 'admin', visibleTo: 'admin', options: ANREDE_OPTIONS },
      { key: 'vorname', label: 'Vorname', type: 'text', editableBy: 'admin', visibleTo: 'admin', placeholder: 'Vorname' },
      { key: 'nachname', label: 'Nachname', type: 'text', editableBy: 'admin', visibleTo: 'admin', placeholder: 'Nachname' },
      { key: 'geburtsdatum', label: 'Geburtsdatum', type: 'date', editableBy: 'admin', visibleTo: 'admin' },
      { key: 'kvnr', label: 'KVNR', type: 'text', editableBy: 'all', placeholder: 'z.B. A123456789' },
      { key: 'versicherung', label: 'Versicherung', type: 'text', editableBy: 'admin', placeholder: 'z.B. DAK' },
    ],
  },
  {
    title: 'Kontakt', visibleTo: 'admin',
    fields: [
      { key: 'strasse', label: 'Straße', type: 'text', editableBy: 'admin', placeholder: 'Straße + Nr.' },
      { key: 'plz', label: 'PLZ', type: 'text', editableBy: 'admin', placeholder: 'PLZ' },
      { key: 'ort', label: 'Ort', type: 'text', editableBy: 'admin', placeholder: 'Ort' },
      { key: 'email', label: 'E-Mail', type: 'text', editableBy: 'admin', placeholder: 'E-Mail' },
      { key: 'telefonnummer', label: 'Telefon', type: 'text', editableBy: 'admin', placeholder: 'Telefonnummer' },
      { key: 'mobiltelefon', label: 'Mobil', type: 'text', editableBy: 'admin', placeholder: 'Mobilnummer' },
      { key: 'ansprechpartner', label: 'Ansprechpartner', type: 'text', editableBy: 'admin', colSpan: 2, placeholder: 'Ansprechpartner' },
    ],
  },
  {
    title: 'Falldetails', visibleTo: 'admin',
    fields: [
      { key: 'kurzbeschreibung', label: 'Kurzbeschreibung', type: 'textarea', editableBy: 'admin', colSpan: 2 },
      { key: 'fragestellung', label: 'Fragestellung', type: 'textarea', editableBy: 'admin', colSpan: 2 },
      { key: 'kommentar', label: 'Kommentar', type: 'textarea', editableBy: 'admin', colSpan: 2 },
      { key: 'sonstiges', label: 'Sonstiges', type: 'textarea', editableBy: 'admin', colSpan: 2 },
    ],
  },
  {
    title: 'Unterlagen', visibleTo: 'admin',
    fields: [
      { key: 'unterlagen', label: 'Unterlagen vorhanden', type: 'boolean', editableBy: 'admin' },
      { key: 'erhalten', label: 'Erhalten', type: 'boolean', editableBy: 'admin' },
      { key: 'unterlagen_verschickt', label: 'Verschickt am', type: 'date', editableBy: 'admin' },
      { key: 'unterlagen_erhalten', label: 'Erhalten am', type: 'date', editableBy: 'admin' },
      { key: 'unterlagen_an_gutachter', label: 'An Gutachter am', type: 'date', editableBy: 'admin' },
    ],
  },
  {
    title: 'Gutachten', visibleTo: 'admin',
    fields: [
      { key: 'gutachten', label: 'Gutachten vorhanden', type: 'boolean', editableBy: 'admin' },
      { key: 'gutachter', label: 'Gutachter', type: 'text', editableBy: 'admin', placeholder: 'Name des Gutachters' },
      { key: 'gutachten_erstellt', label: 'Erstellt am', type: 'date', editableBy: 'admin' },
      { key: 'gutachten_versendet', label: 'Versendet am', type: 'date', editableBy: 'admin' },
      { key: 'schweigepflicht', label: 'Schweigepflichtentbindung', type: 'boolean', editableBy: 'admin' },
    ],
  },
  {
    title: 'Status', visibleTo: 'admin',
    fields: [
      { key: 'ablehnung', label: 'Ablehnung', type: 'boolean', editableBy: 'admin' },
      { key: 'abbruch', label: 'Abbruch', type: 'boolean', editableBy: 'admin' },
      { key: 'abbruch_datum', label: 'Abbruch-Datum', type: 'date', editableBy: 'admin' },
    ],
  },
  {
    title: 'Abrechnung', visibleTo: 'admin',
    fields: [
      { key: 'abgerechnet', label: 'Abgerechnet', type: 'boolean', editableBy: 'admin' },
      { key: 'abrechnung_datum', label: 'Abrechnungsdatum', type: 'date', editableBy: 'admin' },
    ],
  },
]
