import{j as a,C as v,u as K,c as o,d as _,g as H,e as q,m as z,h as B,i as G,n as J,k as Q,o as W,T as X}from"./index-Bsr9DJ3G.js";import{r as C,u as Y}from"./vendor-DJo4KD8w.js";import{a as Z,u as P}from"./routing-DCIgrT7s.js";import{T as ee}from"./ToolbarPanels-CPoZvoTB.js";import{u as y}from"./i18n-BbpF47i1.js";import"./XMarkIcon-KMKD47CF.js";function te(){const{t:d}=y(),e=(i,r)=>d(`Compose.${i}`,r),g=Z(),c=P(),[t]=Y(),p=K(),h=o(p.activeKbId$),n=o(p.activeSession$),R=o(n==null?void 0:n.user$),b=o(n==null?void 0:n.token$),m=!!R,l=h!=null&&n==null,{showError:k,showSuccess:T}=_(),w=n==null?void 0:n.client;C.useEffect(()=>{l||m||c.push("/")},[l,m,c]);const x=H(),u=t!=null&&t.get("annotationUri")?`gather-context:${t.get("annotationUri")}`:null,f=u&&typeof sessionStorage<"u"?sessionStorage.getItem(u)??void 0:void 0;u&&f&&typeof sessionStorage<"u"&&sessionStorage.removeItem(u);const s=q(()=>z(w,x,{mode:(t==null?void 0:t.get("mode"))??void 0,token:(t==null?void 0:t.get("token"))??void 0,annotationUri:(t==null?void 0:t.get("annotationUri"))??void 0,sourceDocumentId:(t==null?void 0:t.get("sourceDocumentId"))??void 0,name:(t==null?void 0:t.get("name"))??void 0,entityTypes:(t==null?void 0:t.get("entityTypes"))??void 0,storedContext:f},b??void 0)),S=o(s.browse.activePanel$)??null,$=o(s.mode$)??"new",D=o(s.loading$)??!0,L=o(s.cloneData$)??null,E=o(s.referenceData$)??null,F=o(s.gatheredContext$)??null,N=o(s.entityTypes$)??[],{theme:oe,setTheme:I,resolvedTheme:j}=B(),{showLineNumbers:M,toggleLineNumbers:U}=G(),{hoverDelayMs:A}=J();Q({"settings:theme-changed":({theme:i})=>I(i),"settings:line-numbers-toggled":()=>U()});const O=async i=>{try{const r=await s.save(i);i.mode==="reference"&&i.annotationUri&&T("Reference successfully linked to the new resource"),c.push(`/know/resource/${encodeURIComponent(r)}`)}catch(r){const V=r instanceof Error?r.message:"Failed to save resource. Please try again.";throw k(V),r}};return l||D?a.jsx(v,{message:l?"Checking authentication...":"Loading cloned resource..."}):m?a.jsx(W,{mode:$,cloneData:L,referenceData:E,gatheredContext:F,availableEntityTypes:N,initialLocale:g,theme:j,showLineNumbers:M,hoverDelayMs:A,activePanel:S,onSaveResource:O,onCancel:()=>c.push("/know/discover"),translations:{title:e("title"),titleEditClone:e("titleEditClone"),titleCompleteReference:e("titleCompleteReference"),subtitleClone:e("subtitleClone"),subtitleReference:e("subtitleReference"),linkedNoticePrefix:e("linkedNoticePrefix"),resourceName:e("resourceName"),resourceNamePlaceholder:e("resourceNamePlaceholder"),entityTypes:e("entityTypes"),language:e("language"),contentSource:e("contentSource"),uploadFile:e("uploadFile"),uploadFileDescription:e("uploadFileDescription"),writeContent:e("writeContent"),writeContentDescription:e("writeContentDescription"),dropFileOrClick:e("dropFileOrClick"),supportedFormats:e("supportedFormats"),mediaType:e("mediaType"),autoDetected:e("autoDetected"),format:e("format"),content:e("content"),resourceContent:e("resourceContent"),encoding:e("encoding"),archiveOriginal:e("archiveOriginal"),cancel:e("cancel"),saving:e("saving"),creating:e("creating"),creatingAndLinking:e("creatingAndLinking"),saveClonedResource:e("saveClonedResource"),createAndLinkResource:e("createAndLinkResource"),createResource:e("createResource")},ToolbarPanels:ee,Toolbar:X}):null}function le(){const{t:d}=y(),e=(g,c)=>d(`Compose.${g}`,c);return a.jsx(C.Suspense,{fallback:a.jsx(v,{message:e("loading")}),children:a.jsx(te,{})})}export{le as default};
//# sourceMappingURL=page-BS88Xh4W.js.map
