import { useState, useEffect, useMemo } from "react";
import { getAllEntityConfigs } from "../lib/entities/registry.client.js";
import { useAllPermissions } from "../lib/permissions/hooks.js";
function useQuickCreateEntities() {
  const [allEntities, setAllEntities] = useState([]);
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState(null);
  const userPermissions = useAllPermissions();
  useEffect(() => {
    try {
      setIsLoading(true);
      setError(null);
      const entities = getAllEntityConfigs();
      const topbarEntities = entities.filter(
        (entity) => {
          var _a, _b;
          return entity.enabled && ((_b = (_a = entity.ui) == null ? void 0 : _a.dashboard) == null ? void 0 : _b.showInTopbar);
        }
      );
      setAllEntities(topbarEntities);
    } catch (err) {
      const errorMessage = err instanceof Error ? err.message : "Failed to load entities";
      console.warn("Error loading entities for quick create:", err);
      setError(errorMessage);
      setAllEntities([]);
    } finally {
      setIsLoading(false);
    }
  }, []);
  const filteredEntities = useMemo(() => {
    if (allEntities.length === 0) return [];
    return allEntities.filter((entity) => {
      const createPermission = `${entity.slug}.create`;
      return userPermissions.includes(createPermission);
    });
  }, [allEntities, userPermissions]);
  return {
    entities: filteredEntities,
    isLoading,
    error,
    hasEntities: filteredEntities.length > 0
  };
}
export {
  useQuickCreateEntities
};
