/** Cell references for generalptwformat.xlsx (opening / GENERAL sections only). */

export const TEMPLATE_PATH = "/templates/generalptwformat.xlsx";

export const HEADER_CELLS = {
  permitNumber: "M3",
  jobLocation: "D6",
  jobDetails: "D8",
  otherWork: "K9",
  otherPrecautions: "D36",
  safetyEquipment: "D37"
};

export const CHECKLIST_START_ROW = 14;
export const CHECKLIST_ROW_COUNT = 21;
export const CHECKLIST_COLUMNS = { yes: "L", no: "M", na: "N" };

/** Normalized B-column checklist labels from the template (rows 14–34). */
export const TEMPLATE_CHECKLIST_LABELS = [
  "1 are the contractors workers concerned qualified and competent to undertake the identified tasks or activities",
  "2 have the contractors workers received the appropriate site and area safety induction before commencing work",
  "3 have a formal risk assessment on the shopfloor and safe system of work of the area and activities been completed before work begins",
  "x is there no risk for tooling material water used by the contractors workers to get in contact by any means with the product",
  "4 is there any other task related permit required have all specific permits been issued",
  "5 is all plant and equipment in the area affected by the contractors work safely isolated and locked off",
  "6 have the contractors worker been made aware of where the nearest call point is and site fire emergency evacuation rules",
  "7 have the contractors worker been given an emergency and first aid contact responsible for the area of work",
  "8 do the people performing the work have the right ppe required to perform the job safely",
  "9 are all equipment including ladders scaffold lifting mewps electrical and mechanical equipment fit for purpose",
  "10 are the hazardous material to be used during performing the task been identified approved controlled and secured",
  "11 is the use of services required water electric gas compressed air available",
  "12 are suitable arrangements in place should lone work operations be required",
  "13 have any other work actvities which could impact on the safety of this permit been suspended as required in this area to ensure that there is no coactivity taking place",
  "14 is the area in which work is to take place clearly identified and has it been suitably cordoned off",
  "15 have neighbouring areas been assessed for risks to local workers contact with vehicles or other dangers",
  "16 have any additional risks or hazards flammable chemicals been identified and either removed or protected to prevent harm to people",
  "17 is appropriate lifting equipment available for use to avoid manual handling of loads over 23 kg",
  "18 is competent supervision present throughout the duration of the work",
  "19 are any wastes generated by the task suitably identified contained and controlled to be correctly disposed off",
  "20 are any significant environmental impact risks from the task identified and controlled"
];

export const SIGNOFF_ROWS = {
  "permit issuer": 43,
  "person in charge": 44,
  "permit applicant": 45,
  "watch person": 46,
  "working party 1": 47,
  "working party 2": 48,
  "working party 3": 49,
  "working party 4": 50
};

export const SIGNOFF_VALUE_COLUMNS = {
  name: "E",
  company: "H",
  signature: "J"
};

export const PERMIT_DATETIME_CELLS = {
  validFromDate: { day: "L43", month: "M43", year: "N43" },
  validFromTime: { hour: "M44", minute: "N44" },
  validUntilDate: { day: "L46", month: "M46", year: "N46" },
  validUntilTime: { hour: "M47", minute: "N47" },
  taskDuration: "M49"
};

export const HEADER_FIELD_KEYWORDS = {
  jobLocation: ["job location"],
  jobDetails: ["job detail"],
  otherWork: ["other work", "affect this permit", "currently undertaken"],
  otherPrecautions: ["other precautions"],
  safetyEquipment: ["safety equipment"]
};

export function normalizeQuestionText(text) {
  return String(text || "")
    .toLowerCase()
    .replace(/[^\w\s]/g, " ")
    .replace(/\s+/g, " ")
    .trim();
}

export function normalizeRoleLabel(role) {
  return normalizeQuestionText(String(role || "").replace(/:/g, ""));
}
