import { Plus, X } from "lucide-react";
import { compactQuestions } from "./utils";
interface BusinessQuestionsEditorProps {
value: string[];
onChange: (questions: string[]) => void;
disabled?: boolean;
}
export function BusinessQuestionsEditor({ value, onChange, disabled }: BusinessQuestionsEditorProps) {
const questions = value.length ? value : [""];
const update = (index: number, next: string) => {
const copy = [...questions];
copy[index] = next;
onChange(copy);
};
const remove = (index: number) => {
if (questions.length <= 2) return;
const next = questions.filter((_, i) => i !== index);
onChange(next.length ? next : [""]);
};
const canAdd = questions.length < 5;
const canRemove = questions.length > 2;
return (
{canAdd && (
)}
{questions.map((question, index) => (
update(index, event.target.value)}
disabled={disabled}
placeholder={index === 0 ? "What should this analysis answer?" : "Add another question"}
className="min-w-0 flex-1 rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-800 outline-none transition placeholder:text-slate-400 focus:border-emerald-500 focus:ring-2 focus:ring-emerald-100 disabled:bg-slate-50"
/>
{canRemove && (
)}
))}
{compactQuestions(questions).length < 2 &&
Add at least 2 questions (max 5).
}
);
}