"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1400],{23359:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @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 r=(0,t(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"}]])},81260:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @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 r=(0,t(60998).Z)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},13626:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @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 r=(0,t(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"}]])},61400:function(e,s,t){t.r(s),t.d(s,{RecipeHub:function(){return B}});var r=t(85893),a=t(67294),n=t(11163),l=t(41664),c=t.n(l),i=t(55739),o=t(1272),d=t(81021),m=t(24544),x=t(47603),u=t(96122),p=t(81260),h=t(13626),j=t(23359),b=t(37673),g=t(30803),f=t(68764),y=t(94545),N=t(50326),v=t(42557),w=t(36185);t(69123);var k=t(65089),C=t(62935),_=t(470),S=t(15821),R=t(79586),L=t(98691);let Z=[{label:"Name",value:"name"},{label:"Type",value:"recipe_type"},{label:"Owner",value:"user_name"}];function T(e){let{name:s,className:t=""}=e;if(!s)return(0,r.jsx)("span",{className:t,children:"Unknown"});if(s.includes("@")){let e=s.split("@")[0];return(0,r.jsx)(_.Md,{content:s,children:(0,r.jsx)("span",{className:"border-b border-dotted border-gray-400 cursor-help ".concat(t),children:e})})}return(0,r.jsx)("span",{className:t,children:s})}function E(e){let{recipe:s,onPin:t}=e,a=(0,L.NL)(s.recipe_type),n=a.icon,l=s.name;return(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(c(),{href:"/recipes/".concat(l),className:"block",children:(0,r.jsx)(b.Zb,{className:"h-full hover:bg-gray-50 transition-colors cursor-pointer group",children:(0,r.jsxs)(b.aY,{className:"p-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2 mb-1.5",children:[(0,r.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,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsx)("h3",{className:"text-base font-medium text-blue-600 truncate group-hover:text-blue-800 transition-colors",children:s.name})})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("div",{className:"text-sm text-gray-500",children:a.label}),s.description&&(0,r.jsx)("p",{className:"text-sm text-gray-600 truncate",title:s.description,children:s.description}),(0,r.jsxs)("div",{className:"text-sm text-gray-500 truncate",children:["Authored by"," ",(0,r.jsx)(T,{name:s.user_name||s.user_id})]}),s.is_editable&&"local"!==s.user_name&&(0,r.jsxs)("div",{className:"text-sm text-gray-500 truncate",children:["Updated by"," ",(0,r.jsx)(T,{name:s.updated_by_name||s.user_name})," ",(0,r.jsx)(_.Zg,{date:s.updated_at?new Date(1e3*s.updated_at):null})]})]})]})})}),t&&s.pinned&&!1!==s.is_pinnable&&(0,r.jsx)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),t(s.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,r.jsx)(d.Z,{className:"h-4 w-4"})})]})}function M(e){let{title:s,icon:t,recipes:a,emptyMessage:n,iconColor:l,onPin:c}=e;return 0===a.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,r.jsx)(t,{className:"w-4 h-4 ".concat(l)}),(0,r.jsx)("h2",{className:"text-base text-gray-700",children:s}),(0,r.jsxs)("span",{className:"text-sm text-gray-500",children:["(",a.length,")"]})]}),(0,r.jsx)("div",{className:"text-center py-6 bg-white rounded-lg border border-gray-200 shadow-sm",children:(0,r.jsx)("p",{className:"text-gray-500",children:n})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,r.jsx)(t,{className:"w-4 h-4 ".concat(l)}),(0,r.jsx)("h2",{className:"text-base text-gray-700",children:s}),(0,r.jsxs)("span",{className:"text-sm text-gray-500",children:["(",a.length,")"]})]}),(0,r.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:a.map(e=>(0,r.jsx)(E,{recipe:e,onPin:c},e.name))})]})}function F(e){let{recipes:s,onPin:t,onDelete:n}=e,[l,i]=(0,a.useState)(null),[o,u]=(0,a.useState)([]),[p,h]=(0,a.useState)({key:"updated_at",direction:"descending"}),j=(0,a.useMemo)(()=>{let e=new Set,t=new Set,r=new Set;return s.forEach(s=>{s.name&&e.add(s.name),s.recipe_type&&t.add(s.recipe_type),s.user_name?r.add(s.user_name):s.user_id&&r.add(s.user_id)}),{name:Array.from(e).sort(),recipe_type:Array.from(t).sort(),user_name:Array.from(r).sort()}},[s]),g=e=>{let s="ascending";p.key===e&&"ascending"===p.direction&&(s="descending"),h({key:e,direction:s})},N=e=>p.key===e?"ascending"===p.direction?" ↑":" ↓":"",v=(0,a.useMemo)(()=>{let e=s;return o.length>0&&(e=e.filter(e=>{for(let s of o){let t=s.property.toLowerCase().replace(" ","_"),r="";if("name"===t?r=e.name||"":"type"===t?r=e.recipe_type||"":"owner"===t&&(r=e.user_name||e.user_id||""),!r.toLowerCase().includes(s.value.toLowerCase()))return!1}return!0})),(0,y.R0)(e,p.key,p.direction)},[s,o,p]);return(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[(0,r.jsx)("span",{className:"text-base text-gray-700",children:"All Recipes"}),(0,r.jsx)("div",{className:"w-full sm:w-auto",children:(0,r.jsx)(P,{propertyList:Z,valueList:j,setFilters:u,placeholder:"Filter recipes",filters:o})}),(0,r.jsxs)("span",{className:"text-sm text-gray-500 ml-auto",children:[v.length," of ",s.length]})]}),o.length>0&&(0,r.jsx)(A,{filters:o,setFilters:u}),(0,r.jsx)(b.Zb,{children:(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,r.jsxs)(f.iA,{className:"min-w-full",children:[(0,r.jsx)(f.xD,{children:(0,r.jsxs)(f.SC,{children:[(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("recipe_type"),children:["Type",N("recipe_type")]}),(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("name"),children:["Name",N("name")]}),(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("description"),children:["Description",N("description")]}),(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("user_name"),children:["Owner",N("user_name")]}),(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("updated_by_name"),children:["Last Updated By",N("updated_by_name")]}),(0,r.jsxs)(f.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>g("updated_at"),children:["Updated",N("updated_at")]}),(0,r.jsx)(f.ss,{className:"whitespace-nowrap w-[100px]",children:"Actions"})]})}),(0,r.jsx)(f.RM,{children:0===v.length?(0,r.jsx)(f.SC,{children:(0,r.jsx)(f.pj,{colSpan:7,className:"text-center py-6 text-gray-500",children:0===s.length?"No recipes available.":"No recipes match your filter criteria."})}):v.map(e=>{let s=(0,L.NL)(e.recipe_type),a=s.icon,n=e.name,l=e.description?e.description.length>80?e.description.substring(0,80)+"...":e.description:"-";return(0,r.jsxs)(f.SC,{className:"hover:bg-gray-50",children:[(0,r.jsx)(f.pj,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(a,{className:"w-4 h-4 ".concat("sky"===s.color?"text-sky-600":"purple"===s.color?"text-purple-600":"green"===s.color?"text-green-600":"orange"===s.color?"text-orange-600":"text-gray-600")}),(0,r.jsx)("span",{children:s.label})]})}),(0,r.jsx)(f.pj,{children:(0,r.jsx)(c(),{href:"/recipes/".concat(n),className:"text-blue-600 hover:text-blue-800 hover:underline",children:e.name})}),(0,r.jsx)(f.pj,{className:"text-gray-600 max-w-[400px]",title:e.description||"",children:(0,r.jsx)("span",{className:"cursor-default",children:l})}),(0,r.jsx)(f.pj,{className:"text-gray-600",children:(0,r.jsx)(T,{name:e.user_name||e.user_id})}),(0,r.jsx)(f.pj,{className:"text-gray-600",children:e.updated_by_name||e.user_name?(0,r.jsx)(T,{name:e.updated_by_name||e.user_name}):"-"}),(0,r.jsx)(f.pj,{className:"text-gray-500",children:(0,r.jsx)(_.Zg,{date:e.updated_at?new Date(1e3*e.updated_at):null})}),(0,r.jsx)(f.pj,{children:(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{onClick:s=>{s.stopPropagation(),!1!==e.is_pinnable&&t(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,r.jsx)(d.Z,{className:"h-4 w-4"}):(0,r.jsx)(m.Z,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:s=>{s.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,r.jsx)(x.Z,{className:"h-4 w-4"})})]})})]},e.name)})})]})})}),(0,r.jsx)(D,{recipe:l,onClose:()=>i(null),onDelete:n})]})}function D(e){let{recipe:s,onClose:t,onDelete:n}=e,[l,c]=(0,a.useState)(!1),o=async()=>{c(!0);try{await n(s.name),t()}catch(e){(0,S.C)("Delete failed: ".concat(e.message),"error")}finally{c(!1)}};return s?(0,r.jsx)(N.Vq,{open:!!s,onOpenChange:t,children:(0,r.jsxs)(N.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(N.fK,{children:[(0,r.jsx)(N.$N,{className:"text-xl text-red-600",children:"Delete Recipe"}),(0,r.jsxs)(N.Be,{children:['Are you sure you want to delete "',s.name,'"? This action cannot be undone.']})]}),(0,r.jsxs)(N.cN,{className:"mt-4",children:[(0,r.jsx)(g.z,{variant:"outline",onClick:t,disabled:l,children:"Cancel"}),(0,r.jsx)(g.z,{onClick:o,disabled:l,className:"bg-red-600 hover:bg-red-700 text-white",children:l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.Z,{size:16,className:"mr-2"}),"Deleting..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(x.Z,{className:"w-4 h-4 mr-2"}),"Delete"]})})]})]})}):null}let P=e=>{let{propertyList:s=[],valueList:t,setFilters:n,placeholder:l="Filter recipes",filters:c=[]}=e,i=(0,a.useRef)(null),o=(0,a.useRef)(null),[d,m]=(0,a.useState)(!1),[x,u]=(0,a.useState)(""),[p,h]=(0,a.useState)("name"),[j,b]=(0,a.useState)([]),g=(0,a.useCallback)(e=>{let t=s.find(s=>s.value===e);return t?t.label:e},[s]);(0,a.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&i.current&&!i.current.contains(e.target)&&m(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,a.useEffect)(()=>{let e=[],s=g(p),r=c.filter(e=>e.property===s).map(e=>e.value);t&&"object"==typeof t&&(e=(t[p]||[]).filter(e=>!r.includes(e))),""!==x.trim()&&(e=e.filter(e=>e&&e.toString().toLowerCase().includes(x.toLowerCase()))),b(e)},[p,t,x,c,g]);let f=e=>{n(s=>[...s,{property:g(p),operator:":",value:e}]),m(!1),u(""),i.current.focus()};return(0,r.jsxs)("div",{className:"flex flex-row border border-gray-300 rounded-md overflow-visible",children:[(0,r.jsx)("div",{className:"border-r border-gray-300 flex-shrink-0",children:(0,r.jsxs)(C.Ph,{onValueChange:h,value:p,children:[(0,r.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,r.jsx)(C.ki,{placeholder:"Name"})}),(0,r.jsx)(C.Bw,{children:s.map((e,s)=>(0,r.jsx)(C.Ql,{value:e.value,children:e.label},"property-item-".concat(s)))})]})}),(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)("input",{type:"text",ref:i,placeholder:l,value:x,onChange:e=>{u(e.target.value),d||m(!0)},onFocus:()=>{m(!0)},onKeyDown:e=>{"Enter"===e.key&&""!==x.trim()?(n(e=>[...e,{property:g(p),operator:":",value:x}]),u(""),m(!1)):"Escape"===e.key&&(m(!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"}),x&&(0,r.jsx)("button",{onClick:()=>{u(""),m(!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,r.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),d&&j.length>0&&(0,r.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:j.map((e,s)=>(0,r.jsx)("div",{className:"px-3 py-2 cursor-pointer hover:bg-gray-50 text-sm ".concat(s!==j.length-1?"border-b border-gray-100":""),onClick:()=>f(e),children:(0,r.jsx)("span",{className:"text-sm text-gray-700",children:e})},"".concat(e,"-").concat(s)))})]})]})},A=e=>{let{filters:s=[],setFilters:t}=e,a=e=>{t(s=>s.filter((s,t)=>t!==e))};return(0,r.jsx)("div",{className:"flex items-center gap-4 py-2 px-2 mb-2",children:(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[s.map((e,s)=>(0,r.jsx)(U,{filter:e,onRemove:()=>a(s)},"filteritem-".concat(s))),s.length>0&&(0,r.jsx)("button",{onClick:()=>{t([])},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:s,onRemove:t}=e;return(0,r.jsxs)("div",{className:"flex items-center text-blue-600 bg-blue-100 px-1 py-1 rounded-full text-sm",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2",children:[(0,r.jsx)("span",{children:s.property}),(0,r.jsx)("span",{children:s.operator}),(0,r.jsx)("span",{children:s.value})]}),(0,r.jsx)("button",{onClick:t,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,r.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"white",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:5,d:"M6 18L18 6M6 6l12 12"})})})]})};function z(e){switch(e){case L.nT.CLUSTER:return'name: my-cluster\nresources:\n  infra: aws\n  accelerators: A100:1\n\nrun: |\n  echo "Hello, SkyPilot!"\n';case L.nT.JOB:return'name: my-job\nresources:\n  infra: aws\n  accelerators: A100:1\n\nrun: |\n  echo "Running managed job..."\n';case L.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 q(e){let{isOpen:s,onClose:t,onSubmit:n,initialData:l,isAuthenticated:c}=e,[d,m]=(0,a.useState)(""),[x,p]=(0,a.useState)(""),[h,j]=(0,a.useState)(z(L.nT.CLUSTER)),[b,f]=(0,a.useState)(L.nT.CLUSTER),[y,_]=(0,a.useState)(""),[S,R]=(0,a.useState)(!1),[Z,T]=(0,a.useState)(null);(0,a.useEffect)(()=>{s&&(l?(m(l.name||""),p(l.description||""),j(l.content||""),f(l.recipe_type||L.nT.CLUSTER)):(m(""),p(""),f(L.nT.CLUSTER),j(z(L.nT.CLUSTER))),_(""),T(null))},[l,s]);let E=async e=>{e.preventDefault(),R(!0),T(null);try{o.ZP.load(h)}catch(e){T("Invalid YAML: ".concat(e.message)),R(!1);return}try{await n({name:d,description:x||null,content:h,recipeType:b,ownerName:y||null}),t()}catch(e){T(e.message)}finally{R(!1)}};return(0,r.jsx)(N.Vq,{open:s,onOpenChange:t,children:(0,r.jsxs)(N.cZ,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto px-8",children:[(0,r.jsxs)(N.fK,{children:[(0,r.jsx)(N.$N,{className:"text-xl text-gray-900",children:"Create New Recipe"}),(0,r.jsx)(N.Be,{children:"Create a reusable recipe for clusters, jobs, and more."})]}),(0,r.jsxs)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 flex items-start gap-2 mt-4",children:[(0,r.jsx)(u.Z,{className:"w-4 h-4 text-amber-600 mt-0.5 flex-shrink-0"}),(0,r.jsx)("p",{className:"text-sm text-amber-800",children:"This recipe will be visible to everyone with access to this dashboard."})]}),(0,r.jsxs)("form",{onSubmit:E,className:"space-y-4 mt-4",children:[(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w._,{htmlFor:"name",children:"Name *"}),(0,r.jsx)(v.I,{id:"name",value:d,onChange:e=>{m(e.target.value),T(null)},placeholder:"my-gpu-training",className:"placeholder:text-gray-400",required:!0})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w._,{htmlFor:"recipe-type",children:"Type *"}),(0,r.jsxs)(C.Ph,{value:b,onValueChange:e=>{(h===z(b)||""===h)&&j(z(e)),f(e)},children:[(0,r.jsx)(C.i4,{children:(0,r.jsx)(C.ki,{placeholder:"Select type"})}),(0,r.jsx)(C.Bw,{children:L.Ft.map(e=>{let s=(0,L.NL)(e),t=s.icon;return(0,r.jsx)(C.Ql,{value:e,children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(t,{className:"w-4 h-4 ".concat(s.colorClass)}),(0,r.jsx)("span",{children:s.fullLabel})]})},e)})})]})]})]}),!c&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w._,{htmlFor:"owner-name",children:"Your Name"}),(0,r.jsx)(v.I,{id:"owner-name",value:y,onChange:e=>_(e.target.value),placeholder:"Enter your name (optional)",className:"placeholder:text-gray-400"}),(0,r.jsx)("p",{className:"text-xs text-gray-500",children:"This name will be shown as the template owner."})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w._,{htmlFor:"description",children:"Description"}),(0,r.jsx)(v.I,{id:"description",value:x,onChange:e=>p(e.target.value),placeholder:"A brief description of what this recipe does...",className:"placeholder:text-gray-400"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w._,{htmlFor:"content",children:"YAML Content *"}),(0,r.jsx)(k.X,{value:h,onChange:e=>{j(e),T(null)},maxHeight:"400px"})]}),Z&&(0,r.jsxs)("div",{className:"rounded-md border border-red-200 bg-red-50 p-3 flex items-start gap-2",children:[(0,r.jsx)(u.Z,{className:"w-4 h-4 text-red-600 mt-0.5 flex-shrink-0"}),(0,r.jsx)("p",{className:"text-sm text-red-800",children:Z})]}),(0,r.jsxs)(N.cN,{children:[(0,r.jsx)(g.z,{type:"button",variant:"outline",onClick:t,disabled:S,children:"Cancel"}),(0,r.jsx)(g.z,{type:"submit",disabled:S,className:"bg-sky-600 hover:bg-sky-700 text-white",children:S?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.Z,{size:16,className:"mr-2"}),"Creating..."]}):"Create Recipe"})]})]})]})})}function B(){let e=(0,n.useRouter)(),[s,t]=(0,a.useState)([]),[l,c]=(0,a.useState)(null),[o,d]=(0,a.useState)(!1),[x,u]=(0,a.useState)(!0),[g,f]=(0,a.useState)(null),[y,N]=(0,a.useState)(!1),[v,w]=(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 s=await e.json();c(s.id||"local"),d(s.id&&"local"!==s.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&&u(!0);try{let e=await (0,R.iM)();t(e||[]),f(new Date)}catch(e){console.error("Error fetching recipes:",e),(0,S.C)("Error loading recipes: ".concat(e.message),"error")}finally{e&&u(!1)}},[]);(0,a.useEffect)(()=>{if(e.query.copy)try{let s=JSON.parse(e.query.copy);w(s),N(!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 L=s.filter(e=>e.pinned),Z=o?s.filter(e=>!e.pinned&&e.user_id===l):[],T=async e=>{await (0,R.kW)({...e,...e.ownerName?{ownerName:e.ownerName}:{}}),(0,S.C)("Recipe created successfully!","success"),await C(),w(null)},E=async(e,s)=>{try{await (0,R.Uu)(e,s)&&((0,S.C)(s?"Recipe pinned!":"Recipe unpinned!","success"),await C())}catch(e){(0,S.C)("Pin operation failed: ".concat(e.message),"error")}},D=async e=>{if(await (0,R.eI)(e))(0,S.C)("Recipe deleted successfully!","success"),await C();else throw Error("Failed to delete recipe")};return x&&0===s.length?(0,r.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,r.jsx)(i.Z,{size:20,className:"mr-2"}),(0,r.jsx)("span",{className:"text-gray-500",children:"Loading..."})]}):(0,r.jsxs)("div",{className:"h-full",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-4 min-h-[20px]",children:[(0,r.jsx)("div",{className:"text-base flex items-center",children:(0,r.jsx)("span",{className:"text-sky-blue leading-none text-base",children:"Recipes"})}),(0,r.jsxs)("div",{className:"flex items-center gap-2 ml-auto",children:[x&&(0,r.jsxs)("div",{className:"flex items-center mr-2",children:[(0,r.jsx)(i.Z,{size:16}),(0,r.jsx)("span",{className:"ml-2 text-gray-500 text-sm",children:"Refreshing..."})]}),!x&&g&&(0,r.jsx)(_.$3,{timestamp:g,className:"mr-2"}),(0,r.jsxs)("button",{onClick:()=>{C(!0)},disabled:x,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,r.jsx)(h.Z,{className:"h-4 w-4 mr-1.5"}),(0,r.jsx)("span",{children:"Refresh"})]}),(0,r.jsxs)("button",{onClick:()=>N(!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,r.jsx)(p.Z,{className:"h-4 w-4 mr-2"}),"New Recipe"]})]})]}),0===s.length?(0,r.jsx)(b.Zb,{children:(0,r.jsx)(()=>(0,r.jsxs)("div",{className:"text-center py-12",children:[(0,r.jsx)("p",{className:"text-gray-500 mb-4",children:"No recipes yet"}),(0,r.jsxs)("button",{onClick:()=>N(!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,r.jsx)(p.Z,{className:"h-4 w-4 mr-2"}),"Create Your First Template"]})]}),{})}):(0,r.jsxs)("div",{children:[(0,r.jsx)(M,{title:"Pinned Recipes",icon:m.Z,iconColor:"text-amber-500",recipes:L,emptyMessage:"No pinned recipes. Pin important recipes for quick access.",onPin:E}),o&&(0,r.jsx)(M,{title:"My Recipes",icon:j.Z,iconColor:"text-sky-500",recipes:Z,emptyMessage:"You haven't created any recipes yet."}),(0,r.jsx)(F,{recipes:s,onPin:E,onDelete:D})]}),(0,r.jsx)(q,{isOpen:y,onClose:()=>{N(!1),w(null)},onSubmit:T,initialData:v,isAuthenticated:o})]})}},68764:function(e,s,t){t.d(s,{RM:function(){return i},SC:function(){return o},iA:function(){return l},pj:function(){return m},ss:function(){return d},xD:function(){return c}});var r=t(85893),a=t(67294),n=t(46990);let l=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("div",{className:"relative w-full overflow-auto",children:(0,r.jsx)("table",{ref:s,className:(0,n.cn)("w-full caption-bottom text-base",t),...a})})});l.displayName="Table";let c=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("thead",{ref:s,className:(0,n.cn)("[&_tr]:border-b",t),...a})});c.displayName="TableHeader";let i=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("tbody",{ref:s,className:(0,n.cn)("[&_tr:last-child]:border-0",t),...a})});i.displayName="TableBody",a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("tfoot",{ref:s,className:(0,n.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...a})}).displayName="TableFooter";let o=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("tr",{ref:s,className:(0,n.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...a})});o.displayName="TableRow";let d=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("th",{ref:s,className:(0,n.cn)("h-12 px-4 text-left align-middle font-medium text-[hsl(var(--text-strong))] [&:has([role=checkbox])]:pr-0",t),...a})});d.displayName="TableHead";let m=a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("td",{ref:s,className:(0,n.cn)("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...a})});m.displayName="TableCell",a.forwardRef((e,s)=>{let{className:t,...a}=e;return(0,r.jsx)("caption",{ref:s,className:(0,n.cn)("mt-4 text-base text-muted-foreground",t),...a})}).displayName="TableCaption"}}]);