"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[400],{23359:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]])},81021:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]])},24544:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]])},81260:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},13626:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},47603:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])},96122:function(e,t,r){r.d(t,{Z:function(){return s}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let s=(0,r(60998).Z)("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]])},61400:function(e,t,r){r.r(t),r.d(t,{RecipeHub:function(){return V}});var s=r(85893),a=r(67294),n=r(11163),l=r(41664),c=r.n(l),i=r(55739),o=r(1272),d=r(81021),u=r(24544),p=r(47603),x=r(96122),m=r(81260),h=r(13626),y=r(23359),j=r(37673),g=r(30803),f=r(68764),b=r(94545),w=r(91360),v=r(42557),N=r(29749);r(69123);var k=r(28970),C=r(62935),_=r(470),L=r(15821),S=r(79586),Z=r(56072);let M=[{label:"Name",value:"name"},{label:"Type",value:"recipe_type"},{label:"Owner",value:"user_name"}];function R(e){let{name:t,className:r=""}=e;if(!t)return(0,s.jsx)("span",{className:r,children:"Unknown"});if(t.includes("@")){let e=t.split("@")[0];return(0,s.jsx)(_.Md,{content:t,children:(0,s.jsx)("span",{className:"border-b border-dotted border-gray-400 cursor-help ".concat(r),children:e})})}return(0,s.jsx)("span",{className:r,children:t})}function E(e){let{recipe:t,onPin:r}=e,a=(0,Z.NL)(t.recipe_type),n=a.icon,l=t.name;return(0,s.jsxs)("div",{className:"relative w-[300px]",children:[(0,s.jsx)(c(),{href:"/recipes/".concat(l),className:"block",children:(0,s.jsx)(j.Zb,{className:"h-full hover:bg-gray-50 transition-colors cursor-pointer group",children:(0,s.jsxs)(j.aY,{className:"p-3",children:[(0,s.jsxs)("div",{className:"flex items-start gap-2 mb-1.5",children:[(0,s.jsx)(n,{className:"w-4 h-4 flex-shrink-0 mt-0.5 ".concat("sky"===a.color?"text-sky-600":"purple"===a.color?"text-purple-600":"green"===a.color?"text-green-600":"orange"===a.color?"text-orange-600":"text-gray-600")}),(0,s.jsx)("div",{className:"flex-1 min-w-0",children:(0,s.jsx)("h3",{className:"text-base font-medium text-blue-600 truncate group-hover:text-blue-800 transition-colors",children:t.name})})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("div",{className:"text-sm text-gray-500",children:a.label}),(0,s.jsx)("p",{className:"text-sm truncate ".concat(t.description?"text-gray-600":"invisible"),title:t.description||"",children:t.description||"\xa0"}),(0,s.jsxs)("div",{className:"text-sm text-gray-500 truncate",children:["Authored by"," ",(0,s.jsx)(R,{name:t.user_name||t.user_id})]}),(0,s.jsxs)("div",{className:"text-sm text-gray-500 truncate ".concat(t.is_editable&&"local"!==t.user_name?"":"invisible"),children:["Updated by"," ",(0,s.jsx)(R,{name:t.updated_by_name||t.user_name})," ",(0,s.jsx)(_.Zg,{date:t.updated_at?new Date(1e3*t.updated_at):null})]})]})]})})}),r&&t.pinned&&!1!==t.is_pinnable&&(0,s.jsx)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),r(t.name,!1)},className:"absolute top-2 right-2 p-1 rounded transition-colors text-amber-500 hover:text-amber-700 hover:bg-amber-100",title:"Unpin recipe",children:(0,s.jsx)(d.Z,{className:"h-4 w-4"})})]})}function T(e){let{title:t,icon:r,recipes:a,emptyMessage:n,iconColor:l,onPin:c}=e;return 0===a.length?(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,s.jsx)(r,{className:"w-4 h-4 ".concat(l)}),(0,s.jsx)("h2",{className:"text-base text-gray-700",children:t}),(0,s.jsxs)("span",{className:"text-sm text-gray-500",children:["(",a.length,")"]})]}),(0,s.jsx)("div",{className:"text-center py-6 bg-white rounded-lg border border-gray-200 shadow-sm",children:(0,s.jsx)("p",{className:"text-gray-500",children:n})})]}):(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,s.jsx)(r,{className:"w-4 h-4 ".concat(l)}),(0,s.jsx)("h2",{className:"text-base text-gray-700",children:t}),(0,s.jsxs)("span",{className:"text-sm text-gray-500",children:["(",a.length,")"]})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-3",children:a.map(e=>(0,s.jsx)(E,{recipe:e,onPin:c},e.name))})]})}function O(e){let{recipes:t,onPin:r,onDelete:n}=e,[l,i]=(0,a.useState)(null),[o,x]=(0,a.useState)([]),[m,h]=(0,a.useState)({key:"updated_at",direction:"descending"}),y=(0,a.useMemo)(()=>{let e=new Set,r=new Set,s=new Set;return t.forEach(t=>{t.name&&e.add(t.name),t.recipe_type&&r.add(t.recipe_type),t.user_name?s.add(t.user_name):t.user_id&&s.add(t.user_id)}),{name:Array.from(e).sort(),recipe_type:Array.from(r).sort(),user_name:Array.from(s).sort()}},[t]),g=e=>{let t="ascending";m.key===e&&"ascending"===m.direction&&(t="descending"),h({key:e,direction:t})},w=e=>m.key===e?"ascending"===m.direction?" ↑":" ↓":"",v=(0,a.useMemo)(()=>{let e=t;return o.length>0&&(e=e.filter(e=>{for(let t of o){let r=t.property.toLowerCase().replace(" ","_"),s="";if("name"===r?s=e.name||"":"type"===r?s=e.recipe_type||"":"owner"===r&&(s=e.user_name||e.user_id||""),!s.toLowerCase().includes(t.value.toLowerCase()))return!1}return!0})),(0,b.R0)(e,m.key,m.direction)},[t,o,m]);return(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[(0,s.jsx)("span",{className:"text-base text-gray-700",children:"All Recipes"}),(0,s.jsx)("div",{className:"w-full sm:w-auto",children:(0,s.jsx)(A,{propertyList:M,valueList:y,setFilters:x,placeholder:"Filter recipes",filters:o})}),(0,s.jsxs)("span",{className:"text-sm text-gray-500 ml-auto",children:[v.length," of ",t.length]})]}),o.length>0&&(0,s.jsx)(z,{filters:o,setFilters:x}),(0,s.jsx)(j.Zb,{children:(0,s.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,s.jsxs)(f.iA,{className:"min-w-full",children:[(0,s.jsx)(f.xD,{children:(0,s.jsxs)(f.SC,{children:[(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("recipe_type"),children:["Type",w("recipe_type")]}),(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("name"),children:["Name",w("name")]}),(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("description"),children:["Description",w("description")]}),(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("user_name"),children:["Owner",w("user_name")]}),(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("updated_by_name"),children:["Last Updated By",w("updated_by_name")]}),(0,s.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("updated_at"),children:["Updated",w("updated_at")]}),(0,s.jsx)(f.ss,{className:"whitespace-nowrap w-[100px]",children:"Actions"})]})}),(0,s.jsx)(f.RM,{children:0===v.length?(0,s.jsx)(f.SC,{children:(0,s.jsx)(f.pj,{colSpan:7,className:"text-center py-6 text-gray-500",children:0===t.length?"No recipes available.":"No recipes match your filter criteria."})}):v.map(e=>{let t=(0,Z.NL)(e.recipe_type),a=t.icon,n=e.name,l=e.description?e.description.length>80?e.description.substring(0,80)+"...":e.description:"-";return(0,s.jsxs)(f.SC,{className:"hover:bg-gray-50",children:[(0,s.jsx)(f.pj,{children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(a,{className:"w-4 h-4 ".concat("sky"===t.color?"text-sky-600":"purple"===t.color?"text-purple-600":"green"===t.color?"text-green-600":"orange"===t.color?"text-orange-600":"text-gray-600")}),(0,s.jsx)("span",{children:t.label})]})}),(0,s.jsx)(f.pj,{children:(0,s.jsx)(c(),{href:"/recipes/".concat(n),className:"text-blue-600 hover:text-blue-800 hover:underline",children:e.name})}),(0,s.jsx)(f.pj,{className:"text-gray-600 max-w-[400px]",title:e.description||"",children:(0,s.jsx)("span",{className:"cursor-default",children:l})}),(0,s.jsx)(f.pj,{className:"text-gray-600",children:(0,s.jsx)(R,{name:e.user_name||e.user_id})}),(0,s.jsx)(f.pj,{className:"text-gray-600",children:e.updated_by_name||e.user_name?(0,s.jsx)(R,{name:e.updated_by_name||e.user_name}):"-"}),(0,s.jsx)(f.pj,{className:"text-gray-500",children:(0,s.jsx)(_.Zg,{date:e.updated_at?new Date(1e3*e.updated_at):null})}),(0,s.jsx)(f.pj,{children:(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),!1!==e.is_pinnable&&r(e.name,!e.pinned)},disabled:!1===e.is_pinnable,className:"p-1 rounded transition-colors ".concat(!1===e.is_pinnable?"text-gray-300 cursor-not-allowed":e.pinned?"text-amber-500 hover:text-amber-700 hover:bg-amber-100":"text-amber-400 hover:text-amber-600 hover:bg-amber-100"),title:!1===e.is_pinnable?"Default recipes cannot be pinned/unpinned":e.pinned?"Unpin recipe":"Pin recipe",children:e.pinned?(0,s.jsx)(d.Z,{className:"h-4 w-4"}):(0,s.jsx)(u.Z,{className:"h-4 w-4"})}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),!1!==e.is_editable&&i(e)},disabled:!1===e.is_editable,className:"p-1 rounded transition-colors ".concat(!1===e.is_editable?"text-gray-300 cursor-not-allowed":"text-red-400 hover:text-red-700 hover:bg-red-100"),title:!1===e.is_editable?"Default recipes cannot be deleted":"Delete recipe",children:(0,s.jsx)(p.Z,{className:"h-4 w-4"})})]})})]},e.name)})})]})})}),(0,s.jsx)(P,{recipe:l,onClose:()=>i(null),onDelete:n})]})}function P(e){let{recipe:t,onClose:r,onDelete:n}=e,[l,c]=(0,a.useState)(!1),o=async()=>{c(!0);try{await n(t.name),r()}catch(e){(0,L.C)("Delete failed: ".concat(e.message),"error")}finally{c(!1)}};return t?(0,s.jsx)(w.Vq,{open:!!t,onOpenChange:r,children:(0,s.jsxs)(w.cZ,{className:"sm:max-w-md",children:[(0,s.jsxs)(w.fK,{children:[(0,s.jsx)(w.$N,{className:"text-xl text-red-600",children:"Delete Recipe"}),(0,s.jsxs)(w.Be,{children:['Are you sure you want to delete "',t.name,'"? This action cannot be undone.']})]}),(0,s.jsxs)(w.cN,{className:"mt-4",children:[(0,s.jsx)(g.z,{variant:"outline",onClick:r,disabled:l,children:"Cancel"}),(0,s.jsx)(g.z,{onClick:o,disabled:l,className:"bg-red-600 hover:bg-red-700 text-white",children:l?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Z,{size:16,className:"mr-2"}),"Deleting..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(p.Z,{className:"w-4 h-4 mr-2"}),"Delete"]})})]})]})}):null}let A=e=>{let{propertyList:t=[],valueList:r,setFilters:n,placeholder:l="Filter recipes",filters:c=[]}=e,i=(0,a.useRef)(null),o=(0,a.useRef)(null),[d,u]=(0,a.useState)(!1),[p,x]=(0,a.useState)(""),[m,h]=(0,a.useState)("name"),[y,j]=(0,a.useState)([]),g=(0,a.useCallback)(e=>{let r=t.find(t=>t.value===e);return r?r.label:e},[t]);(0,a.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&i.current&&!i.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,a.useEffect)(()=>{let e=[],t=g(m),s=c.filter(e=>e.property===t).map(e=>e.value);r&&"object"==typeof r&&(e=(r[m]||[]).filter(e=>!s.includes(e))),""!==p.trim()&&(e=e.filter(e=>e&&e.toString().toLowerCase().includes(p.toLowerCase()))),j(e)},[m,r,p,c,g]);let f=e=>{n(t=>[...t,{property:g(m),operator:":",value:e}]),u(!1),x(""),i.current.focus()};return(0,s.jsxs)("div",{className:"flex flex-row border border-gray-300 rounded-md overflow-visible",children:[(0,s.jsx)("div",{className:"border-r border-gray-300 flex-shrink-0",children:(0,s.jsxs)(C.Ph,{onValueChange:h,value:m,children:[(0,s.jsx)(C.i4,{"aria-label":"Filter Property",className:"focus:ring-0 focus:ring-offset-0 border-none rounded-l-md rounded-r-none w-20 sm:w-24 md:w-32 h-8 text-xs sm:text-sm",children:(0,s.jsx)(C.ki,{placeholder:"Name"})}),(0,s.jsx)(C.Bw,{children:t.map((e,t)=>(0,s.jsx)(C.Ql,{value:e.value,children:e.label},"property-item-".concat(t)))})]})}),(0,s.jsxs)("div",{className:"relative flex-1",children:[(0,s.jsx)("input",{type:"text",ref:i,placeholder:l,value:p,onChange:e=>{x(e.target.value),d||u(!0)},onFocus:()=>{u(!0)},onKeyDown:e=>{"Enter"===e.key&&""!==p.trim()?(n(e=>[...e,{property:g(m),operator:":",value:p}]),x(""),u(!1)):"Escape"===e.key&&(u(!1),i.current.blur())},className:"h-8 w-full sm:w-96 px-3 pr-8 text-sm border-none rounded-l-none rounded-r-md focus:ring-0 focus:outline-none",autoComplete:"off"}),p&&(0,s.jsx)("button",{onClick:()=>{x(""),u(!1)},className:"absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",title:"Clear filter",tabIndex:-1,children:(0,s.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),d&&y.length>0&&(0,s.jsx)("div",{ref:o,className:"absolute z-50 mt-1 w-full bg-white border border-gray-200 rounded-md shadow-lg max-h-60 overflow-y-auto",style:{zIndex:9999},children:y.map((e,t)=>(0,s.jsx)("div",{className:"px-3 py-2 cursor-pointer hover:bg-gray-50 text-sm ".concat(t!==y.length-1?"border-b border-gray-100":""),onClick:()=>f(e),children:(0,s.jsx)("span",{className:"text-sm text-gray-700",children:e})},"".concat(e,"-").concat(t)))})]})]})},z=e=>{let{filters:t=[],setFilters:r}=e,a=e=>{r(t=>t.filter((t,r)=>r!==e))};return(0,s.jsx)("div",{className:"flex items-center gap-4 py-2 px-2 mb-2",children:(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[t.map((e,t)=>(0,s.jsx)(U,{filter:e,onRemove:()=>a(t)},"filteritem-".concat(t))),t.length>0&&(0,s.jsx)("button",{onClick:()=>{r([])},className:"rounded-full px-4 py-1 text-sm text-gray-700 bg-gray-200 hover:bg-gray-300",children:"Clear filters"})]})})},U=e=>{let{filter:t,onRemove:r}=e;return(0,s.jsxs)("div",{className:"flex items-center text-blue-600 bg-blue-100 px-1 py-1 rounded-full text-sm",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 px-2",children:[(0,s.jsx)("span",{children:t.property}),(0,s.jsx)("span",{children:t.operator}),(0,s.jsx)("span",{children:t.value})]}),(0,s.jsx)("button",{onClick:r,className:"p-0.5 ml-1 text-gray-400 hover:text-gray-600 bg-blue-500 hover:bg-blue-600 rounded-full flex items-center",title:"Remove filter",children:(0,s.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"white",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:5,d:"M6 18L18 6M6 6l12 12"})})})]})};function D(e){switch(e){case Z.nT.CLUSTER:return'name: my-cluster\nresources:\n  infra: aws\n  accelerators: A100:1\n\nrun: |\n  echo "Hello, SkyPilot!"\n';case Z.nT.JOB:return'name: my-job\nresources:\n  infra: aws\n  accelerators: A100:1\n\nrun: |\n  echo "Running managed job..."\n';case Z.nT.POOL:return"pool:\n  name: my-pool\n\nresources:\n  infra: aws\n  accelerators: A100:1\n";default:return"name: my-".concat(e,'\nresources:\n  infra: aws\n  accelerators: A100:1\n\nrun: |\n  echo "Hello, SkyPilot!"\n')}}function F(e){let{isOpen:t,onClose:r,onSubmit:n,initialData:l,isAuthenticated:c}=e,[d,u]=(0,a.useState)(""),[p,m]=(0,a.useState)(""),[h,y]=(0,a.useState)(D(Z.nT.CLUSTER)),[j,f]=(0,a.useState)(Z.nT.CLUSTER),[b,_]=(0,a.useState)(""),[L,S]=(0,a.useState)(!1),[M,R]=(0,a.useState)(null);(0,a.useEffect)(()=>{t&&(l?(u(l.name||""),m(l.description||""),y(l.content||""),f(l.recipe_type||Z.nT.CLUSTER)):(u(""),m(""),f(Z.nT.CLUSTER),y(D(Z.nT.CLUSTER))),_(""),R(null))},[l,t]);let E=async e=>{e.preventDefault(),S(!0),R(null);try{o.ZP.load(h)}catch(e){R("Invalid YAML: ".concat(e.message)),S(!1);return}try{await n({name:d,description:p||null,content:h,recipeType:j,ownerName:b||null}),r()}catch(e){R(e.message)}finally{S(!1)}};return(0,s.jsx)(w.Vq,{open:t,onOpenChange:r,children:(0,s.jsxs)(w.cZ,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto px-8",children:[(0,s.jsxs)(w.fK,{children:[(0,s.jsx)(w.$N,{className:"text-xl text-gray-900",children:"Create New Recipe"}),(0,s.jsx)(w.Be,{children:"Create a reusable recipe for clusters, jobs, and more."})]}),(0,s.jsxs)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 flex items-start gap-2 mt-4",children:[(0,s.jsx)(x.Z,{className:"w-4 h-4 text-amber-600 mt-0.5 flex-shrink-0"}),(0,s.jsx)("p",{className:"text-sm text-amber-800",children:"This recipe will be visible to everyone with access to this dashboard."})]}),(0,s.jsxs)("form",{onSubmit:E,className:"space-y-4 mt-4",children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(N._,{htmlFor:"name",children:"Name *"}),(0,s.jsx)(v.I,{id:"name",value:d,onChange:e=>{u(e.target.value),R(null)},placeholder:"my-gpu-training",className:"placeholder:text-gray-400",required:!0})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(N._,{htmlFor:"recipe-type",children:"Type *"}),(0,s.jsxs)(C.Ph,{value:j,onValueChange:e=>{(h===D(j)||""===h)&&y(D(e)),f(e)},children:[(0,s.jsx)(C.i4,{children:(0,s.jsx)(C.ki,{placeholder:"Select type"})}),(0,s.jsx)(C.Bw,{children:Z.Ft.map(e=>{let t=(0,Z.NL)(e),r=t.icon;return(0,s.jsx)(C.Ql,{value:e,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(r,{className:"w-4 h-4 ".concat(t.colorClass)}),(0,s.jsx)("span",{children:t.fullLabel})]})},e)})})]})]})]}),!c&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(N._,{htmlFor:"owner-name",children:"Your Name"}),(0,s.jsx)(v.I,{id:"owner-name",value:b,onChange:e=>_(e.target.value),placeholder:"Enter your name (optional)",className:"placeholder:text-gray-400"}),(0,s.jsx)("p",{className:"text-xs text-gray-500",children:"This name will be shown as the template owner."})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(N._,{htmlFor:"description",children:"Description"}),(0,s.jsx)(v.I,{id:"description",value:p,onChange:e=>m(e.target.value),placeholder:"A brief description of what this recipe does...",className:"placeholder:text-gray-400"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(N._,{htmlFor:"content",children:"YAML Content *"}),(0,s.jsx)(k.X,{value:h,onChange:e=>{y(e),R(null)},maxHeight:"400px"})]}),M&&(0,s.jsxs)("div",{className:"rounded-md border border-red-200 bg-red-50 p-3 flex items-start gap-2",children:[(0,s.jsx)(x.Z,{className:"w-4 h-4 text-red-600 mt-0.5 flex-shrink-0"}),(0,s.jsx)("p",{className:"text-sm text-red-800",children:M})]}),(0,s.jsxs)(w.cN,{children:[(0,s.jsx)(g.z,{type:"button",variant:"outline",onClick:r,disabled:L,children:"Cancel"}),(0,s.jsx)(g.z,{type:"submit",disabled:L,className:"bg-sky-600 hover:bg-sky-700 text-white",children:L?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Z,{size:16,className:"mr-2"}),"Creating..."]}):"Create Recipe"})]})]})]})})}function V(){let e=(0,n.useRouter)(),[t,r]=(0,a.useState)([]),[l,c]=(0,a.useState)(null),[o,d]=(0,a.useState)(!1),[p,x]=(0,a.useState)(!0),[g,f]=(0,a.useState)(null),[b,w]=(0,a.useState)(!1),[v,N]=(0,a.useState)(null),k=(0,a.useCallback)(async()=>{try{let e=await fetch("".concat(window.location.origin,"/internal/dashboard/users/role"));if(e.ok){let t=await e.json();c(t.id||"local"),d(t.id&&"local"!==t.id)}else c("local"),d(!1)}catch(e){console.error("Failed to get user info:",e),c("local"),d(!1)}},[]),C=(0,a.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];e&&x(!0);try{let e=await (0,S.iM)();r(e||[]),f(new Date)}catch(e){console.error("Error fetching recipes:",e),(0,L.C)("Error loading recipes: ".concat(e.message),"error")}finally{e&&x(!1)}},[]);(0,a.useEffect)(()=>{if(e.query.copy)try{let t=JSON.parse(e.query.copy);N(t),w(!0),e.replace("/recipes",void 0,{shallow:!0})}catch(e){console.error("Failed to parse copy data:",e)}},[e.query.copy,e]),(0,a.useEffect)(()=>{k(),C(!0)},[k,C]);let Z=t.filter(e=>e.pinned),M=o?t.filter(e=>!e.pinned&&e.user_id===l):[],R=async e=>{await (0,S.kW)({...e,...e.ownerName?{ownerName:e.ownerName}:{}}),(0,L.C)("Recipe created successfully!","success"),await C(),N(null)},E=async(e,t)=>{try{await (0,S.Uu)(e,t)&&((0,L.C)(t?"Recipe pinned!":"Recipe unpinned!","success"),await C())}catch(e){(0,L.C)("Pin operation failed: ".concat(e.message),"error")}},P=async e=>{if(await (0,S.eI)(e))(0,L.C)("Recipe deleted successfully!","success"),await C();else throw Error("Failed to delete recipe")};return p&&0===t.length?(0,s.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,s.jsx)(i.Z,{size:20,className:"mr-2"}),(0,s.jsx)("span",{className:"text-gray-500",children:"Loading..."})]}):(0,s.jsxs)("div",{className:"h-full",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-4 min-h-[20px]",children:[(0,s.jsx)("div",{className:"text-base flex items-center",children:(0,s.jsx)("span",{className:"text-sky-blue leading-none text-base",children:"Recipes"})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 ml-auto",children:[p&&(0,s.jsxs)("div",{className:"flex items-center mr-2",children:[(0,s.jsx)(i.Z,{size:16}),(0,s.jsx)("span",{className:"ml-2 text-gray-500 text-sm",children:"Refreshing..."})]}),!p&&g&&(0,s.jsx)(_.$3,{timestamp:g,className:"mr-2"}),(0,s.jsxs)("button",{onClick:()=>{C(!0)},disabled:p,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,s.jsx)(h.Z,{className:"h-4 w-4 mr-1.5"}),(0,s.jsx)("span",{children:"Refresh"})]}),(0,s.jsxs)("button",{onClick:()=>w(!0),className:"ml-4 bg-sky-600 hover:bg-sky-700 text-white flex items-center rounded-md px-3 py-1 text-sm font-medium transition-colors duration-200",title:"New Recipe",children:[(0,s.jsx)(m.Z,{className:"h-4 w-4 mr-2"}),"New Recipe"]})]})]}),0===t.length?(0,s.jsx)(j.Zb,{children:(0,s.jsx)(()=>(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("p",{className:"text-gray-500 mb-4",children:"No recipes yet"}),(0,s.jsxs)("button",{onClick:()=>w(!0),className:"bg-sky-600 hover:bg-sky-700 text-white flex items-center justify-center mx-auto rounded-md px-3 py-1.5 text-sm font-medium transition-colors duration-200",children:[(0,s.jsx)(m.Z,{className:"h-4 w-4 mr-2"}),"Create Your First Template"]})]}),{})}):(0,s.jsxs)("div",{children:[(0,s.jsx)(T,{title:"Pinned Recipes",icon:u.Z,iconColor:"text-amber-500",recipes:Z,emptyMessage:"No pinned recipes. Pin important recipes for quick access.",onPin:E}),o&&(0,s.jsx)(T,{title:"My Recipes",icon:y.Z,iconColor:"text-sky-500",recipes:M,emptyMessage:"You haven't created any recipes yet."}),(0,s.jsx)(O,{recipes:t,onPin:E,onDelete:P})]}),(0,s.jsx)(F,{isOpen:b,onClose:()=>{w(!1),N(null)},onSubmit:R,initialData:v,isAuthenticated:o})]})}},79586:function(e,t,r){r.d(t,{DI:function(){return c},G3:function(){return n},Uu:function(){return o},eI:function(){return i},iM:function(){return a},kW:function(){return l}});var s=r(47145);async function a(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{let t={pinned_only:e.pinnedOnly||!1,my_recipes_only:e.myRecipesOnly||!1,recipe_type:e.recipeType||null};return await s.x.fetch("/recipes/list",t,"POST")||[]}catch(e){throw console.error("Error fetching YAML templates:",e),e}}async function n(e){try{return await s.x.fetch("/recipes/get",{recipe_name:e})}catch(e){throw console.error("Error fetching Recipe:",e),e}}async function l(e){try{return await s.x.fetch("/recipes/create",{name:e.name,content:e.content,recipe_type:e.recipeType,description:e.description||null,owner_name:e.ownerName||null})}catch(e){throw console.error("Error creating Recipe:",e),e}}async function c(e,t){try{return await s.x.fetch("/recipes/update",{recipe_name:e,description:t.description,content:t.content})}catch(e){throw console.error("Error updating Recipe:",e),e}}async function i(e){try{return await s.x.fetch("/recipes/delete",{recipe_name:e})}catch(e){throw console.error("Error deleting Recipe:",e),e}}async function o(e,t){try{return await s.x.fetch("/recipes/pin",{recipe_name:e,pinned:t})}catch(e){throw console.error("Error toggling Recipe pin status:",e),e}}},56072:function(e,t,r){r.d(t,{Ft:function(){return o},nT:function(){return i},UU:function(){return p},NL:function(){return u}});var s=r(60998);/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let a=(0,s.Z)("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]),n=(0,s.Z)("Briefcase",[["path",{d:"M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16",key:"jecpp"}],["rect",{width:"20",height:"14",x:"2",y:"6",rx:"2",key:"i6l2r4"}]]),l=(0,s.Z)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),c=(0,s.Z)("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]),i=Object.freeze({CLUSTER:"cluster",JOB:"job",POOL:"pool",VOLUME:"volume"}),o=Object.freeze(Object.values(i)),d={sky:"text-sky-600",purple:"text-purple-600",green:"text-green-600",orange:"text-orange-600",gray:"text-gray-600"};function u(e){let t;switch(e){case i.CLUSTER:t={icon:a,color:"sky",label:"Cluster",fullLabel:"Cluster"};break;case i.JOB:t={icon:n,color:"purple",label:"Job",fullLabel:"Managed Job"};break;case i.VOLUME:t={icon:l,color:"green",label:"Volume",fullLabel:"Volume"};break;case i.POOL:t={icon:c,color:"orange",label:"Pool",fullLabel:"Job Pool"};break;default:throw Error("Invalid recipe type: ".concat(e))}return t.colorClass=d[t.color]||"text-gray-600",t}function p(e,t){switch(e){case i.CLUSTER:return"sky launch recipes:".concat(t);case i.JOB:return"sky jobs launch recipes:".concat(t);case i.VOLUME:return"sky volumes apply recipes:".concat(t);case i.POOL:return"sky jobs pool apply recipes:".concat(t);default:throw Error("Invalid recipe type: ".concat(e))}}}}]);