"use client";
import { jsx as z } from "react/jsx-runtime";
import { useAppDispatch as B } from "../hooks/use-app-dispatch.js";
import { useAppSelector as s } from "../hooks/use-app-selector.js";
import v from "../hooks/use-localstorage.js";
import { getSelectedBlock as R } from "../../../../store/selectors.js";
import { createContext as T, useState as V } from "react";
import C from "../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/react-hot-toast/dist/index.js";
import { useHotkeys as a } from "../../../../node_modules/.pnpm/react-hotkeys-hook@4.6.1_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/react-hotkeys-hook/dist/react-hotkeys-hook.esm.js";
import { ActionCreators as h } from "../../../../node_modules/.pnpm/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js";
import { useContainerSettings as j } from "../hooks/use-container-settings.js";
import { insertFromClipboard as F, duplicateBlock as K, copyToClipboard as L, removeBlock as O } from "../store/builder-slice.js";
const H = T(void 0), $ = ({ children: S }) => {
  const A = j(), r = s(R), [y, b] = v("eidtor-left-panel-open", !0), [i, c] = v(
    "active-right-panel",
    null
  ), o = B(), [P, n] = V(!1), l = s((t) => t.builder.past.length > 1), p = s((t) => t.builder.future.length > 0), u = () => {
    l && o(h.undo());
  }, f = () => {
    p && o(h.redo());
  }, k = () => {
    console.log("Saving theme");
  }, M = async () => {
    console.log("Saving model");
  }, d = async () => {
    try {
      n(!0), await k(), await M(), n(!1), C.success("Saved successfully");
    } catch {
      n(!1), C.error("Failed to save content.");
    }
  }, x = (t) => {
    o(K({ blockId: t }));
  }, g = async () => {
    if (!navigator.clipboard || !navigator.clipboard.readText)
      return null;
    try {
      const t = await navigator.clipboard.readText(), e = JSON.parse(t);
      return !e || typeof e != "object" || !e.id || !e.type || !e.parentId ? null : e;
    } catch {
      return null;
    }
  }, m = async ({ blockId: t }) => {
    try {
      const e = await g();
      if (!e) return;
      o(F({ blockId: t, data: e, containerSettings: A }));
    } catch {
    }
  }, D = () => {
    let t = "Ctrl+C";
    return (navigator.userAgent && navigator.userAgent.toUpperCase().includes("MAC") || navigator.platform && navigator.platform.toUpperCase().includes("MAC")) && (t = "⌘+C"), t;
  }, U = () => {
    let t = "Ctrl+V";
    return (navigator.userAgent && navigator.userAgent.toUpperCase().includes("MAC") || navigator.platform && navigator.platform.toUpperCase().includes("MAC")) && (t = "⌘+V"), t;
  }, I = () => {
    let t = "Ctrl+S";
    return (navigator.userAgent && navigator.userAgent.toUpperCase().includes("MAC") || navigator.platform && navigator.platform.toUpperCase().includes("MAC")) && (t = "⌘+S"), t;
  }, w = (t) => {
    c(i === t ? null : t);
  };
  return a(["ctrl+s", "meta+s"], (t) => {
    t.preventDefault(), d();
  }), a(["ctrl+c", "meta+c"], (t) => {
    r && (t.preventDefault(), o(L({ blockId: r.id })));
  }), a(["ctrl+v", "meta+v"], (t) => {
    r && (t.preventDefault(), m({ blockId: r.id }));
  }), a(["del", "backspace"], () => {
    r && o(O(r.id));
  }), a(["ctrl+z", "meta+z"], (t) => {
    t.preventDefault(), u();
  }), a(["ctrl+shift+z", "meta+shift+z"], (t) => {
    t.preventDefault(), f();
  }), /* @__PURE__ */ z(
    H.Provider,
    {
      value: {
        save: d,
        isSaving: P,
        duplicate: x,
        pasteFromClipboard: m,
        getPlatformSpecificCopyShortcut: D,
        getPlatformSpecificPasteShortcut: U,
        getPlatformSpecificSaveShortcut: I,
        isLeftPanelOpen: y,
        setIsLeftPanelOpen: b,
        activeRightPanel: i,
        toggleRightPanel: w,
        getClipboardData: g,
        isUndoable: l,
        isRedoable: p,
        undo: u,
        redo: f
      },
      children: S
    }
  );
};
export {
  H as ActionContext,
  $ as ActionProvider
};
//# sourceMappingURL=action-context.js.map
