import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { useEffect } from "react";
import { useLocalStorage } from "react-use";
export default (function (file, changeFile) {
  var _useLocalStorage = useLocalStorage("recentItems", []),
      _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
      recentItems = _useLocalStorage2[0],
      changeRecentItems = _useLocalStorage2[1];

  if (!recentItems) recentItems = [];
  useEffect(function () {
    if (!file || file.fileName === "unnamed") return;

    if (recentItems.map(function (item) {
      return item.id;
    }).includes(file.id)) {
      changeRecentItems(recentItems.map(function (ri) {
        return ri.id === file.id ? file : ri;
      }));
    } else {
      changeRecentItems([file].concat(recentItems).slice(0, 3));
    } // eslint-disable-next-line

  }, [file, changeRecentItems]);
  return {
    recentItems: recentItems,
    changeRecentItems: changeRecentItems
  };
});