var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellLookup/utils/storage.ts
var storage_exports = {};
__export(storage_exports, {
  addHistoryItem: () => addHistoryItem,
  clearHistory: () => clearHistory,
  isLocalStorageAvailable: () => isLocalStorageAvailable,
  loadHistory: () => loadHistory,
  removeHistoryItem: () => removeHistoryItem,
  saveHistory: () => saveHistory
});
module.exports = __toCommonJS(storage_exports);
var loadHistory = (key) => {
  try {
    const data = localStorage.getItem(key);
    if (!data) return [];
    return JSON.parse(data);
  } catch (error) {
    console.error("Failed to load history from localStorage:", error);
    return [];
  }
};
var saveHistory = (key, history, maxCount) => {
  try {
    const limitedHistory = history.slice(0, maxCount);
    localStorage.setItem(key, JSON.stringify(limitedHistory));
  } catch (error) {
    console.error("Failed to save history to localStorage:", error);
  }
};
var clearHistory = (key) => {
  try {
    localStorage.removeItem(key);
  } catch (error) {
    console.error("Failed to clear history from localStorage:", error);
  }
};
var addHistoryItem = (key, item, maxCount) => {
  try {
    const history = loadHistory(key);
    const filteredHistory = history.filter((h) => h !== item);
    const newHistory = [item, ...filteredHistory];
    saveHistory(key, newHistory, maxCount);
    return newHistory.slice(0, maxCount);
  } catch (error) {
    console.error("Failed to add history item:", error);
    return [];
  }
};
var removeHistoryItem = (key, item) => {
  try {
    const history = loadHistory(key);
    const newHistory = history.filter((h) => h !== item);
    localStorage.setItem(key, JSON.stringify(newHistory));
    return newHistory;
  } catch (error) {
    console.error("Failed to remove history item:", error);
    return [];
  }
};
var isLocalStorageAvailable = () => {
  try {
    const testKey = "__pisell_lookup_test__";
    localStorage.setItem(testKey, "test");
    localStorage.removeItem(testKey);
    return true;
  } catch {
    return false;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  addHistoryItem,
  clearHistory,
  isLocalStorageAvailable,
  loadHistory,
  removeHistoryItem,
  saveHistory
});
