import { defaultPagingController } from "./../../components/SearchResults/SearchResults";
import { isNullOrUndefined } from "html5-qrcode/esm/core";
import { isEmpty } from "lodash";

export const downloadFile = (blobData: Uint8Array, filename: string) => {
  const url = URL.createObjectURL(new Blob([blobData]));
  const link = document.createElement("a");
  link.href = url;
  link.setAttribute("download", filename);
  link.click();
};

export const convertObjToURLSearchParams = <T extends object>(
  data?: T | null,
): string => {
  if (isEmpty(data)) {
    return "";
  }

  const params = new URLSearchParams();
  Object.entries(data).forEach(([key, value]) => {
    if (!isNullOrUndefined(value)) {
      params.append(key, String(value));
    }
  });

  return params.toString();
};

export const getCustomWidth = (): number => {
  const LIMIT_WIDTH = 1000
  const CUSTOM_WIDTH = 1100
  if (window.innerWidth < LIMIT_WIDTH) return CUSTOM_WIDTH
  return window.innerWidth
}