"use client"; import React from "react"; import { Star } from "lucide-react"; /** Field types added for feedback (also usable on attendee forms). */ export const EXTRA_FIELD_TYPES = ["rating", "multiple_choice"] as const; export const isExtraFieldType = (t: string) => (EXTRA_FIELD_TYPES as readonly string[]).includes(t); /** The choices of a multiple-choice field (stored as a JSON array of strings). */ export const fieldChoices = (field: { options?: unknown }): string[] => Array.isArray(field.options) ? field.options.map(String).filter(Boolean) : []; /** * Input for a rating (1–5 stars) or multiple-choice field. Values are strings, like every * other form answer: "1".."5" for a rating, the chosen option for multiple choice. */ export function ExtraFieldInput({ field, value, onChange, idPrefix = "f" }: { field: { id?: string; type: string; label: string; options?: unknown }; value: string; onChange: (v: string) => void; idPrefix?: string; }) { if (field.type === "rating") { const n = Number(value) || 0; return (
{[1, 2, 3, 4, 5].map(star => ( ))} {n > 0 && {n} of 5}
); } const choices = fieldChoices(field); return (
{choices.map(c => ( ))}
); } /** Builder controls for a multiple-choice field's options (one per line). */ export function ChoicesEditor({ options, onChange }: { options: unknown; onChange: (opts: string[]) => void }) { const text = Array.isArray(options) ? options.join("\n") : ""; return (