'use client'
import CodeMirror from '@uiw/react-codemirror'
import { caddyfileLanguage } from '@/lib/codemirror/caddyfile-mode'
import { EditorView } from '@codemirror/view'

type Props = {
  value: string
  onChange: (next: string) => void
  readOnly?: boolean
}

export default function CaddyCodeMirror({ value, onChange, readOnly }: Props) {
  return (
    <CodeMirror
      value={value}
      onChange={onChange}
      readOnly={readOnly}
      extensions={[caddyfileLanguage, EditorView.lineWrapping]}
      theme="dark"
      height="480px"
      basicSetup={{ lineNumbers: true, foldGutter: false, highlightActiveLine: !readOnly }}
      className="rounded-lg border border-border overflow-hidden text-xs"
    />
  )
}
