'use client'

import React from 'react'
import type { StepProps } from '../_types'
import { CONTRACT_TILES } from '../_tiles'
import { toggleInArray } from '../_data'

export function Step8Contracts({ form, updateForm }: StepProps) {
  return (
    <div className="space-y-6">
      <h2 className="text-lg font-semibold text-gray-900">Vertraege & Compliance-Dokumentation</h2>
      <p className="text-sm text-gray-500">Welche Compliance-Dokumente liegen bereits vor? (Mehrfachauswahl moeglich)</p>

      <div className="grid grid-cols-2 md:grid-cols-3 gap-3">
        {CONTRACT_TILES.map(item => (
          <button
            key={item.value}
            type="button"
            onClick={() => updateForm({ contracts: toggleInArray(form.contracts, item.value) })}
            className={`p-3 rounded-xl border-2 text-left transition-all ${
              form.contracts.includes(item.value)
                ? item.value === 'none'
                  ? 'border-amber-500 bg-amber-50 ring-1 ring-amber-300'
                  : 'border-purple-500 bg-purple-50 ring-1 ring-purple-300'
                : 'border-gray-200 hover:border-purple-300 hover:bg-gray-50'
            }`}
          >
            <div className="flex items-center gap-2 mb-1">
              <span className="text-lg">{item.icon}</span>
              <span className="text-sm font-medium text-gray-900">{item.label}</span>
            </div>
            <p className="text-xs text-gray-500 leading-tight">{item.desc}</p>
          </button>
        ))}
      </div>

      <div>
        <label className="block text-sm font-medium text-gray-700 mb-1">Subprozessoren (optional)</label>
        <textarea
          value={form.subprocessors}
          onChange={e => updateForm({ subprocessors: e.target.value })}
          rows={2}
          placeholder="z.B. OpenAI (USA, SCC), Hetzner Cloud (DE)..."
          className="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500 focus:border-transparent"
        />
      </div>
    </div>
  )
}
