export const checkForData = (data, source) => {
  const expectedData = data?.filter((d) => d?.source === source);
  return expectedData;
};

export const removeExtraIdentifiers = (
  data,
  identiferFirstKey,
  identifiersSecondKey,
) => {
  let finalResult = data;
  const extraIdentifiers = data?.filter(
    (d) => d?.idType === identiferFirstKey || d?.idType === identifiersSecondKey,
  );
  finalResult = extraIdentifiers?.length > 0
    ? data?.filter((item) => extraIdentifiers?.indexOf(item) === -1)
    : data;

  return finalResult;
};

export const identifiersHighlight = (searchString, data) => {
  let finalResult;
  if (data?.length > 0) {
    finalResult = data?.map((d) => {
      const searchedStringIndex = d?.idValue?.indexOf(searchString);
      const searchStringLength = searchString?.length;
      const sliceString = searchedStringIndex + searchStringLength;
      return {
        firstString: d?.idValue?.substring(0, searchedStringIndex),
        secondString: d?.idValue?.substring(searchedStringIndex, sliceString),
        thirdString: d?.idValue?.substring(sliceString),
      };
    });
  }
  return finalResult;
};

// Name breaking icon
export const getNamingIcon = (data) => {
  let returnedString;
  const splitStrings = data?.split(' ');
  returnedString = splitStrings?.length > 1
    ? splitStrings[0].charAt(0).toUpperCase()
      + splitStrings[1].charAt(0).toUpperCase()
    : splitStrings[0].charAt(0).toUpperCase()
      + splitStrings[0].charAt(1).toUpperCase();
  return returnedString;
};
