
const getReopenReason = (id: any) => {
    const reopenReasons = [
      {id: 1, title: "Problem not fixed", description: "The original issue still exists exactly as it was."},
      {id: 2, title: "Issue returned", description: "The repair worked for a short time but the problem has come back."},
      {id: 3, title: "Partial repair", description: "Only one part of the problem was fixed, but others were ignored."},
      {id: 4, title: "Staff never showed up", description: "The ticket was marked resolved, but no one visited the property."},
      {id: 5, title: "Incomplete work", description: "The technician left before finishing the job (e.g., waiting for parts or left a mess)."},
      {id: 6, title: "Poor quality of work", description: "The repair was done unprofessionally or looks unfinished."},
      {id: 7, title: "New issue created", description: "The repair process caused a different problem in the unit."},
      {id: 8, title: "Further inspection needed", description: "The fix was a patch and the root cause still needs looking at."},
    ];
    let reopenReason: any = reopenReasons.find((reason) => reason.id === Number(id));
    if (Number(id) === 0) {
        reopenReason = reopenReasons;
    }
    return reopenReason;
  };  


export const getReopenReasonIdByDescription = (description: string): number | null => {
  const REOPEN_REASONS = [
    { id: 1, title: "Problem not fixed", description: "The original issue still exists exactly as it was." },
    { id: 2, title: "Issue returned", description: "The repair worked for a short time but the problem has come back." },
    { id: 3, title: "Partial repair", description: "Only one part of the problem was fixed, but others were ignored." },
    { id: 4, title: "Staff never showed up", description: "The ticket was marked resolved, but no one visited the property." },
    { id: 5, title: "Incomplete work", description: "The technician left before finishing the job (e.g., waiting for parts or left a mess)." },
    { id: 6, title: "Poor quality of work", description: "The repair was done unprofessionally or looks unfinished." },
    { id: 7, title: "New issue created", description: "The repair process caused a different problem in the unit." },
    { id: 8, title: "Further inspection needed", description: "The fix was a patch and the root cause still needs looking at." },
  ];
  if (!description) return null;

  const normalizedInput = description.trim().toLowerCase();

  const found = REOPEN_REASONS.find(
    (reason) =>
      reason.description.toLowerCase() === normalizedInput ||
      reason.title.toLowerCase() === normalizedInput
  );

  return found ? found.id : null;
};
  
  export default getReopenReason;