import { usePagination } from "hooks/usePagination";
import { templateService } from "services";

export const templateQueryKey = (templateId: string | null) => {
  return ["campaignTemplate", templateId] as const;
};

export const emptyAddress = () => {
  return {
    firstLine: null,
    secondLine: null,
    city: null,
    country: null,
    zipcode: null,
  };
};

export function useTemplatesListPagination(
  searchTerm: string,
  options = { limit: 16 }
) {
  return usePagination(
    "templates",
    async (queryParams) => {
      return (
        (await templateService.getTemplatesWithCursor(
          queryParams,
          searchTerm
        )) ?? []
      );
    },
    async (countParams) => {
      return (
        (await templateService.getTemplatesCount(countParams, searchTerm)) ?? 0
      );
    },
    options.limit,
    "DESC",
    [searchTerm]
  );
}
