import { useState } from 'react'
import { Check } from 'lucide-react'
import { cn } from '@/lib/utils'
import type { StepOptionSchema } from '@/types/ai-session'

interface FlowPilotOptionsProps {
  options: StepOptionSchema[]
  onSelect: (value: string) => void
  disabled?: boolean
}

export function FlowPilotOptions({ options, onSelect, disabled }: FlowPilotOptionsProps) {
  const [selected, setSelected] = useState<string | null>(null)

  const handleSelect = (value: string) => {
    if (disabled) return
    setSelected(value)
    onSelect(value)
  }

  return (
    <div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
      {options.map((option) => {
        const isSelected = selected === option.value
        return (
          <button
            key={option.value}
            onClick={() => handleSelect(option.value)}
            disabled={disabled}
            className={cn(
              'group relative rounded-xl border p-3 sm:p-4 text-left transition-all min-h-[44px]',
              'hover:border-[rgba(96,165,250,0.3)] hover:shadow-[0_0_20px_rgba(96,165,250,0.08)]',
              'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40',
              isSelected
                ? 'border-primary/40 bg-accent-dim'
                : 'border-border bg-card/50',
              disabled && 'pointer-events-none opacity-60'
            )}
          >
            <div className="flex items-start justify-between gap-3">
              <div className="flex-1">
                <p className="text-sm font-medium text-foreground">{option.label}</p>
                {option.followup_hint && (
                  <p className="mt-1 text-xs text-muted-foreground">{option.followup_hint}</p>
                )}
              </div>
              {isSelected && (
                <span className="flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-primary/20 text-primary">
                  <Check size={12} />
                </span>
              )}
            </div>
          </button>
        )
      })}
    </div>
  )
}
