'use client'

import { DSRSource } from '@/lib/sdk/dsr/types'

const SOURCES: { value: DSRSource; label: string; icon: string }[] = [
  { value: 'web_form', label: 'Webformular', icon: 'M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9' },
  { value: 'email', label: 'E-Mail', icon: 'M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z' },
  { value: 'letter', label: 'Brief', icon: 'M3 19v-8.93a2 2 0 01.89-1.664l7-4.666a2 2 0 012.22 0l7 4.666A2 2 0 0121 10.07V19M3 19a2 2 0 002 2h14a2 2 0 002-2M3 19l6.75-4.5M21 19l-6.75-4.5M3 10l6.75 4.5M21 10l-6.75 4.5' },
  { value: 'phone', label: 'Telefon', icon: 'M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z' },
  { value: 'in_person', label: 'Persoenlich', icon: 'M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z' },
  { value: 'other', label: 'Sonstiges', icon: 'M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z' }
]

export function SourceSelector({
  selectedSource,
  sourceDetails,
  onSourceChange,
  onDetailsChange
}: {
  selectedSource: DSRSource | ''
  sourceDetails: string
  onSourceChange: (source: DSRSource) => void
  onDetailsChange: (details: string) => void
}) {
  return (
    <div className="space-y-3">
      <label className="block text-sm font-medium text-gray-700">
        Quelle der Anfrage <span className="text-red-500">*</span>
      </label>
      <div className="grid grid-cols-3 md:grid-cols-6 gap-2">
        {SOURCES.map(source => (
          <button
            key={source.value}
            type="button"
            onClick={() => onSourceChange(source.value)}
            className={`
              p-3 rounded-xl border-2 text-center transition-all
              ${selectedSource === source.value
                ? 'border-purple-500 bg-purple-50'
                : 'border-gray-200 hover:border-gray-300'
              }
            `}
          >
            <svg
              className={`w-6 h-6 mx-auto ${selectedSource === source.value ? 'text-purple-600' : 'text-gray-400'}`}
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d={source.icon} />
            </svg>
            <div className={`text-xs mt-1 ${selectedSource === source.value ? 'text-purple-600 font-medium' : 'text-gray-500'}`}>
              {source.label}
            </div>
          </button>
        ))}
      </div>
      {selectedSource && (
        <input
          type="text"
          value={sourceDetails}
          onChange={(e) => onDetailsChange(e.target.value)}
          placeholder={
            selectedSource === 'web_form' ? 'z.B. Kontaktformular auf website.de' :
            selectedSource === 'email' ? 'z.B. info@firma.de' :
            selectedSource === 'phone' ? 'z.B. Anruf am 22.01.2025' :
            'Weitere Details zur Quelle'
          }
          className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500"
        />
      )}
    </div>
  )
}
