import { Bari } from "./interfaces";
import { v4 as uuidv4 } from "uuid";

export const barnat: Bari[] = [];
export let barnatRAw: any[] = [];
export const rregulloBarnat = (trajtimiRaw: any) => {
  let barnatRawArr = trajtimiRaw.split("\n");
  barnatRawArr = barnatRawArr.flatMap((bar: any) => {
    return bar.split(",");
  });

  let trajtimi: any[] = [];
  barnatRawArr = barnatRawArr.map((bar: any) => {
    bar = bar.trim();
    if (bar !== "") {
      bar = bar.split(" ");
      return bar;
    }
  });
  // barnatRawArr = barnatRawArr.map((bar: any) => {
  //   bar = bar.trim();
  //   if (bar !== "") {
  //     let njesia = "";
  //     let sasia = "";
  //     let unidentifiedValue = "";
  //     bar = bar.split(" ");
  //     let bariEmer = filterBariEmer(bar[0]);
  //     return bar.map((bar: string) => {
  //       if (bar.toLowerCase().includes("mg")) {
  //         let sasiaFrak = bar.toLowerCase().split("mg");
  //         njesia = "Mg";
  //         if (sasiaFrak[1] !== "") unidentifiedValue = sasiaFrak[1];
  //       }
  //       return {
  //         emer: bariEmer!,
  //         njesia: njesia,
  //         sasia: sasia,
  //         unidentifiedValue: unidentifiedValue,
  //       };
  //     });
  //   }
  //   // filterNjesia(bar[1]);
  //   return null;
  // });
  // console.log(barnatRawArr);
  barnatRAw.push(barnatRawArr);
  // return barnatRawArr.map((bar: any) => {
  //   let bariRaw = bar.split(",");
  //   const bariEmer = filterBariEmer(bariRaw);
  //   if (bariEmer) {
  //     let newBar: Bari = {
  //       id: uuidv4(),
  //       emer: bariEmer,
  //     };
  //     const isFoundBari = barnat.some((bar) => {
  //       if (newBar.emer === bar.emer) {
  //         return true;
  //       }
  //       return false;
  //     });
  //     if (!isFoundBari) {
  //       barnat.push(newBar);
  //     }
  //     return newBar;
  //   }
  //   return;
  // });
};

const filterNjesia = (njesia: string) => {
  console.log(njesia);
};

const filterBariEmer = (bariRaw: string) => {
  let bariEmer = "";
  if (
    bariRaw === "" ||
    bariRaw === "??" ||
    bariRaw === "???" ||
    bariRaw === "????" ||
    bariRaw === "---" ||
    bariRaw === "----" ||
    bariRaw === "-----"
  ) {
    return null;
  } else if (
    bariRaw.toLowerCase().includes("parac") ||
    bariRaw.toLowerCase().includes("pracetamol")
  ) {
    bariEmer = "Paracetamol";
  } else if (bariRaw.includes("Dexa")) {
    bariEmer = "Dexamethasone";
  } else if (bariRaw.toLowerCase().includes("papa")) {
    bariEmer = "Papaverine";
  } else if (
    bariRaw.toLowerCase().includes("busc") ||
    bariRaw.toLowerCase().includes("bscopan")
  ) {
    bariEmer = "Buscopan";
  } else if (bariRaw.toLowerCase().includes("volt")) {
    bariEmer = "Voltaren";
  } else if (bariRaw.toLowerCase().includes("lido")) {
    bariEmer = "Lidocaine";
  } else if (
    bariRaw.toLowerCase().includes("cefaz") ||
    bariRaw.toLowerCase().includes("cefaolin") ||
    bariRaw.toLowerCase().includes("cafazoline")
  ) {
    bariEmer = "Cefazolin";
  } else if (
    bariRaw.toLowerCase().includes("oxyt") ||
    bariRaw.toLowerCase().includes("oxit")
  ) {
    bariEmer = "Oxytocin";
  } else if (
    bariRaw.toLowerCase().includes("metam") ||
    bariRaw.toLowerCase().includes("metham") ||
    bariRaw.toLowerCase().includes("mata")
  ) {
    bariEmer = "Metamizole";
  } else if (bariRaw.toLowerCase().includes("atr")) {
    bariEmer = "Atropine";
  } else if (bariRaw.toLowerCase().includes("meterg")) {
    bariEmer = "Methergine";
  } else if (bariRaw.toLowerCase().includes("metron")) {
    bariEmer = "Metronidazole";
  } else if (bariRaw.toLowerCase().includes("tramad")) {
    bariEmer = "Tramadol";
  } else if (
    bariRaw.toLowerCase().includes("indomet") ||
    bariRaw.toLowerCase().includes("inodmethac")
  ) {
    bariEmer = "Indomethacin";
  } else if (bariRaw.toLowerCase().includes("ampicil")) {
    bariEmer = "Ampicillin";
  } else if (bariRaw.toLowerCase().includes("gentamicin")) {
    bariEmer = "Gentamicin";
  } else if (
    bariRaw.toLowerCase().includes("cipr") ||
    bariRaw.toLowerCase().includes("cirpoflox")
  ) {
    bariEmer = "Ciprofloxacin";
  } else if (
    bariRaw.toLowerCase().includes("metil") ||
    bariRaw.toLowerCase().includes("metyl")
  ) {
    bariEmer = "Methylprednisolone";
  } else if (bariRaw.toLowerCase().includes("morfin")) {
    bariEmer = "Morphine";
  } else if (bariRaw.toLowerCase().includes("lasix")) {
    bariEmer = "Lasix";
  } else if (bariRaw.toLowerCase().includes("nifedipin")) {
    bariEmer = "Nifedipine";
  } else if (
    bariRaw.toLowerCase().includes("prednis") &&
    !bariRaw.toLowerCase().includes("Methyl")
  ) {
    bariEmer = "Prednisolone";
  } else if (bariRaw.toLowerCase().includes("cefat")) {
    bariEmer = "Cefotaxime";
  } else if (bariRaw.toLowerCase().includes("analgin")) {
    bariEmer = "Analgin";
  } else if (
    bariRaw.toLowerCase().includes("promet") ||
    bariRaw.toLowerCase().includes("pometazin")
  ) {
    bariEmer = "Promethazine";
  } else if (bariRaw.toLowerCase().includes("apotel")) {
    bariEmer = "Apotel";
  } else if (bariRaw.toLowerCase().includes("furosemid")) {
    bariEmer = "Furosemide";
  } else if (bariRaw.toLowerCase().includes("ranitidin")) {
    bariEmer = "Ranitidine";
  } else if (bariRaw.toLowerCase().includes("man")) {
    bariEmer = "Mannitol";
  } else if (bariRaw.toLowerCase().includes("primp")) {
    bariEmer = "Primperan";
  } else if (bariRaw.toLowerCase().includes("enoxaparin")) {
    bariEmer = "Enoxaparin";
  } else if (bariRaw.toLowerCase().includes("nitrogl")) {
    bariEmer = "Nitroglycerin";
  } else if (bariRaw.toLowerCase().includes("diazepam")) {
    bariEmer = "Diazepam";
  } else if (bariRaw.toLowerCase().includes("aspirin")) {
    bariEmer = "Aspirin";
  } else if (bariRaw.toLowerCase().includes("alciparin")) {
    bariEmer = "Calciparine";
  } else {
    bariEmer = bariRaw.trim().toLowerCase();
  }
  // return bariEmer.charAt(0).toUpperCase() + bariEmer.slice(1);
  return bariEmer;
};
