import { FormField, Input, Select } from '@cameleer/design-system';
import type { FormState } from '../form-state';

export function AgentStateForm({ form, setForm }: { form: FormState; setForm: (f: FormState) => void }) {
  const c = form.condition as Record<string, unknown>;
  const patch = (p: Record<string, unknown>) =>
    setForm({ ...form, condition: { ...(form.condition as Record<string, unknown>), ...p } as FormState['condition'] });

  return (
    <>
      <FormField label="Agent state">
        <Select
          value={(c.state as string) ?? 'DEAD'}
          onChange={(e) => patch({ state: e.target.value })}
          options={[
            { value: 'DEAD', label: 'DEAD' },
            { value: 'STALE', label: 'STALE' },
          ]}
        />
      </FormField>
      <FormField label="For duration (seconds)">
        <Input
          type="number"
          value={(c.forSeconds as number | undefined) ?? 60}
          onChange={(e) => patch({ forSeconds: Number(e.target.value) })}
        />
      </FormField>
    </>
  );
}
