// Helper function to create a mock infinite query from static options, this is
// needed because OXXO has hardcoded options for Tipo de Colaborador
export function createStaticOptionsQuery<T>(
  options: T[],
  cfg?: { getSearchText?: (item: T) => string },
) {
  return (params: { limit: number; name: string }) => {
    // Filter by name
    const getSearchText =
      cfg?.getSearchText ??
      ((opt: T) =>
        ((opt as Record<string, unknown>)?.title as string | undefined) ??
        ((opt as Record<string, unknown>)?.name as string | undefined) ??
        '');

    const search = params.name.toLowerCase();
    const filteredOptions = params.name
      ? options.filter(opt => getSearchText(opt).toLowerCase().includes(search))
      : options;

    return {
      data: {
        pages: [
          {
            data: {
              items: filteredOptions,
              count: filteredOptions.length,
              total: filteredOptions.length,
            },
          },
        ],
      },
      isLoading: false,
      fetchNextPage: () => undefined,
      isFetchingNextPage: false,
      hasNextPage: false,
      isPreviousData: false,
    };
  };
}
