!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="bd619da4-789f-4c9f-a5f0-918968cb6364",e._sentryDebugIdIdentifier="sentry-dbid-bd619da4-789f-4c9f-a5f0-918968cb6364")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4109],{31102:function(e,t,n){var l=n(97017),r=n(97616),s=n(70986),i=parseFloat,a=Math.min,o=Math.random;e.exports=function(e,t,n){if(n&&"boolean"!=typeof n&&r(e,t,n)&&(t=n=void 0),void 0===n&&("boolean"==typeof t?(n=t,t=void 0):"boolean"==typeof e&&(n=e,e=void 0)),void 0===e&&void 0===t?(e=0,t=1):(e=s(e),void 0===t?(t=e,e=0):t=s(t)),e>t){var d=e;e=t,t=d}if(n||e%1||t%1){var c=o();return a(e+c*(t-e+i("1e-"+((c+"").length-1))),t)}return l(e,t)}},4561:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/glifs/[id]",function(){return n(15055)}])},96589:function(e,t,n){"use strict";n.d(t,{Z:function(){return l}});let l=(0,n(30411).Z)("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]])},36404:function(e,t,n){"use strict";n.d(t,{Z:function(){return l}});let l=(0,n(30411).Z)("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]])},37113:function(e,t,n){"use strict";n.d(t,{$:function(){return v},v:function(){return g}});var l=n(33741),r=n(16565),s=n(12080),i=n(62645),a=n(53561),o=n(21309),d=n(87689),c=n(72485),u=n(73072),m=n(5367),h=n(45517),f=n(43114),p=n(39734);let x=(0,r.createContext)(void 0);function g(e){var t;let{spell:n,children:g}=e,{enqueueRun:v}=(0,a.Z)(),{data:j}=(0,u.useSession)(),b=p.h.spell.getEstimatedCreditCostForLiveSpell.useQuery({spellId:null!==(t=null==n?void 0:n.id)&&void 0!==t?t:""},{enabled:!!n}).data,y=(0,r.useRef)((0,h.sj)({isLoggedIn:null!=j,spell:n,estimatedCost:void 0,currentRuns:[],isRunning:!1,graph:void 0,graphValidationError:void 0,updateInputValue:function(e,t){y.inputs[e]=t},handleRunGraph:w,spellRunId:void 0,prevSpellId:void 0,inputs:{},setReplyingToId:void 0,markRunAsDeleted:function(e){let t=y.currentRuns.find(t=>t.spellRunId===e);t&&(t.isDeleted=!0)}})).current;async function w(){if(!y.graph||!y.spell){o.ZP.error("Something went wrong");return}if(!y.inputs){o.ZP.error("Please fill in all inputs");return}if(!y.isLoggedIn){(0,o.ZP)("You need to sign in to run a glif! Redirecting...",{icon:"\uD83E\uDD2D"}),setTimeout(()=>{(0,u.signIn)()},1e3);return}y.isRunning=!0;let e=y.currentRuns.push({id:Date.now().toString(),spellRunId:void 0,output:void 0,outputType:void 0,isRunning:!0,isDeleted:!1,progressUpdates:[]}),t=y.currentRuns[e-1];if(null==t)throw Error("newRun is undefined");let n=y.graph,l=await v({inputs:new Map(Object.entries(y.inputs)),spellId:y.spell.id,updateCallback:async e=>{let l=Object.entries(e.graphExecutionState.nodes).reduce((e,t)=>{let[l,r]=t,s=(0,f.findBlockOrThrow)(n,l);return e.push({node:s,status:r.status}),e},[]);t.progressUpdates=l}});console.log("Glif run response:",l),(null==l?void 0:l.output)&&(t.output=l.output,t.outputType=l.outputType,t.spellRunId=l.spellRunId,t.isRunning=!1),y.isRunning=!1,(0,c.j)("Glif ran",{glifId:y.spell.id})}return(0,r.useEffect)(()=>{y.isLoggedIn=null!=j},[y,j]),(0,r.useEffect)(()=>{if(n&&n.data&&(void 0===y.prevSpellId||y.prevSpellId!==n.id)){y.spell=n,y.graphValidationError=void 0;try{y.graph=(0,s.Z)(n.data);let e=(0,i.F)(y.graph);y.inputs=e,y.prevSpellId=n.id}catch(e){if(e instanceof d.z.ZodError||e instanceof m.W6)y.graphValidationError=e;else throw e}}},[n,y]),(0,r.useEffect)(()=>{b&&(y.estimatedCost=b)},[b,y]),(0,l.jsx)(x.Provider,{value:y,children:g})}function v(){let e=(0,r.useContext)(x);if(!e)throw Error("useGlifPlayerSession must be used within a GlifPlayerSessionProvider");return e}},52648:function(e,t,n){"use strict";n.d(t,{Z:function(){return c}});var l=n(33741),r=n(84875),s=n.n(r),i=n(16565),a=n(18139),o=n(68164),d=n(65361);function c(e){let{children:t}=e,[n,r]=(0,o._)("staffPanel",!0),[c,u]=(0,i.useState)(n);return(0,l.jsx)(d.Z,{staff:!0,hideLabel:!0,children:(0,l.jsxs)("div",{className:"group fixed bottom-0 left-0 z-glif-nav grid max-w-[100vw] grid-cols-[auto_minmax(0,1fr)] overflow-hidden rounded-tr-md bg-white text-sm shadow-dropdown",children:[(0,l.jsx)("h3",{className:s()("bg-brand-500 text-white"),children:(0,l.jsx)("button",{type:"button",className:"h-full w-full px-3",onClick:()=>{u(!c),r(!c)},children:"Staff"})}),(0,l.jsx)(a.E.div,{initial:c?"open":"closed",animate:c?"open":"closed",variants:{open:{width:"max-content",maxWidth:"100%"},closed:{width:0,maxWidth:"0%"}},children:(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsx)("div",{className:"m-2 w-max",children:t})})})]})})}},86623:function(e,t,n){"use strict";n.d(t,{Z:function(){return u}});var l=n(33741),r=n(62102),s=n(76377),i=n.n(s),a=n(47325),o=n(86112);function d(e){let{children:t}=e;return(0,l.jsx)(r.yO,{component:(e,t)=>(0,l.jsx)(i(),{href:(0,a.D2)({username:e.replace(/^\@/,"")}),children:e},t),regex:/@([\w_]+)/,children:t})}function c(e){let{children:t}=e;return(0,l.jsx)(r.yO,{component:(e,t)=>(0,l.jsx)(i(),{href:"/glifs/all?tag=".concat(e.replace(/^#/,"")),children:e},t),regex:o.uY,children:t})}function u(e){let{children:t}=e;return(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(r.Ld,{children:(0,l.jsx)(d,{children:(0,l.jsx)(c,{children:t})})})})}},59168:function(e,t,n){"use strict";var l=n(33741),r=n(16565),s=n(77351),i=n(64292);t.Z=(0,r.forwardRef)(function(e,t){let{centered:n,isLoading:r,onLoadMore:a}=e;return(0,i.n)(function(){a()}),(0,l.jsx)("div",{className:n?"w-full p-s2 text-center":"",ref:t,children:r?(0,l.jsx)("div",{children:(0,l.jsx)(s.Z,{})}):(0,l.jsx)("button",{type:"button",className:"text-glif-lime-600 hover:text-glif-lime-700 focus:text-glif-lime-700",onClick:a,children:"Load more..."})})})},72997:function(e,t,n){"use strict";n.d(t,{M:function(){return i},Z:function(){return s}});var l=n(33741),r=n(6209);function s(e){let{items:t,renderItem:n,layout:s="masonry"}=e;return(0,l.jsxs)("div",{className:"mx-auto max-w-screen-2xl",children:[0===t.length&&(0,l.jsx)(a,{}),"masonry"===s&&(0,l.jsx)(r.R,{items:t,config:{columns:[1,3],gap:[24,24],media:[768,768]},render:n}),"grid"===s&&(0,l.jsx)("div",{className:"grid grid-cols-1 gap-6  md:grid-cols-3",children:t.map((e,t)=>n(e,t))})]})}function i(e){return e.flatMap(e=>e.items)}function a(){return(0,l.jsx)("div",{children:(0,l.jsxs)("p",{className:"text-center",children:["No plays yet ",(0,l.jsx)("span",{className:"inline-block rotate-90",children:":-("})]})})}},76774:function(e,t,n){"use strict";var l=n(33741);let r={staff:"bg-[#DCD8F5] text-[#5B3BEE]"};t.Z=e=>{let{label:t,type:n}=e;return(0,l.jsx)("div",{className:"flex items-center rounded ".concat(r[n]," px-1 py-0.5"),children:(0,l.jsx)("span",{className:"text-xs font-medium",children:t})})}},80196:function(e,t,n){"use strict";n.d(t,{Z:function(){return s}});var l=n(33741),r=n(77708);function s(e){let{checked:t,disabled:n=!1,label:s,onChange:i,iconName:a}=e;return(0,l.jsxs)("label",{className:"flex items-center gap-2",children:[(0,l.jsx)(r.r,{checked:t,disabled:n,onCheckedChange:e=>i(e),iconName:a}),s]})}},77708:function(e,t,n){"use strict";n.d(t,{r:function(){return o}});var l=n(33741),r=n(16565),s=n(41349),i=n(87986),a=n(75567);let o=r.forwardRef((e,t)=>{let{className:n,iconName:r,...o}=e;return(0,l.jsx)(s.fC,{className:(0,a.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",n),...o,ref:t,children:(0,l.jsx)(s.bU,{className:(0,a.cn)("pointer-events-none flex h-5 w-5 items-center justify-center rounded-full bg-background text-foreground shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"),children:r&&(0,l.jsx)(i.Z,{name:r,size:12})})})});o.displayName=s.fC.displayName},76645:function(e,t,n){"use strict";n.d(t,{N:function(){return s}});var l=n(16565),r=n(68164);function s(e){let{isFetchingNextPage:t,hasNextPage:n,fetchNextPage:s}=e,i=(0,l.useRef)(null),a=(0,r.S1)(i,{}),o=!!(null==a?void 0:a.isIntersecting);return(0,l.useEffect)(()=>{o&&!t&&n&&s()},[s,o,t,n]),{ref:i}}},15055:function(e,t,n){"use strict";n.r(t),n.d(t,{__N_SSG:function(){return e1},default:function(){return e2}});var l,r,s=n(33741),i=n(16565),a=n(60478),o=n(76377),d=n.n(o),c=n(89168),u=n(37113),m=n(70379),h=n(52648),f=n(54148),p=n(59168),x=n(84875),g=n.n(x),v=n(18139),j=n(44965),b=n(11269),y=n(73072),w=n(68164),N=n(5255),k=n(39014),C=n(26515),E=n(47325),Z=n(68766),S=n(34859),I=n(32497),F=n(4906),R=n(65361),L=n(60657),A=n(15407);function M(e){let{spell:t}=e,n=(0,L.Z)({id:t.id});return(0,s.jsxs)(s.Fragment,{children:[n.element,(0,s.jsx)(A.Z,{iconName:"remix",variant:"flat",onClick:()=>n.createFork(),disabled:n.isLoading,label:"Remix",isAccessibilityLabel:!0})]})}var T=n(25046),D=n(18770),P=n(60859),O=n(55101),_=n.n(O);function G(e){let{spell:t,children:n,showImage:l=!1,linked:r,header:i=!0}=e,{id:a,name:o,output:c,outputType:u,user:m}=t,h=r?(0,s.jsx)(d(),{href:(0,E.xN)({id:a,user:m}),children:o}):o;return(0,s.jsxs)("div",{className:"flex items-center",children:[l&&c&&"IMAGE"===u&&(0,s.jsx)("div",{className:"relative h-[30px] w-[30px] overflow-hidden rounded-md border-[2px] border-white shadow-image",children:(0,s.jsx)(_(),{width:60,height:60,src:c,alt:"",className:"h-[30px] w-[30px] object-cover"})}),i?(0,s.jsx)("h1",{className:"truncate text-2xl font-bold leading-[150%] text-black",children:h}):(0,s.jsx)(s.Fragment,{children:h}),n]})}var U=n(86623),z=n(64072),H=()=>(0,s.jsx)("svg",{width:"19",height:"19",viewBox:"0 0 19 19",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,s.jsx)("path",{d:"M5.76653 17.1361C7.61741 18.0411 9.73397 18.243 11.7226 17.7043C13.7112 17.1656 15.4364 15.923 16.5775 14.2076C17.7185 12.4921 18.1977 10.4207 17.9258 8.37842C17.654 6.33617 16.6496 4.46217 15.0995 3.10496C13.5495 1.74775 11.5592 0.999721 9.49898 1C7.43872 1.00028 5.44868 1.74884 3.89899 3.10647C2.3493 4.4641 1.34545 6.33837 1.07415 8.3807C0.802854 10.423 1.28257 12.4944 2.42408 14.2095M5.76653 17.1361L1 17.9992L2.42408 14.2095M5.76653 17.1361H5.77307M2.42408 14.2095L2.42538 14.2069",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})});function Q(e){let{count:t,onClick:n,color:l="text-gray-400"}=e;return(0,s.jsx)(z.Z,{tip:"Comments",children:(0,s.jsxs)("button",{className:"flex h-10 flex-row items-center ".concat(l,"  hover:text-black"),type:"button",onClick:n,children:[(0,s.jsx)(H,{}),(0,s.jsx)("span",{className:"pl-1 font-bold tabular-nums",children:t})]})})}var B=n(21309),V=n(39734),q=n(27402),$=n(37917),W=n(56881),X=n(79719),J=n(87986),K=n(76774),Y=e=>{let{comment:t,onDelete:n,onStaffDelete:l}=e,[r,a]=(0,i.useState)(!1);return(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"mb-2 flex flex-row rounded-xl p-2 text-sm ".concat(r?"bg-white":"bg-gray-100"," border border-gray-100"),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[(0,s.jsx)("div",{className:"flex flex-col p-1 pr-3",children:(0,s.jsx)(S.Z,{size:"lg",variant:"only-icon",user:t.user})}),(0,s.jsxs)("div",{className:"flex w-full flex-col",children:[(0,s.jsx)("div",{className:"flex flex-row justify-between",children:(0,s.jsxs)("div",{className:"flex w-full flex-row justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center gap-2",children:[(0,s.jsx)(d(),{href:"/@".concat(t.user.username),children:(0,s.jsx)("b",{children:t.user.username})}),t.user.staff&&(0,s.jsx)(K.Z,{label:"Staff",type:"staff"})]}),(0,s.jsx)("span",{className:"font-normal text-gray-400",children:(0,s.jsx)(W.Z,{date:t.createdAt})})]})}),(0,s.jsx)("div",{className:"flex flex-row",children:(0,s.jsx)("p",{className:"comment-content overflow-x-none whitespace-break-spaces text-gray-500",style:{wordBreak:"break-word"},children:(0,s.jsx)(U.Z,{children:t.content})})})]}),(0,s.jsx)("div",{"data-hover":r,className:"h-9 rounded-lg hover:bg-gray-100 data-[hover=true]:block hover-hover:hidden",children:(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)(I.Z,{iconAlignment:"vertical",portal:!0,children:[(0,s.jsx)(R.Z,{owner:t.userId,children:(0,s.jsxs)(I.Z.Item,{onClick:n,children:[(0,s.jsx)(X.Z,{name:"trash"}),"Delete"]})}),(0,s.jsx)(R.Z,{staff:!0,children:(0,s.jsxs)(I.Z.Item,{onClick:l,children:[(0,s.jsx)(X.Z,{size:20,name:"trash"}),"Hide"]})}),(0,s.jsxs)(I.Z.Item,{onClick:async()=>{200==(await fetch("/api/internal/reportComment",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commentId:t.id})})).status?(0,B.ZP)("Comment reported successfully"):(0,B.ZP)("An unknown error occurred, please try again")},children:[(0,s.jsx)(J.Z,{name:"flag",size:20}),"Report"]})]})})})]})})},ee=n(10185),et=n(86112),en=n(72485),el=n(66368);function er(e){let{spell:t}=e,n=(0,C.Z)({spellId:t.id}),l=function(e){let{spellId:t}=e,[n,l]=(0,i.useState)(!1),[r,a]=(0,i.useState)(""),[o,d]=(0,i.useState)(!1),{data:u,status:m}=(0,y.useSession)(),h=V.h.comment.create.useMutation({onSuccess(){B.Am.success("Comment submitted"),a(""),x.refetch()},useErrorBoundary:!0,retry:!1,onError:e=>{B.Am.error(e.message)}}),f=V.h.comment.delete.useMutation({onSuccess(){B.Am.success("Comment deleted"),x.refetch()},useErrorBoundary:!0,retry:!1,onError:e=>{B.Am.error(e.message)}}),p=V.h.comment.staffHide.useMutation({onSuccess(){B.Am.success("Comment flagged as staff"),x.refetch()},useErrorBoundary:!0,retry:!1,onError:e=>{B.Am.error(e.message)}});if(null==t)return;let x=V.h.comment.list.useQuery({glifId:t}),g=x.data||[],v=x.isLoading,j=V.h.comment.count.useQuery({glifId:t}),b=async()=>{if(!r){B.Am.error("Comment cannot be empty");return}if(!o){if(d(!0),null==t)return;if(r.length>et.qr){B.Am.error("Comment is too long"),d(!1);return}try{console.log({commentText:r}),await h.mutateAsync({glifId:t,comment:r}),await j.refetch(),(0,en.j)("Comment created",{glifId:t})}catch(e){(0,en.j)("Error when creating comment",{glifId:t}),(0,q.f)(e)}finally{d(!1)}}},w=async e=>{await f.mutateAsync({id:e}),await j.refetch(),(0,en.j)("Comment deleted",{glifId:t})},N=async e=>{await p.mutateAsync({id:e}),await j.refetch()};return{element:t?(0,s.jsx)($.yo,{open:n,onOpenChange:()=>l(!1),children:(0,s.jsxs)($.ue,{side:"right",className:"flex h-full flex-col",children:[(0,s.jsx)($.Tu,{children:(0,s.jsx)($.bC,{children:(0,s.jsxs)("span",{className:"flex flex-row items-center space-x-3 font-bold",children:[(0,s.jsx)(H,{})," ",(0,s.jsxs)("span",{children:[j.data," Comment",1===j.data?"":"s"]}),(0,s.jsx)("div",{className:"flex-grow"}),(0,s.jsx)($.sw,{})]})})}),u&&"authenticated"==m&&(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),await b()},children:[(0,s.jsx)("label",{htmlFor:"comment-input",className:"sr-only",children:"Leave a comment"}),(0,s.jsx)(ee.Z,{autoFocus:!0,value:r,onChange:e=>a(e),placeholder:"Leave a comment...",submitOn:"metaEnter",bottomControls:(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)("div",{className:"flex-grow"}),(0,s.jsx)(c.Z,{disabled:o,type:"submit",children:"Comment"})]})})]})}),v&&(0,s.jsx)(s.Fragment,{children:"Loading..."}),(0,s.jsxs)("div",{className:"flex flex-col overflow-y-auto",children:[g&&!v&&g.length>0&&g.map(e=>(0,s.jsx)(Y,{comment:e,onDelete:()=>{w(e.id)},onStaffDelete:()=>{N(e.id)}},e.id)),g&&!v&&0===g.length&&(0,s.jsx)("p",{children:"No comments yet"})]})]})}):null,handleShowComments(){l(!0)},count:j}}({spellId:t.id}),r=(0,a.useRouter)(),o=(0,F.Z)({spellId:t.id}),d=(0,L.Z)({id:t.id});return(0,i.useEffect)(()=>{null!==new URLSearchParams(window.location.search).get("showComments")&&(null==l||l.handleShowComments(),r.replace(window.location.pathname))},[l,r]),(0,s.jsxs)(s.Fragment,{children:[l&&l.element,n.element,o.element,d.element,(0,s.jsxs)("div",{className:"container relative flex flex-col items-start gap-1.5 px-2.5 md:mx-auto md:flex-row",children:[(0,s.jsxs)("div",{className:"w-full max-w-[calc(100vw-9px-17px)]",children:[(0,s.jsx)(G,{spell:t,linked:!0,children:(0,s.jsx)("div",{className:"ml-auto md:ml-0",children:(0,s.jsxs)(I.Z,{iconAlignment:"vertical",children:[(0,s.jsx)(R.Z,{owner:t.user.id,fallback:(0,s.jsx)(I.Z.Item,{href:(0,E.OB)(t),iconName:"eye",children:"View source"}),children:(0,s.jsx)(I.Z.Item,{href:(0,E.ss)(t),iconName:"edit",children:"Edit"})}),(0,s.jsx)(I.Z.Item,{onClick:async()=>{await d.createFork(),(0,en.j)("Remix clicked")},iconName:"remix",children:"Remix"}),(0,s.jsx)(I.Z.Separator,{}),(0,s.jsx)(R.Z,{owner:t.user.id,children:(0,s.jsx)(I.Z.Item,{onClick:()=>n.handleSoftDelete(),iconName:"delete",children:"Delete"})}),(0,s.jsx)(I.Z.Item,{onClick:()=>o.handleReport(),iconName:"warn",variant:"destructive",children:"Report"})]})})}),(0,s.jsxs)("div",{className:"my-1.5 flex flex-col gap-2",children:[t.description&&(0,s.jsx)("div",{className:"underline-links line-clamp-2 max-w-[550px] text-sm font-medium leading-[150%] text-gray-500 ",children:(0,s.jsx)(U.Z,{children:t.description})}),t.spellTags.length>0&&(0,s.jsx)("div",{className:"md:my-2",children:(0,s.jsx)(el.Z,{tags:t.spellTags.map(e=>e.tag.name),linkTagsToExplore:!0,doNotHideTags:!0})})]})]}),(0,s.jsxs)("div",{className:"flex w-full items-center gap-3 pb-3 md:ml-auto md:justify-end",children:[(0,s.jsx)("div",{className:"mr-auto md:mr-[42px]",children:(0,s.jsx)(S.Z,{user:t.user,variant:"with-name",color:"black",size:"md"})}),(0,s.jsx)(Q,{count:t._count.comments,onClick:()=>{var e;return null==l?void 0:null===(e=l.handleShowComments)||void 0===e?void 0:e.call(l)},color:"text-gray-400"}),(0,s.jsx)(T.Z,{likeable:t,type:D.E.Spell,count:t._count.likes}),(0,s.jsx)(M,{spell:t}),(0,s.jsx)(P.Z,{spellName:t.name,shareUrl:"".concat(Z.K,"/@").concat(t.user.username,"/glifs/").concat(t.id),variant:"flat"})]})]})]})}var es=n(19239),ei=n(53250),ea=n(89408),eo=n(11264),ed=n(7001),ec=n(27919);function eu(e){let{containerHeight:t,spellRun:n,isPublic:l,onDelete:r}=e,{output:i,outputType:a}=n,o=(0,E.Dd)(n),d=function(e){let{outputType:t,url:n,output:l,name:r}=e,s=(0,ed.Z)();return function(){s.share(function(){switch(t){case"TEXT":return{title:r,text:l,url:n};case"MULTIPLE":return{title:r,url:n};default:return{title:r,url:n,assetUrls:[l]}}}())}}({name:n.spell.name,output:i,outputType:a,url:o}),c=(0,D.Z)({type:D.E.SpellRun,likeable:n}),u=(0,s.jsxs)(s.Fragment,{children:["IMAGE"===a&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,iconName:"download",href:(0,ec.s)(n),download:!0,target:"_blank",rel:"noreferrer",label:"Download"})}),"TEXT"===a&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,iconName:"copy",label:"Copy",onClick:()=>{(0,es.Z)(i),B.Am.success("Copied to clipboard")}})}),l&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,onClick:d,iconName:"share",label:"Share"})}),l&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,iconName:c.isLiked?"liked":"notLiked",label:c.isLiked?"Unlike":"Like",onClick:()=>c.toggleLike(),disabled:c.isProcessing})}),l&&r&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,onClick:r,iconName:"trash",label:"Delete"})})]}),m=(0,eo.Z)(n,u),h="IMAGE"===a&&(0,s.jsx)("li",{children:(0,s.jsx)(A.Z,{isAccessibilityLabel:!0,onClick:()=>null==m?void 0:m.openModal(),iconName:"zoomIn",label:"Zoom"})});return(0,s.jsxs)("div",{"data-testid":"Output",className:"group/output relative mx-auto grid h-full min-h-[50vh] w-max max-w-[100%] md:block md:min-h-[auto] md:grid-cols-[1fr_max-content]",children:[t&&(0,s.jsx)(em,{containerHeight:t,spellRun:n,onClickImage:null==m?void 0:m.openModal})||(0,s.jsx)(s.Fragment,{}),null==m?void 0:m.modalElement,(0,s.jsxs)("ul",{className:"absolute right-4 top-4 flex gap-1 transition-opacity hover-hover:opacity-0 md:group-hover/output:opacity-100",children:[u," ",h]})]})}function em(e){let{containerHeight:t,spellRun:n,onClickImage:l}=e,r=(0,s.jsx)(ei.Z,{children:(0,ea.Z)(n,{height:t,showOriginalImage:!0})});return"IMAGE"===n.outputType?(0,s.jsx)("div",{onClick:l,className:"cursor-zoom-in",children:r}):r}var eh=n(31102),ef=n.n(eh),ep=n(61178),ex=n.n(ep),eg=n(49524),ev=n(17774);let ej={0:"relative ml-5 top-5",1:"-ml-5 z-10",2:"relative -ml-5 top-2"},eb={0:{rotate:-8},1:{rotate:0},2:{rotate:-2}};function ey(e){let{runs:t}=e,n=(0,ev.G)("md");return(0,s.jsx)("div",{className:"mb-8 mt-6 flex justify-center",children:(0,s.jsx)("div",{className:"flex min-w-full justify-center",children:ex()(0,3).map(e=>{let l=t[e];if(!l)return null;let{height:r}=(0,eg.j)(l,{maxWidth:n?{landscape:320,portrait:200,square:320}:{landscape:160,portrait:100,square:160}},e.toString()),i=ej[e],a=eb[e],o=(0,ea.Z)(l,{height:r,maxHeight:r});return(0,s.jsx)(v.E.div,{className:g()("relative h-max w-max max-w-2xl shrink-0 rounded-md border-[3px] border-white bg-gray-100 shadow-image",i),style:a,exit:{x:0,y:r,opacity:0,transition:{delay:ef()(0,.1)}},children:o},e)})})})}var ew=n(24544),eN=n(61102),ek=n(8451),eC=n(50534),eE=n(47629),eZ=n(55153),eS=n(30411);let eI=(0,eS.Z)("ThumbsUp",[["path",{d:"M7 10v12",key:"1qc93n"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}]]),eF=(0,eS.Z)("ThumbsDown",[["path",{d:"M17 14V2",key:"8ymqnk"}],["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",key:"m61m77"}]]);function eR(e){let{spellRunId:t}=e,[n,l]=(0,i.useState)(!1),r=V.h.spellRun.rateOutput.useMutation({onError(e){var t;B.ZP.error("Error rating: ".concat(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:e))}});return n?(0,s.jsx)("div",{className:"mx-auto rounded-2xl p-2",children:(0,s.jsxs)("div",{className:"flex flex-row items-center justify-center space-x-1",children:[(0,s.jsx)(v.E.span,{animate:{scale:[1,2,1]},transition:{duration:.5,repeat:0,repeatType:"reverse"},whileHover:{rotate:[0,-10,10,0]},children:"\uD83C\uDF89"}),(0,s.jsx)("span",{className:"text-sm text-gray-400",children:"Thanks"})]})}):(0,s.jsx)("div",{className:"mx-auto rounded-2xl p-2",children:(0,s.jsxs)("div",{className:"flex flex-col items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-400",children:"What did you think?"}),(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("div",{className:"cursor-pointer rounded-full p-1 transition-colors hover:bg-gray-200 ",children:(0,s.jsx)("button",{type:"button",className:"cursor-pointer rounded-full p-1 transition-colors hover:bg-gray-200",onClick:function(){l(!0),r.mutate({spellRunId:t,value:"up"})},children:(0,s.jsx)(eI,{className:"h-4 w-4 text-gray-400 transition-colors hover:text-gray-900"})})}),(0,s.jsx)("div",{className:"cursor-pointer rounded-full p-1 transition-colors hover:bg-gray-200",children:(0,s.jsx)("button",{type:"button",className:"cursor-pointer rounded-full p-1 transition-colors hover:bg-gray-200",onClick:function(){l(!0),r.mutate({spellRunId:t,value:"down"})},children:(0,s.jsx)(eF,{className:"h-4 w-4 text-gray-400 transition-colors hover:text-gray-900"})})})]})]})})}function eL(e){let{spellId:t}=e,n=(0,ev.G)("md");return(0,s.jsxs)("div",{className:"container opacity-50",style:{"--glif-max-height":"1024px","--glif-min-height":"370px","--glif-info-h":n?"87px":"142px","--glif-height":"calc(100dvh - var(--glif-nav-h) - var(--glif-info-h))","--glif-accent-col":(0,ek.e)(t)},children:[(0,s.jsx)("div",{className:"h-[--glif-info-h]"}),(0,s.jsx)("div",{className:g()("flex flex-col items-center gap-2"),children:(0,s.jsxs)("div",{className:g()("box-border grid min-h-[var(--glif-min-height)] w-screen snap-x snap-mandatory scroll-p-10 grid-cols-[90vw,90vw] grid-rows-[minmax(0,1fr)] gap-2 overflow-x-auto overflow-y-hidden max-md:px-2.5 md:h-[--glif-height] md:max-h-[var(--glif-max-height)] md:w-full md:grid-cols-[363px,1fr] md:overflow-hidden [&::-webkit-scrollbar]:hidden"),children:[(0,s.jsx)("div",{className:"mb-3 flex h-full w-full animate-pulse rounded-2xl bg-[--glif-accent-col]"}),(0,s.jsx)("div",{className:"animate-pulse snap-end overflow-hidden rounded-2xl border-2 border-[#F3F3F3] bg-[#fbfbfb]"})]})})]})}var eA=(0,i.memo)(function(e){let{actions:t,spell:n,spellRuns:l,form:r,view:a,outputSpellRun:o,progressUpdates:d,runsInSession:c=0,onRunDeleted:u}=e,{outputRef:m,outputHeight:h}=function(e){let{view:t,dimension:n="height"}=e,[l,r]=(0,i.useState)(!0),[s,a]=(0,N.x)(l),o=(0,w.Nr)(s?s[n]:0,500),[d,c]=(0,i.useState)(o);return(0,i.useEffect)(()=>{!1!==l&&!1!=!!o&&(c(o),"run-page"===t&&r(!1))},[o,t,l]),{outputHeight:d,outputRef:a}}({view:a}),{data:f}=(0,y.useSession)(),p=!!(null==f?void 0:f.user),x=(0,i.useRef)(null),C=null==d?void 0:d.map(e=>{let{status:t,node:n}=e,l=(0,b.iE)(n.type);return{name:n.name,type:n.type,category:l.category,iconName:l.iconName,status:t}});(0,i.useEffect)(()=>{if("run"===a){var e;null===(e=x.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"})}},[a]);let E=(0,ev.G)("md"),Z=(0,eN.Z)({run:o,redirectOnDelete:!1,onDeleted:u});return(0,s.jsxs)(v.E.div,{animate:a,className:"container",children:[Z.deleteModal,(0,s.jsx)(er,{spell:n,actions:t,linked:!0,size:"large"}),(0,s.jsx)("div",{className:g()("flex flex-col items-center gap-2"),style:{"--glif-output-height":"".concat(h,"px"),"--glif-max-height":"1024px","--glif-min-height":"370px","--glif-info-h":E?"148px":"142px","--glif-height":"calc(100dvh - var(--glif-nav-h) - var(--glif-info-h))","--glif-accent-col":(0,ek.e)(n.id)},children:(0,s.jsxs)("div",{className:g()("box-border grid min-h-[var(--glif-min-height)] w-screen snap-x snap-mandatory scroll-p-10 grid-cols-[90vw,90vw] grid-rows-[minmax(0,1fr)] gap-2 overflow-x-auto overflow-y-hidden max-md:px-2.5 md:h-[--glif-height] md:max-h-[var(--glif-max-height)] md:w-full md:grid-cols-[363px,1fr] md:overflow-hidden [&::-webkit-scrollbar]:hidden"),children:[(0,s.jsx)("div",{className:g()("h-full snap-start",p?"flex":"hidden md:flex"),children:(0,s.jsxs)("div",{className:"relative z-[20] w-full max-w-[355px] space-y-4 rounded-xl bg-[--glif-accent-col] p-4",children:[!p&&E&&(0,s.jsx)(eO,{onClick:()=>(0,y.signIn)()}),p&&r]})}),(0,s.jsxs)("div",{className:"col-span-2 col-start-1 row-start-2 space-x-4 font-medium text-gray-400",children:[n.forkedFromId&&(0,s.jsx)(eM,{forkedFromId:n.forkedFromId}),(0,s.jsx)(eP,{glifId:n.id}),(0,s.jsx)(eT,{})]}),(0,s.jsxs)("div",{className:"snap-end overflow-hidden rounded-2xl border-2 border-[#F3F3F3] bg-[#fbfbfb]",ref:x,children:[(0,s.jsx)(j.M,{children:"detail"===a&&(0,s.jsx)(eC.Z,{children:(0,s.jsxs)("div",{className:"my-[35px] flex flex-col gap-[34px]",children:[(0,s.jsx)(k.H,{children:(0,s.jsx)(ey,{runs:null!=l?l:[],show:"detail"===a})}),!p&&!E&&(0,s.jsx)(eO,{onClick:()=>(0,y.signIn)()})]})})}),p&&(0,s.jsx)("div",{className:"h-full w-full p-3",children:(0,s.jsx)("div",{ref:m,className:g()("relative z-10 h-full w-full items-center justify-center","detail"===a?"hidden":"flex"),children:(0,s.jsxs)("div",{className:"grid grid-cols-1 grid-rows-1 place-content-center place-items-center",children:[(0,s.jsx)("div",{className:"col-start-1 row-start-1 flex h-full w-full",children:(0,s.jsx)(ew.Z,{items:null!=C?C:[]})}),(0,s.jsxs)("div",{className:"col-start-1 row-start-1  h-full w-full",children:[(0,s.jsx)(v.E.div,{transition:{duration:.5},initial:{x:0,y:(h-70)*.75,rotate:0,opacity:0},animate:"output"===a?{x:0,y:0,rotate:0,opacity:1}:"run"===a?{x:0,y:.75*h,rotate:c>1?-30:0,opacity:0}:{x:0,y:.75*h,rotate:0,opacity:0},children:o&&(0,s.jsx)(eu,{spellRun:o,isPublic:!0,containerHeight:h-70,onDelete:()=>Z.openDeleteModal("owner")})}),o&&(0,s.jsx)(v.E.div,{className:"mt-2 h-[70px]",initial:{opacity:0},animate:{opacity:1},transition:{delay:.5,ease:"easeIn",duration:.75},children:(0,s.jsx)(eR,{spellRunId:o.id})})]})]})})})]})]})})]})});function eM(e){let{forkedFromId:t}=e;return(0,s.jsxs)("span",{children:["Remix of ",(0,s.jsx)(eD,{glifId:t})]})}function eT(){let e=(0,u.$)(),{graph:t}=(0,eZ.R)(e),n=null==t?void 0:t.nodes.filter(function(e){var t;return"GlifBlock"===e.type&&!(null===(t=e.params.id)||void 0===t?void 0:t.match(eE.JQ))}).map(e=>e.params.id).filter(e=>"string"==typeof e).reduce((e,t)=>(e[t]=(e[t]||0)+1,e),{});return t&&n&&0!==Object.keys(n).length?(0,s.jsxs)("span",{children:["Uses other glifs:"," ",(0,s.jsx)("div",{className:"inline-block space-x-2",children:Object.entries(n).map(e=>{let[t,n]=e;return(0,s.jsx)(eD,{glifId:t,count:n},t)})})]}):null}function eD(e){let{glifId:t,count:n}=e,l=V.h.spell.byId.useQuery({id:t},{retry:!1,useErrorBoundary:!1,onError:()=>{console.warn("Error fetching original glif; maybe deleted or made private? Nbd")}}),r=l.data;return!r&&l.isError?(0,s.jsx)("span",{className:"text-red-500",children:"[DELETED]"}):!r&&l.isLoading?(0,s.jsx)("span",{className:"animate-pulse",children:"…"}):r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(d(),{href:(0,E.xN)({id:r.id,user:r.user}),className:"text-gray-950",children:[(0,s.jsx)(J.Z,{name:"sparkle",size:16})," ",r.name]}),n&&n>1?" (".concat(n,"x)"):""]}):null}function eP(e){let{glifId:t}=e,n=V.h.spell.remixesCount.useQuery({glifId:t}),l=null==n?void 0:n.data;return!l||l<=0?null:(0,s.jsxs)(d(),{href:"/glifs/".concat(t,"/remixes"),className:"hover:underline",children:[l," remix",l>1?"es":""," of this glif ↗"]})}function eO(e){let{onClick:t}=e;return(0,s.jsx)("div",{className:"relative m-auto flex h-12 min-w-[84px] items-center justify-center",children:(0,s.jsx)(c.Z,{onClick:t,children:"Sign in to run"})})}var e_=n(88236),eG=n(83859),eU=n(77038),ez=n(56104);function eH(e){var t,n,l;let{spellId:r,spellSphereIds:a,postSaveCallback:o}=e,{data:d}=(0,y.useSession)(),u=null!==(l=null==d?void 0:null===(t=d.user)||void 0===t?void 0:t.staff)&&void 0!==l&&l,m=V.h.sphere.list.useQuery(),[h,f]=(0,i.useState)(a),p=V.h.useContext(),x=V.h.spell.updateSpheres.useMutation({onSuccess(e){var t;let n=(null===(t=e.spheres)||void 0===t?void 0:t.length)>0?e.spheres.map(e=>e.name).join(", "):"none";B.ZP.success("Set spheres to: ".concat(n)),p.spell.byId.invalidate({id:r})},onError(e){var t;B.ZP.error("Error updating spheres: ".concat(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:e))}});return u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(eU.Z,{label:"Spheres",children:(0,s.jsx)(eG.Z,{multiple:!0,onChange:f,defaultValue:h,children:null===(n=m.data)||void 0===n?void 0:n.map(e=>(0,s.jsx)(eG.Z.Option,{value:e.id,children:e.name},e.id))})}),(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)(c.Z,{onClick:function(){x.mutate({id:r,sphereIds:h}),o&&o()},children:"Update"})})]}):null}let eQ=e=>{let{spellId:t,spellSphereIds:n}=e,[l,r]=(0,i.useState)(!1);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",onClick:()=>r(!0),className:"underline hover:text-brand-600",children:"Edit spheres"}),(0,s.jsx)(ez.Z,{isOpen:l,onClose:()=>r(!1),title:"Edit spheres",children:(0,s.jsx)("div",{className:"min-w-[320px] space-y-2",children:(0,s.jsx)(eH,{spellId:t,spellSphereIds:n,postSaveCallback:()=>{r(!1)}})})})]})};var eB=n(87689);function eV(e){var t,n;let{spellId:l,postSaveCallback:a}=e,{data:o}=(0,y.useSession)(),d=null!==(n=null==o?void 0:null===(t=o.user)||void 0===t?void 0:t.staff)&&void 0!==n&&n,[u,m]=(0,i.useState)(""),h=V.h.useContext(),{data:f,isLoading:p,isError:x}=V.h.spell.getTagsForSpell.useQuery({spellId:l,tagType:r.STAFF},{enabled:!!l});(0,i.useEffect)(()=>{f&&m(f.map(e=>e.name).join("\n"))},[f]);let g=V.h.spell.setTags.useMutation({onSuccess(){B.ZP.success("Tags updated successfully"),h.spell.getTagsForSpell.invalidate({spellId:l}),a&&a()},onError(e){var t;B.ZP.error("Error updating tags: ".concat(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:e))}});function v(){let e=u.split("\n").filter(e=>""!==e.trim());g.mutate({spellId:l,tagNames:e,tagType:r.STAFF})}return d?p?(0,s.jsx)("div",{children:"Loading tags..."}):x?(0,s.jsx)("div",{children:"Error loading tags"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(eU.Z,{label:"Tags (one per line)",children:(0,s.jsx)("textarea",{value:u,onChange:e=>m(e.target.value),onKeyDown:function(e){e.metaKey&&"Enter"===e.key&&v()},className:"h-32 w-full rounded p-2"})}),(0,s.jsxs)("div",{className:"flex flex items-center justify-between",children:[(0,s.jsx)("small",{className:"text-gray-500",children:"Command+Enter to save"}),(0,s.jsx)(c.Z,{onClick:v,disabled:g.isLoading,children:g.isLoading?"Updating...":"Update Tags"})]})]}):null}(l=r||(r={})).STAFF="STAFF",l.MODELS="MODELS",eB.z.nativeEnum(r);let eq=e=>{let{spellId:t}=e,[n,l]=(0,i.useState)(!1);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",onClick:()=>l(!0),className:"underline hover:text-brand-600",children:"Staff Tags"}),(0,s.jsx)(ez.Z,{isOpen:n,onClose:()=>l(!1),title:"Edit tags",children:(0,s.jsx)("div",{className:"min-w-[320px] space-y-2",children:(0,s.jsx)(eV,{spellId:t,postSaveCallback:()=>{l(!1)}})})})]})};var e$=n(72997),eW=n(80196);function eX(e){let{spell:t}=e,n=V.h.useContext(),l=V.h.spell.setFeatured.useMutation({onError:q.f,onSuccess(){t&&n.spell.byId.invalidate({id:t.id})}});return(0,s.jsx)(eW.Z,{label:"Featured",checked:null!==t.featuredAt,disabled:l.isLoading,onChange:()=>l.mutate({id:t.id,featured:null===t.featuredAt})})}var eJ=n(76645),eK=n(82189),eY=n(72798);function e0(e){let{spell:t}=e,n=V.h.useContext(),l=V.h.spell.getFullSpellForStaff.useQuery({id:t.id}).data,r=V.h.spell.updateHiddenFromNewGlifsPage.useMutation({onError:q.f,onSuccess(){t&&(n.spell.byId.invalidate({id:t.id}),n.spell.getFullSpellForStaff.invalidate({id:t.id}))}});return l?(0,s.jsx)(eW.Z,{label:"Allow in Trending",checked:null===l.hiddenFromNewGlifsPageAt,disabled:r.isLoading,onChange:()=>r.mutate({id:t.id,hiddenFromNewGlifsPage:null===l.hiddenFromNewGlifsPageAt})}):(0,s.jsx)(eY.Z,{})}var e1=!0;function e2(e){let{id:t,title:n,openGraph:l}=e,{data:r}=V.h.spell.byId.useQuery({id:null!=t?t:""},{enabled:!!t}),i=!r,a={onError:q.f,async onSuccess(){B.Am.success("Reindex operation enqueued",{duration:5e3})}},o=V.h.spell.reindexSpell.useMutation(a),d=async()=>{r&&o.mutate({spellId:r.id})};return(0,s.jsx)(f.ZP,{title:n,openGraph:l,container:!1,children:(0,s.jsxs)(u.v,{spell:r,children:[null!=r&&(0,s.jsx)(h.Z,{children:(0,s.jsxs)("div",{className:"flex flex-row items-center gap-4",children:[(0,s.jsx)(eX,{spell:r}),(0,s.jsx)(e0,{spell:r}),(0,s.jsx)(eQ,{spellId:r.id,spellSphereIds:r.spheres.map(e=>e.id)}),(0,s.jsx)(c.Z,{onClick:d,children:"Reindex Spell"}),(0,s.jsx)(eq,{spellId:r.id})]})}),(0,s.jsx)(e7,{id:t,spell:r}),(0,s.jsx)("div",{className:g()(i?"min-h-screen":"","container mt-[27px]"),id:"plays",children:(0,s.jsx)(e4,{spell:r})})]})})}function e3(e){let{spell:t}=e,{graphValidationError:n}=(0,eZ.R)((0,u.$)());return n?(0,s.jsxs)("div",{className:"container rounded-2xl border-2 border-[#F3F3F3] bg-[#fbfbfb] p-4",children:[(0,s.jsx)("div",{className:"text-lg font-semibold",children:"Unfortunately this glif is no longer runnable"}),(0,s.jsxs)("div",{className:"pt-6",children:[(0,s.jsx)("div",{className:"font-semibold",children:"Errors:"}),n.issues.map((e,t)=>(0,s.jsxs)("div",{children:["- ",e.path.join(".")," → ",e.message]},t))]}),(0,s.jsx)(R.Z,{owner:t.userId,children:(0,s.jsx)(d(),{href:"/glifs/".concat(t.id,"/validate"),children:(0,s.jsx)(c.Z,{className:"mt-4",children:"Edit Graph JSON"})})})]}):null}let e5=(0,i.memo)(function(){let e=(0,u.$)(),{graph:t,handleRunGraph:n,estimatedCost:l,spell:r}=(0,eZ.R)(e),{updateInputValue:o,inputs:d}=(0,eZ.R)(e,{sync:!0}),c=V.h.useUtils(),m=(0,a.useSearchParams)();return(0,i.useEffect)(()=>{t&&Object.keys(d).forEach(e=>{let t=null==m?void 0:m.get(e);t&&o(e,t)})},[t,m]),t&&d&&(0,s.jsx)(e_.Z,{graph:t,isLoggedIn:!0,inputs:d,estimatedCosts:l,averageDuration:null==r?void 0:r.averageDuration,onChange:o,preventSpecialScrolling:!0,onConfirm:async()=>{await n(),await c.invalidate()}})});function e7(e){var t,n;let{id:l,spell:r}=e,{isRunning:a,markRunAsDeleted:o,currentRuns:d,graphValidationError:c}=(0,eZ.R)((0,u.$)()),m=(0,i.useMemo)(()=>(0,s.jsx)(e5,{}),[]),{spellRunId:h,progressUpdates:f,output:p,isDeleted:x}=null!==(n=d[d.length-1])&&void 0!==n?n:{spellRunId:void 0,progressUpdates:[],output:void 0,outputType:void 0,isDeleted:!1},g=V.h.spellRun.findById.useQuery({spellRunId:null!=h?h:""},{enabled:!!h&&!x}),{data:v}=V.h.spellRun.paginatedListCompletedForSpell.useInfiniteQuery({limit:3,spellId:l},{enabled:!!l,onError:q.f}),j=V.h.useContext(),b=(0,i.useCallback)(e=>{o(e),j.spellRun.paginatedListCompletedForSpell.invalidate(),j.spell.byId.invalidate()},[o,j.spell.byId,j.spellRun.paginatedListCompletedForSpell]),y="detail";return(a&&null==p?y="run":null==p||x||(y="output"),null==l)?null:null==r?(0,s.jsx)(eL,{spellId:l}):c?(0,s.jsx)(e3,{spell:r}):(0,s.jsx)(eA,{view:y,spell:r,spellRuns:null==v?void 0:null===(t=v.pages[0])||void 0===t?void 0:t.items,actions:null,form:m,outputSpellRun:x?void 0:g.data,progressUpdates:f,runsInSession:d.length,onRunDeleted:b})}function e4(e){var t;let{spell:n}=e,{isFetchingNextPage:l,fetchNextPage:r,hasNextPage:i,data:a,isInitialLoading:o}=V.h.spellRun.paginatedListCompletedForSpell.useInfiniteQuery({limit:20,spellId:null==n?void 0:n.id},{getNextPageParam:e=>e.nextCursor,enabled:!!(null==n?void 0:n.id),retry:!0,onError:q.f}),{ref:d}=(0,eJ.N)({fetchNextPage:r,hasNextPage:i,isFetchingNextPage:l}),c=(0,e$.M)(null!==(t=null==a?void 0:a.pages)&&void 0!==t?t:[]);return null==n||o?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"mb-8",children:(0,s.jsxs)("h2",{className:"text-2xl font-black",children:[n.completedSpellRunCount.toLocaleString()," ",(0,eK._6)(n.completedSpellRunCount,{one:"Run",many:"Runs"})]})}),(0,s.jsx)(e$.Z,{items:c,renderItem:e=>(0,s.jsx)(m.Z,{spellRun:e,hideGlif:!0,showAllPrompts:!0},e.id),layout:"grid"}),i&&(0,s.jsx)("div",{className:"mx-auto",children:(0,s.jsx)(p.Z,{centered:!0,ref:d,isLoading:l,onLoadMore:r})})]})}},8065:function(e,t,n){e.exports=n(78265)},6209:function(e,t,n){"use strict";n.d(t,{R:function(){return p}});var l=n(16565),r=Object.defineProperty,s=Object.defineProperties,i=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,c=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,u=(e,t)=>{for(var n in t||(t={}))o.call(t,n)&&c(e,n,t[n]);if(a)for(var n of a(t))d.call(t,n)&&c(e,n,t[n]);return e},m=(e,t)=>s(e,i(t)),h=(e,t)=>{var n={};for(var l in e)o.call(e,l)&&0>t.indexOf(l)&&(n[l]=e[l]);if(null!=e&&a)for(var l of a(e))0>t.indexOf(l)&&d.call(e,l)&&(n[l]=e[l]);return n};function f(e){return Array.isArray(e)?e:[e]}function p(e){var{items:t=[],render:n,config:r}=e,s=h(e,["items","render","config"]);let{columns:i,gap:a}=function(e,t,n){let[r,s]=l.useState({columns:1,gap:1});return l.useEffect(()=>{if(!e){s({columns:t[0],gap:n[0]});return}let l=e.map(e=>window.matchMedia(`(min-width: ${e}px)`)),r=()=>{let e=0;l.forEach(t=>{t.matches&&e++});let r=Math.min(l.length-1,Math.max(0,e));s({columns:t[r],gap:n[r]})};for(let e of(r(),l))e.addEventListener("change",r);return()=>{for(let e of l)e.removeEventListener("change",r)}},[r.columns,r.gap]),r}(r.media,f(r.columns),f(r.gap)),o=function(e=[],t=3){let n=Array.from({length:t},()=>[]);for(let l=0;l<t;l++)for(let t=0;t<e.length;t+=1)e[t][l]&&n[l].push(e[t][l]);return n}(function(e=[],t=3){let n=[];for(let l=0;l<e.length;l+=t){let r=e.slice(l,l+t);n.push(r)}return n}(t,i),i);return l.createElement("div",m(u({},s),{style:{display:"grid",alignItems:"start",gridColumnGap:a,gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`}}),o.map((e,t)=>l.createElement(x,{gap:a,key:t},e.map((e,t)=>n(e,t)))))}function x({children:e,gap:t}){return l.createElement("div",{style:{display:"grid",rowGap:t,gridTemplateColumns:"minmax(0, 1fr)"}},e)}},41349:function(e,t,n){"use strict";n.d(t,{bU:function(){return w},fC:function(){return y}});var l=n(91010),r=n(16565),s=n(70425),i=n(94745),a=n(46126),o=n(54006),d=n(93924),c=n(81971),u=n(39715);let m="Switch",[h,f]=(0,a.b)(m),[p,x]=h(m),g=(0,r.forwardRef)((e,t)=>{let{__scopeSwitch:n,name:a,checked:d,defaultChecked:c,required:m,disabled:h,value:f="on",onCheckedChange:x,...g}=e,[v,y]=(0,r.useState)(null),w=(0,i.e)(t,e=>y(e)),N=(0,r.useRef)(!1),k=!v||!!v.closest("form"),[C=!1,E]=(0,o.T)({prop:d,defaultProp:c,onChange:x});return(0,r.createElement)(p,{scope:n,checked:C,disabled:h},(0,r.createElement)(u.WV.button,(0,l.Z)({type:"button",role:"switch","aria-checked":C,"aria-required":m,"data-state":b(C),"data-disabled":h?"":void 0,disabled:h,value:f},g,{ref:w,onClick:(0,s.M)(e.onClick,e=>{E(e=>!e),k&&(N.current=e.isPropagationStopped(),N.current||e.stopPropagation())})})),k&&(0,r.createElement)(j,{control:v,bubbles:!N.current,name:a,value:f,checked:C,required:m,disabled:h,style:{transform:"translateX(-100%)"}}))}),v=(0,r.forwardRef)((e,t)=>{let{__scopeSwitch:n,...s}=e,i=x("SwitchThumb",n);return(0,r.createElement)(u.WV.span,(0,l.Z)({"data-state":b(i.checked),"data-disabled":i.disabled?"":void 0},s,{ref:t}))}),j=e=>{let{control:t,checked:n,bubbles:s=!0,...i}=e,a=(0,r.useRef)(null),o=(0,d.D)(n),u=(0,c.t)(t);return(0,r.useEffect)(()=>{let e=a.current,t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"checked").set;if(o!==n&&t){let l=new Event("click",{bubbles:s});t.call(e,n),e.dispatchEvent(l)}},[o,n,s]),(0,r.createElement)("input",(0,l.Z)({type:"checkbox","aria-hidden":!0,defaultChecked:n},i,{tabIndex:-1,ref:a,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function b(e){return e?"checked":"unchecked"}let y=g,w=v},93924:function(e,t,n){"use strict";n.d(t,{D:function(){return r}});var l=n(16565);function r(e){let t=(0,l.useRef)({value:e,previous:e});return(0,l.useMemo)(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}},62102:function(e,t,n){"use strict";n.d(t,{Ld:function(){return u},yO:function(){return c}});var l=n(16565);let r=/(https?:\/\/|www\.)([-\w.]+\/[\p{L}\p{Emoji}\p{Emoji_Component}!#$%&'"()*+,./\\:;=_?@[\]~-]*[^\s'",.;:\b)\]}?]|(([\w-]+\.)+[\w-]+[\w/-]))/u,s=({match:e,className:t})=>l.createElement("a",{className:t,href:/^www\./.exec(e)?`http://${e}`:e,target:"_blank",rel:"noreferrer"},e),i=0,a=()=>++i,o=/[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim;function d(e,t,n){return"string"==typeof e?function(e,t,n){let r=[],s=e;for(;;){let e=n.exec(s);if(!e||void 0===e[0])break;let l=e.index,i=e.index+e[0].length,d=s.slice(0,l),c=s.slice(l,i).replace(o,"");s=s.slice(i),d&&r.push(d),r.push(t(c,a()))}return(s&&r.push(l.createElement(l.Fragment,{key:a()},s)),0===r.length)?e:r}(e,t,n):Array.isArray(e)?e.map(e=>d(e,t,n)):(0,l.isValidElement)(e)&&e.props.children&&"a"!==e.type&&"button"!==e.type?(0,l.cloneElement)(e,{...e.props,key:a()},d(e.props.children,t,n)):e}let c=e=>l.createElement(l.Fragment,null,d(e.children,e.component,e.regex)),u=e=>l.createElement(l.Fragment,null,d(e.children,(t,n)=>l.createElement(s,{key:n,match:t,className:e.className}),r))}},function(e){e.O(0,[4926,8641,9914,6523,5610,4148,346,5773,8293,8512,1951,9719,2888,9774,179],function(){return e(e.s=4561)}),_N_E=e.O()}]);