import { debounce, throttle } from "lodash"
import { useSnapshotStore } from "@/store"
import usePptWork from "@/store/pptWork"

export default () => {
  const snapshotStore = useSnapshotStore()
  const usePptWorkHook = usePptWork()
  // 添加历史快照(历史记录)
  const addHistorySnapshot = debounce(
    function () {
      usePptWorkHook.isSave = false
      snapshotStore.addSnapshot()
    },
    300,
    { trailing: true }
  )

  // 重做
  const redo = throttle(
    function () {
      usePptWorkHook.isSave = false
      snapshotStore.reDo()
    },
    100,
    { leading: true, trailing: false }
  )

  // 撤销
  const undo = throttle(
    function () {
      usePptWorkHook.isSave = false
      snapshotStore.unDo()
    },
    100,
    { leading: true, trailing: false }
  )

  return {
    addHistorySnapshot,
    redo,
    undo
  }
}
