"use client";
import { jsx as B } from "react/jsx-runtime";
import { useAppDispatch as R } from "../hooks/use-app-dispatch.js";
import { useAppSelector as i } from "../hooks/use-app-selector.js";
import C from "../hooks/use-localstorage.js";
import { getSelectedBlock as T } from "../../../../store/selectors.js";
import { useContext as V, createContext as j, useState as F } from "react";
import h 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 A } from "../../../../node_modules/.pnpm/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js";
import { useContainerSettings as K } from "../hooks/use-container-settings.js";
import { insertFromClipboard as L, duplicateBlock as O, copyToClipboard as E, removeBlock as H } from "../store/builder-slice.js";
const S = j(void 0), tt = ({ children: n }) => {
  const b = K(), o = i(T), [y, P] = C("eidtor-left-panel-open", !0), [c, l] = C(
    "active-right-panel",
    null
  ), r = R(), [x, s] = F(!1), p = i((t) => t.builder.past.length > 1), u = i((t) => t.builder.future.length > 0), f = () => {
    p && r(A.undo());
  }, d = () => {
    u && r(A.redo());
  }, k = () => {
    console.log("Saving theme");
  }, M = async () => {
    console.log("Saving model");
  }, g = async () => {
    try {
      s(!0), await k(), await M(), s(!1), h.success("Saved successfully");
    } catch {
      s(!1), h.error("Failed to save content.");
    }
  }, w = (t) => {
    r(O({ blockId: t }));
  }, m = 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;
    }
  }, v = async ({ blockId: t }) => {
    try {
      const e = await m();
      if (!e) return;
      r(L({ blockId: t, data: e, containerSettings: b }));
    } 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;
  }, z = (t) => {
    l(c === t ? null : t);
  };
  return a(["ctrl+s", "meta+s"], (t) => {
    t.preventDefault(), g();
  }), a(["ctrl+c", "meta+c"], (t) => {
    o && (t.preventDefault(), r(E({ blockId: o.id })));
  }), a(["ctrl+v", "meta+v"], (t) => {
    o && (t.preventDefault(), v({ blockId: o.id }));
  }), a(["del", "backspace"], () => {
    o && r(H(o.id));
  }), a(["ctrl+z", "meta+z"], (t) => {
    t.preventDefault(), f();
  }), a(["ctrl+shift+z", "meta+shift+z"], (t) => {
    t.preventDefault(), d();
  }), /* @__PURE__ */ B(
    S.Provider,
    {
      value: {
        save: g,
        isSaving: x,
        duplicate: w,
        pasteFromClipboard: v,
        getPlatformSpecificCopyShortcut: D,
        getPlatformSpecificPasteShortcut: U,
        getPlatformSpecificSaveShortcut: I,
        isLeftPanelOpen: y,
        setIsLeftPanelOpen: P,
        activeRightPanel: c,
        toggleRightPanel: z,
        getClipboardData: m,
        isUndoable: p,
        isRedoable: u,
        undo: f,
        redo: d
      },
      children: n
    }
  );
}, et = () => {
  const n = V(S);
  if (!n)
    throw new Error("useActionContext must be used within a ActionProvider");
  return n;
};
export {
  S as ActionContext,
  tt as ActionProvider,
  et as useActionContext
};
//# sourceMappingURL=action-context.js.map
