"use client";
import { useState, useCallback, useEffect, useMemo } from "react";
const RECENT_TOOLS_KEY = "om:command-palette:recent-tools";
const MAX_RECENT_TOOLS = 5;
function loadRecentToolIds() {
  if (typeof window === "undefined") return [];
  try {
    const stored = localStorage.getItem(RECENT_TOOLS_KEY);
    if (!stored) return [];
    const parsed = JSON.parse(stored);
    if (!Array.isArray(parsed)) return [];
    return parsed.slice(0, MAX_RECENT_TOOLS);
  } catch {
    return [];
  }
}
function saveRecentToolIds(toolIds) {
  if (typeof window === "undefined") return;
  try {
    localStorage.setItem(RECENT_TOOLS_KEY, JSON.stringify(toolIds.slice(0, MAX_RECENT_TOOLS)));
  } catch {
  }
}
function useRecentTools(allTools) {
  const [recentIds, setRecentIds] = useState([]);
  useEffect(() => {
    setRecentIds(loadRecentToolIds());
  }, []);
  const saveRecentTool = useCallback((toolName) => {
    setRecentIds((prev) => {
      const updated = [toolName, ...prev.filter((t) => t !== toolName)].slice(0, MAX_RECENT_TOOLS);
      saveRecentToolIds(updated);
      return updated;
    });
  }, []);
  const clearRecentTools = useCallback(() => {
    setRecentIds([]);
    if (typeof window !== "undefined") {
      localStorage.removeItem(RECENT_TOOLS_KEY);
    }
  }, []);
  const recentTools = useMemo(
    () => recentIds.map((id) => allTools.find((t) => t.name === id)).filter((t) => t !== void 0),
    [recentIds, allTools]
  );
  return {
    recentTools,
    saveRecentTool,
    clearRecentTools
  };
}
export {
  useRecentTools
};
//# sourceMappingURL=useRecentTools.js.map
