"use client";
import { useState, useCallback, useEffect } from "react";
import { RECENT_ACTIONS_KEY, MAX_RECENT_ACTIONS } from "../constants.js";
function loadRecentActions() {
  if (typeof window === "undefined") return [];
  try {
    const stored = localStorage.getItem(RECENT_ACTIONS_KEY);
    if (!stored) return [];
    const parsed = JSON.parse(stored);
    if (!Array.isArray(parsed)) return [];
    return parsed.slice(0, MAX_RECENT_ACTIONS);
  } catch {
    return [];
  }
}
function saveRecentActions(actions) {
  if (typeof window === "undefined") return;
  try {
    localStorage.setItem(RECENT_ACTIONS_KEY, JSON.stringify(actions.slice(0, MAX_RECENT_ACTIONS)));
  } catch {
  }
}
function useRecentActions() {
  const [recentActions, setRecentActions] = useState([]);
  useEffect(() => {
    setRecentActions(loadRecentActions());
  }, []);
  const addRecentAction = useCallback((action) => {
    setRecentActions((prev) => {
      const newAction = {
        ...action,
        id: crypto.randomUUID(),
        timestamp: Date.now()
      };
      const filtered = prev.filter((a) => a.toolName !== action.toolName);
      const updated = [newAction, ...filtered].slice(0, MAX_RECENT_ACTIONS);
      saveRecentActions(updated);
      return updated;
    });
  }, []);
  const clearRecentActions = useCallback(() => {
    setRecentActions([]);
    if (typeof window !== "undefined") {
      localStorage.removeItem(RECENT_ACTIONS_KEY);
    }
  }, []);
  return {
    recentActions,
    addRecentAction,
    clearRecentActions
  };
}
export {
  useRecentActions
};
//# sourceMappingURL=useRecentActions.js.map
