/**
 * Project Code dropdown (issue #124) — a native <select name="projectCode">
 * carrying the fixed `PROJECT_CODES` list plus an empty "— none —" option
 * (the field stays optional). Plain HTML so it works with the forms' native
 * FormData submission (no client state needed), matching DeliveryLocationField.
 *
 * `current` is the PO's existing project code; if it isn't one of the fixed
 * options (legacy / imported / a since-removed code) it is preserved as a
 * leading "(current)" option so an edit never silently drops it.
 */
import { PROJECT_CODES } from "@/lib/validations/po";

export function ProjectCodeField({
  current,
  className,
}: {
  current?: string | null;
  className?: string;
}) {
  const cur = (current ?? "").trim();
  const currentMissing = cur.length > 0 && !(PROJECT_CODES as readonly string[]).includes(cur);

  return (
    <select name="projectCode" defaultValue={cur} className={className}>
      <option value="">— none —</option>
      {currentMissing && <option value={cur}>{cur} (current)</option>}
      {PROJECT_CODES.map((code) => (
        <option key={code} value={code}>
          {code}
        </option>
      ))}
    </select>
  );
}
