var g=(d,y,a)=>new Promise((o,r)=>{var f=i=>{try{p(a.next(i))}catch(s){r(s)}},n=i=>{try{p(a.throw(i))}catch(s){r(s)}},p=i=>i.done?o(i.value):Promise.resolve(i.value).then(f,n);p((a=a.apply(d,y)).next())});import{jsxs as l,jsx as t}from"react/jsx-runtime";import{B as h,a6 as D,a7 as x,a8 as S}from"./ui-components-B24mpb8o.js";import{useEditor as K}from"./use-editor-D8T8wKX0.js";import N from"./appearance-Ck6qxCB0.js";import C from"./device-mode-Bsl8ZmWC.js";import L from"./preview-CqSw4uJQ.js";import O from"./redo-undo-C37ZJ5Yy.js";import{usePage as T,Link as _,router as P}from"@inertiajs/react";import{Menu as R,Home as b}from"lucide-react";import{useState as I,useEffect as w}from"react";import{toast as M}from"sonner";import"next-themes";import"@radix-ui/react-label";import"class-variance-authority";import"@radix-ui/react-checkbox";import"@radix-ui/react-avatar";import"@radix-ui/react-dropdown-menu";import"@radix-ui/react-scroll-area";import"@radix-ui/react-popover";import"@radix-ui/react-radio-group";import"@radix-ui/react-dialog";import"@radix-ui/react-slot";import"clsx";import"@radix-ui/react-separator";import"@radix-ui/react-tooltip";import"@radix-ui/react-tabs";import"@radix-ui/react-accordion";import"@radix-ui/react-progress";import"@radix-ui/react-select";import"cmdk";import"@radix-ui/react-switch";import"react-day-picker";import"@radix-ui/react-slider";import"embla-carousel-react";import"@radix-ui/react-toggle-group";import"vaul";import"tailwind-merge";import"./editor-provider-CwMLJaUa.js";import"uuid";const xe=()=>{const{props:d}=T(),{project:y,page:a}=d,{editor:o,dispatch:r}=K(),[f,n]=I(!1);w(()=>{r({type:"SET_PROJECT_PAGE_ID",payload:{projectPageId:a.id}})},[a]);const p=()=>{r({type:"TOGGLE_PREVIEW_MODE"}),r({type:"TOGGLE_LIVE_MODE"})},i=()=>{r({type:"UNDO"})},s=()=>{r({type:"REDO"})},u=()=>g(null,null,function*(){n(!0);const e=JSON.stringify(o.editor.elements);P.put(route("page.content",{project:y.id,page:a.id}),{content:e},{preserveScroll:!0,preserveState:!0,onSuccess:()=>{r({type:"CLEAR_HISTORY"}),n(!1)},onError:()=>{M.error("Oopse!",{description:"Could not save content"}),n(!1)}})}),c=e=>{e.key==="s"&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),u()):e.key==="z"&&(e.ctrlKey||e.metaKey)&&!e.shiftKey?(e.preventDefault(),i()):e.key==="z"&&(e.ctrlKey||e.metaKey)&&e.shiftKey||e.key==="y"&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),s()):e.key==="p"&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),p())};w(()=>{var E;document.addEventListener("keydown",c);const e=document.querySelector("iframe"),m=(e==null?void 0:e.contentDocument)||((E=e==null?void 0:e.contentWindow)==null?void 0:E.document);return m&&m.addEventListener("keydown",c),()=>{document.removeEventListener("keydown",c),m&&m.removeEventListener("keydown",c)}},[o]);const k=()=>{r({type:"SET_COMPACT_SIDEBAR",payload:{compactSidebar:!1}})};return o.editor.liveMode||o.editor.previewMode?null:l("nav",{className:"flex h-16 items-center justify-between gap-2 border-b px-4 py-2 transition-all md:px-6",children:[l("aside",{className:"flex items-center gap-2",children:[o.editor.windowWidth<1024&&t(h,{size:"icon",variant:"secondary",className:"h-9 w-9 shadow-md",onClick:k,children:t(R,{className:"h-5 w-5"})}),l(D,{children:[t(x,{asChild:!0,children:t(_,{href:route("pages.index"),children:t(h,{variant:"outline",size:"icon",children:t(b,{className:"h-5 w-5","aria-label":"Back"})})})}),t(S,{children:t("p",{className:"inline-flex items-center gap-2",children:"Back to Pages"})})]}),t(N,{}),t(L,{})]}),t("aside",{children:t(C,{})}),l("aside",{className:"flex items-center gap-2",children:[t(O,{}),t("div",{className:"relative flex flex-col gap-1",children:l(h,{onClick:u,disabled:f,className:"px-3 md:px-4",children:["Save"," ",o.history.history.length>1&&`(${o.history.history.length-1<=50?o.history.history.length-1:"50+"})`]})})]})]})};export{xe as default};
