export const getTagColor = (color: string) => {
  if (!color) return "000000";

  let notAvailableColors = ["white", "fff", "ffffff"];

  let newColor = color?.toLowerCase();
  if (notAvailableColors?.includes(newColor)) {
    return "000000";
  }

  return color;
};

export const getDataForEntityTags = (
  entity: string,
  drivers: any[],
  units: any[],
  subusers: any,
  forms: any[],
  landmarks: any[],
  geofences: any[],
  assets: any[],
  additionalParams: any
) => {
  let data = [];
  if (entity === "Driver") {
    data = drivers.map((d: any) => {
      return {
        id: d.driverId,
        name: "Driver",
        label: d.name,
        status: d.status,
      };
    });
  } else if (entity === "Unit") {
    data = units.map((d) => {
      return {
        id: d.id,
        name: "Unit",
        label: d.label,
        unitVersionId: d.unitVersionId,
        jbus: d.jbus,
        vbus: d.vbus,
      };
    });
    if (additionalParams?.unitsIds) {
      const unitIds = additionalParams.unitsIds?.items?.map(
        (m: any) => m.unitId
      );
      if (unitIds) {
        data = data.filter((item) => unitIds.includes(item.id));
      }
    }
  } else if (entity === "User") {
    data = subusers?.items?.map((d: any) => {
      return { id: `${d.id}`, name: "User", label: d.userName };
    });
  } else if (entity === "Form") {
    data = forms?.map((f) => {
      return { id: `${f.id}`, name: "Form", label: f.name };
    });
  } else if (entity === "Asset") {
    data = assets?.map((a) => {
      return { id: `${a.id}`, name: "Asset", label: a.label };
    });
  } else if (entity === "Landmark") {
    data = landmarks?.map((d) => {
      return { id: d.id, name: "Landmark", label: d.name };
    });
  } else if (entity === "Geofence") {
    data = geofences?.map((g) => {
      return { id: g.id, name: "Geofence", label: g.name };
    });
  }
  return data;
};

export const cutNotes = (note: string, maxLength = 10) => {
  let notes = note ? note : "";
  if (notes.length > maxLength) {
    notes = `${notes.slice(0, maxLength)}...`;
  }
  return notes;
};
