import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as c}from"./router-vendor-DdQhGl5t.js";import{a as D,u as I,B as t,c as R,O as y}from"../assets/index-DW8C1vVk.js";import{a as w,N as k,C as f,O as N,k as C,aB as z,f as J,Q as S,W as T,G as B,Y as M}from"./ui-vendor-C4ZcWovR.js";const P=({artifact:s,className:d})=>{const{t:r}=D(),[h,m]=c.useState(!1),[n,i]=c.useState("preview"),A=c.useRef(null),{theme:x,openArtifactPanel:g}=I(),p=async a=>{try{await navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}catch(l){console.error("Failed to copy:",l)}},u=()=>{const a=new Blob([s.content],{type:L(s.type)}),l=URL.createObjectURL(a),o=document.createElement("a");o.href=l,o.download=`${s.title}.${O(s.type)}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l)},L=a=>{switch(a){case"html":return"text/html";case"react":return"text/javascript";case"svg":return"image/svg+xml";case"css":return"text/css";case"json":return"application/json";default:return"text/plain"}},O=a=>{switch(a){case"html":return"html";case"react":return"jsx";case"svg":return"svg";case"css":return"css";case"json":return"json";default:return"txt"}},b=()=>{switch(s.type){case"html":return e.jsx(B,{className:"h-4 w-4"});case"react":return e.jsx(T,{className:"h-4 w-4"});case"svg":return e.jsx(S,{className:"h-4 w-4"});case"code":return e.jsx(T,{className:"h-4 w-4"});default:return e.jsx(S,{className:"h-4 w-4"})}},E=()=>{const a=`
      <!DOCTYPE html>
      <html>
        <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <base target="_blank">
          <title>${s.title}</title>
          <style>
            body {
              font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
              margin: 0;
              padding: 16px;
              background: white;
              color: #333;
            }
            * { box-sizing: border-box; }
          </style>
        </head>
        <body>
          ${s.content}
        </body>
      </html>
    `;return e.jsx("iframe",{ref:A,srcDoc:a,className:"w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg",sandbox:"allow-scripts allow-same-origin",title:s.title})},F=()=>{try{return e.jsx("div",{className:"w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-hidden border border-gray-200 dark:border-dark-200",dangerouslySetInnerHTML:{__html:s.content}})}catch{return e.jsx("div",{className:"w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200",children:e.jsxs("div",{className:"text-center",children:[e.jsx(M,{className:"h-8 w-8 text-red-500 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("artifacts.invalidSvg")})]})})}},v=()=>{const a=()=>{if(s.language)return s.language;switch(s.type){case"html":return"html";case"react":return"jsx";case"svg":return"xml";case"json":return"json";default:return"text"}};return e.jsx("div",{className:"relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto",children:e.jsx(y,{language:a(),isDark:x.mode==="dark",className:"!m-0 !rounded-lg",children:s.content})})},U=()=>{try{const a=JSON.parse(s.content),l=JSON.stringify(a,null,2);return e.jsx("div",{className:"relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto",children:e.jsx(y,{language:"json",isDark:x.mode==="dark",className:"!m-0 !rounded-lg",children:l})})}catch{return e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200",children:e.jsxs("div",{className:"text-center",children:[e.jsx(M,{className:"h-8 w-8 text-red-500 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("artifacts.invalidJson")})]})})}},_=()=>{if(n==="code")return v();switch(s.type){case"html":return E();case"svg":return F();case"json":return U();default:return v()}},j=()=>s.type==="html"||s.type==="svg"||s.type==="react";return e.jsxs("div",{className:R("border border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a] rounded-xl bg-white dark:bg-dark-25 ophelia:bg-[#050505] shadow-lg transition-all duration-300 hover:shadow-xl","w-full max-w-full overflow-hidden animate-fade-in","max-h-[400px] flex flex-col",d),children:[e.jsxs("div",{className:"px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] flex-shrink-0",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 flex-shrink-0 flex items-center justify-center",children:b()}),e.jsx("h3",{className:"font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate text-sm leading-tight flex-1",children:s.title})]}),e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[j()&&e.jsxs(e.Fragment,{children:[e.jsx(t,{variant:n==="preview"?"primary":"ghost",size:"sm",onClick:()=>i("preview"),className:"h-5 px-0.5 text-xs",title:r("artifacts.previewMode"),children:e.jsx(w,{className:"h-2.5 w-2.5"})}),e.jsx(t,{variant:n==="code"?"primary":"ghost",size:"sm",onClick:()=>i("code"),className:"h-5 px-0.5 text-xs",title:r("artifacts.codeMode"),children:e.jsx(k,{className:"h-2.5 w-2.5"})}),e.jsx("div",{className:"w-px h-2 bg-gray-300 dark:bg-gray-600 ophelia:bg-[#262626] mx-0.5"})]}),e.jsx(t,{variant:"ghost",size:"sm",onClick:()=>p(s.content),className:"h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212] touch-manipulation",title:r("artifacts.copyContent"),children:h?e.jsx(f,{className:"h-2.5 w-2.5 text-green-500"}):e.jsx(N,{className:"h-2.5 w-2.5"})}),e.jsx(t,{variant:"ghost",size:"sm",onClick:u,className:"h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212] touch-manipulation",title:r("artifacts.download"),children:e.jsx(C,{className:"h-2.5 w-2.5"})}),e.jsx(t,{variant:"ghost",size:"sm",onClick:()=>g(s),className:"h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212] touch-manipulation border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]",title:r("artifacts.openInPanel"),children:e.jsx(z,{className:"h-2.5 w-2.5"})})]})]}),e.jsxs("div",{className:"hidden sm:flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("div",{className:"flex-shrink-0",children:b()}),e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:s.title})]}),e.jsx("span",{className:"text-xs bg-primary-50 dark:bg-primary-900/20 ophelia:bg-[rgba(147,51,234,0.2)] text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc] px-2 py-1 rounded-full font-medium flex-shrink-0",children:s.type.toUpperCase()})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[j()&&e.jsxs(e.Fragment,{children:[e.jsxs(t,{variant:n==="preview"?"primary":"ghost",size:"sm",onClick:()=>i("preview"),className:"h-8 px-3 text-xs",title:r("artifacts.previewMode"),children:[e.jsx(w,{className:"h-3 w-3 mr-1"}),r("artifacts.preview")]}),e.jsxs(t,{variant:n==="code"?"primary":"ghost",size:"sm",onClick:()=>i("code"),className:"h-8 px-3 text-xs",title:r("artifacts.codeMode"),children:[e.jsx(k,{className:"h-3 w-3 mr-1"}),r("artifacts.code")]}),e.jsx("div",{className:"w-px h-4 bg-gray-300 dark:bg-gray-600 ophelia:bg-[#262626] mx-1"})]}),e.jsx(t,{variant:"ghost",size:"sm",onClick:()=>p(s.content),className:"h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]",title:r("artifacts.copyContent"),children:h?e.jsx(f,{className:"h-4 w-4 text-green-500"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsx(t,{variant:"ghost",size:"sm",onClick:u,className:"h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]",title:r("artifacts.download"),children:e.jsx(C,{className:"h-4 w-4"})}),e.jsx(t,{variant:"ghost",size:"sm",onClick:()=>g(s),className:"h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]",title:r("artifacts.openInPanel"),children:e.jsx(z,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"p-4 flex-1 overflow-hidden min-h-0",children:[s.description&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] mb-4",children:s.description}),e.jsx("div",{className:"h-full overflow-auto",children:_()})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] bg-gray-50 dark:bg-dark-100/50 ophelia:bg-[#0a0a0a] flex-shrink-0",children:[e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[r("artifacts.created"),":"," ",new Date(s.createdAt).toLocaleString()]}),(s.type==="html"||s.type==="react")&&e.jsxs(t,{variant:"ghost",size:"sm",onClick:()=>{const a=window.open("","_blank");a&&(a.document.write(s.content),a.document.close())},className:"text-xs hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212] ophelia:text-[#a3a3a3]",children:[e.jsx(J,{className:"h-3 w-3 mr-1"}),r("artifacts.openInNewWindow")]})]})]})},V=({artifacts:s,className:d})=>!s||s.length===0?null:e.jsx("div",{className:R("space-y-3",d),children:s.map(r=>e.jsx(P,{artifact:r},r.id))});export{V as A};
