export function splitGradeName(gradeName: string | null | undefined) {
  const normalized = gradeName?.trim();
  if (!normalized) {
    return {
      gradeName: "-",
      itemTypeName: "-",
      itemGradeName: "-"
    };
  }

  const [firstPart, ...remainingParts] = normalized.split(" / ");

  return {
    gradeName: normalized,
    itemTypeName: firstPart?.trim() || normalized,
    itemGradeName: remainingParts.join(" / ").trim() || normalized
  };
}

export function composeGradeLabel(
  itemTypeName: string | null | undefined,
  itemGradeName: string | null | undefined
) {
  const type = itemTypeName?.trim() || "-";
  const grade = itemGradeName?.trim() || "";

  if (!grade || grade === "-" || grade === type) {
    return type;
  }

  return `${type} / ${grade}`;
}
