import { jsx } from 'react/jsx-runtime';
import { useState, useCallback, useMemo } from 'react';
import { EntityListContext } from '@backstage/plugin-catalog-react';

function MockEntityListContextProvider(props) {
  const { children, value } = props;
  const [filters, setFilters] = useState(value?.filters ?? {});
  const updateFilters = useCallback(
    (update) => {
      setFilters((prevFilters) => {
        const newFilters = typeof update === "function" ? update(prevFilters) : update;
        return { ...prevFilters, ...newFilters };
      });
    },
    []
  );
  const defaultValues = useMemo(
    () => ({
      entities: [],
      backendEntities: [],
      queryParameters: {}
    }),
    []
  );
  const resolvedValue = useMemo(
    () => ({
      entities: value?.entities ?? defaultValues.entities,
      backendEntities: value?.backendEntities ?? defaultValues.backendEntities,
      updateFilters: value?.updateFilters ?? updateFilters,
      filters,
      loading: value?.loading ?? false,
      queryParameters: value?.queryParameters ?? defaultValues.queryParameters,
      error: value?.error,
      totalItems: value?.totalItems ?? (value?.entities ?? defaultValues.entities).length,
      limit: value?.limit ?? 20,
      offset: value?.offset,
      setLimit: value?.setLimit ?? (() => {
      }),
      setOffset: value?.setOffset,
      paginationMode: value?.paginationMode ?? "none"
    }),
    [value, defaultValues, filters, updateFilters]
  );
  return /* @__PURE__ */ jsx(EntityListContext.Provider, { value: resolvedValue, children });
}

export { MockEntityListContextProvider };
//# sourceMappingURL=MockEntityListContextProvider.esm.js.map
