/** 展示用：优先顶层合并医嘱，fallback content 纯医嘱 */
export function formatDoctorOrderText(
  item?: {
    doctor_order?: string | string[];
    content?: { doctor_order?: string };
  } | null,
): string {
  const raw = item?.doctor_order ?? item?.content?.doctor_order ?? '';
  if (Array.isArray(raw)) {
    const list = raw.map((s) => String(s).trim()).filter(Boolean);
    return list.length ? list.join('；') : '-';
  }
  const parts = String(raw)
    .split('|')
    .map((s) => s.trim())
    .filter(Boolean);
  return parts.length ? parts.join('；') : raw ? String(raw) : '-';
}

/** 复用开方输入框：detail.doctor_order 为数组时转回字符串 */
export function detailDoctorOrderToText(
  doctorOrder?: string | string[] | null,
): string {
  if (Array.isArray(doctorOrder)) {
    return doctorOrder.map((s) => String(s).trim()).filter(Boolean).join('|');
  }
  return doctorOrder ?? '';
}
