import{f as S,r as n,j as e,g as j,S as z,h as g,C as I,k as L,B as R,D as y,X as M,A as T,m as _,b as W,u as B,l as v,d as A,c as D,e as U,H as F,P as H}from"./use-init-i18n-DnFRQkfM.js";import{aG as p,aH as O,aI as $,aJ as q,aK as V}from"./mermaid-GHXKKRXX-DQDrBeqo.js";/**
 * @license lucide-react v0.510.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const X=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],G=S("loader-circle",X),J=["code","preview","split"];function P(t,s){return(t==null?void 0:t.includes("html"))||/<!doctype html>|<html|<svg/i.test(s)}function K(t,s){return t!=null&&t.includes("html")||/<!doctype html>|<html/i.test(s)?"html":t!=null&&t.includes("svg")||/<svg/i.test(s)?"xml":t!=null&&t.includes("javascript")||t!=null&&t.includes("jsx")?"jsx":t!=null&&t.includes("typescript")||t!=null&&t.includes("tsx")?"tsx":t!=null&&t.includes("css")?"css":t!=null&&t.includes("json")?"json":t!=null&&t.includes("markdown")?"markdown":"html"}const Q="https://www.omniside.ai/artifact-preview",Y=n.memo(({content:t,onRendered:s})=>{const a=n.useRef(null),o=n.useRef(!1),c=n.useRef(t),l=n.useRef(s);return n.useEffect(()=>{l.current=s},[s]),n.useEffect(()=>{var u;c.current=t,o.current&&((u=a.current)!=null&&u.contentWindow)&&a.current.contentWindow.postMessage({type:"artifact:render",html:t},"*")},[t]),n.useEffect(()=>{const u=m=>{var f,d,i,r,x,h;m.source===((f=a.current)==null?void 0:f.contentWindow)&&(((d=m.data)==null?void 0:d.type)==="artifact:ready"?(o.current=!0,(r=(i=a.current)==null?void 0:i.contentWindow)==null||r.postMessage({type:"artifact:render",html:c.current},"*")):((x=m.data)==null?void 0:x.type)==="artifact:rendered"&&((h=l.current)==null||h.call(l)))};return window.addEventListener("message",u),()=>window.removeEventListener("message",u)},[]),e.jsx("iframe",{ref:a,title:"artifact-preview",src:Q,className:"size-full border-0 bg-white"})}),Z=n.memo(({mode:t,onChange:s})=>{const{t:a}=j(),o={code:a("chat.artifact.modeCode"),preview:a("chat.artifact.modePreview"),split:a("chat.artifact.modeCodeAndPreview")};return e.jsx(z,{value:t,options:J.map(c=>({value:c,label:e.jsx("span",{className:"flex items-center gap-1.5",children:e.jsx("span",{children:o[c]})})})),onChange:c=>s(c),variant:"borderless",className:g(`
          !h-7.5 w-40 cursor-pointer !rounded-md !bg-gray-100 dark:!bg-white/5
          [&>div]:!rounded-md [&>div]:!border-0
        `),suffixIcon:e.jsx(I,{className:"size-3 !transition-transform duration-150"})})});function k({type:t="Panel"}){const s=p(h=>h.current),{close:a}=p(),{t:o}=j(),[c,l]=n.useState(t==="Sandbox"?"split":"preview"),u=n.useMemo(()=>s?P(s.type,s.content):!1,[s]),[m,f]=n.useState(!1);n.useEffect(()=>{f(!1)},[s==null?void 0:s.identifier]),n.useMemo(()=>s?K(s.type,s.content):"html",[s]);const d=n.useCallback(()=>{if(!s)return;const h=`${(s.title||"artifact").replace(/[\\/:*?"<>|]/g,"_")}.html`,b=new Blob([s.content],{type:"text/html;charset=utf-8"}),N=URL.createObjectURL(b),w=document.createElement("a");w.href=N,w.download=h,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(N)},[s]);n.useEffect(()=>{s&&l(P(s.type,s.content)&&s.complete?"split":"preview")},[s]);const i=c==="code"||c==="split",r=(c==="preview"||c==="split")&&u,x=n.useRef(!1);return n.useLayoutEffect(()=>{r&&!x.current&&f(!1),x.current=r},[r]),s?e.jsxs("div",{className:"flex h-full w-full flex-col px-4",children:[e.jsxs("div",{className:"flex h-12 items-center justify-between gap-2",children:[e.jsx("div",{className:`
          flex size-6 shrink-0 items-center justify-center rounded-md bg-active
          text-white dark:bg-[#1a2a4a]
        `,children:e.jsx(O,{className:"size-[15px]"})}),e.jsx("div",{className:`
          min-w-0 flex-1 truncate text-base font-semibold text-foreground
        `,children:s.title}),e.jsxs("div",{className:"flex items-center",children:[u&&e.jsx(Z,{mode:c,onChange:l}),e.jsx(L,{content:s.content,className:`
              ml-2 size-8 cursor-pointer bg-transparent !p-0
              text-foreground-muted shadow-none hover:text-[#93A2B3]
              [&_*_svg]:!size-[16px]
            `,variant:"secondary"}),e.jsx(R,{className:`
              size-8 cursor-pointer bg-transparent !p-0 text-foreground-muted
              shadow-none hover:text-[#93A2B3] [&_*_svg]:!size-[16px]
            `,variant:"secondary",title:o("chat.artifact.download"),onClick:d,children:e.jsx(y,{className:"size-4"})}),t==="Panel"&&e.jsx(R,{className:`
                size-8 cursor-pointer bg-transparent !p-0 text-foreground-muted
                shadow-none hover:text-[#93A2B3] [&_*_svg]:!size-[16px]
              `,variant:"secondary",onClick:a,children:e.jsx(M,{className:"size-4"})})]})]}),e.jsxs("div",{className:`
        relative flex min-h-0 flex-1 overflow-hidden rounded-lg bg-[#f7f7f7]
      `,children:[i&&e.jsx("div",{className:g("min-h-0 overflow-auto",r?"w-1/2 border-r border-border":"w-full"),children:e.jsx($,{className:`
                h-full [&_[data-streamdown=code-block]]:rounded-none
                [&_pre]:!bg-transparent
              `,children:s.content})}),r&&e.jsxs("div",{className:g("relative min-h-0",i?"w-1/2":"w-full"),children:[e.jsx(Y,{content:s.content,onRendered:()=>f(!0)}),!m&&e.jsx("div",{className:`
                absolute inset-0 flex items-center justify-center bg-[#f7f7f7]
                text-muted-foreground
              `,children:e.jsx(G,{className:"size-6 animate-spin"})})]}),!i&&!r&&e.jsx("div",{className:`
            flex size-full items-center justify-center text-sm
            text-muted-foreground
          `,children:o("chat.artifact.noContent")})]}),e.jsx("div",{className:"flex h-12 leading-12 text-muted-foreground",children:s.complete?o("chat.artifact.generatedBy",{modelName:s.modelName||"AI"}):o("chat.artifact.generating")})]}):e.jsx("div",{className:"flex h-full w-full items-center justify-center",children:e.jsx("p",{className:"text-base",children:o("common.empty")})})}const ee=360,C=560,te=.8,E=n.memo(()=>{const t=p(r=>r.current),[s,a]=n.useState(!1),[o,c]=n.useState(C),[l,u]=n.useState(!1),m=n.useRef(C),f=n.useCallback(()=>{m.current=o,u(!0),document.body.style.userSelect="none",document.body.style.cursor="ew-resize"},[o]),d=n.useCallback((r,x)=>{const h=typeof window<"u"?window.innerWidth*te:1200,b=Math.max(ee,Math.min(h,m.current-x.offset.x));c(b)},[]),i=n.useCallback(()=>{u(!1),document.body.style.userSelect="",document.body.style.cursor=""},[]);return e.jsxs(e.Fragment,{children:[l&&e.jsx("div",{className:"fixed inset-0 z-[9999]",style:{cursor:"ew-resize"}}),e.jsx(T,{initial:!1,children:t&&e.jsxs(_.div,{initial:{width:0,opacity:0},animate:{width:o,opacity:1},exit:{width:0,opacity:0},transition:l?{duration:0}:{duration:.2,ease:"easeInOut"},onAnimationComplete:()=>a(!0),className:`
              relative h-full max-w-full shrink-0 bg-background max-md:fixed
              max-md:inset-y-0 max-md:right-0 sm:rounded-xl
            `,children:[e.jsx(_.div,{onPanStart:f,onPan:d,onPanEnd:i,style:{touchAction:"none"},className:g(`
                  absolute top-3 -left-0.5 z-20 h-[calc(100%-24px)] w-1
                  cursor-ew-resize transition-colors
                `,l?"bg-secondary/50":"hover:bg-secondary")}),e.jsx(k,{})]})})]})});E.displayName="ArtifactPanel";function se(){W();const{theme:t,toggleTheme:s}=B(),[a,o]=n.useState([]),{t:c}=j(),{close:l}=p(),[u,m]=n.useState(""),f=async()=>{const d=await v.getItem("preview-content");o(d)};return n.useEffect(()=>{f();const d=v.onChange("preview-content",r=>{o(r),l()}),i=v.onChange("theme",r=>{r&&["dark","light"].includes(r)&&s(r==="dark"?r:"light")});return()=>{d(),i()}},[]),n.useEffect(()=>{const i=new URLSearchParams(window.location.search).get("type")||"";m(i),i!=="Artifact"&&l()},[l]),e.jsx("div",{className:t,children:e.jsx("div",{className:`
        flex h-screen gap-3 bg-sidebar px-2.5 py-2 text-sidebar-foreground
        supports-[height:100dvh]:h-dvh
      `,children:u!=="Artifact"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`
                  h-full min-w-0 flex-1 overflow-hidden rounded-lg bg-white pt-4
                  pr-2 pb-8 pl-5 dark:bg-main-background
                `,children:e.jsx(q,{className:"h-full pr-3",children:e.jsx("div",{className:g(`
                        w-full !max-w-full space-y-2 px-2 py-1 text-sm
                        text-foreground sm:text-base
                      `,`
                        sm:py-2 [&_pre_code]:text-[12px]
                        [&_pre_code_span]:before:hidden! [&_ul_p]:my-2
                      `),children:a?a.map((d,i)=>e.jsx(V,{block:d,blocks:a,index:i,searchData:[]},`${d.type}-${i}`)):e.jsx("p",{className:"text-base",children:c("common.empty")})})})}),e.jsx(E,{})]}):e.jsx("div",{className:`
                relative h-full w-full min-w-0 flex-1 rounded-xl bg-background
              `,children:e.jsx(k,{type:"Sandbox"})})})})}async function ne(){const t=await v.getItem("lang"),s=t&&A.locales.includes(t)?t:A.defaultLocale;await D(s),U.createRoot(document.getElementById("root")).render(e.jsx(F,{children:e.jsx(H,{children:e.jsx(se,{})})})),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var a;(a=document.getElementById("omni-boot"))==null||a.remove()})})}ne();
