import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{t}from"./chevron-left-DEkgazsy.js";import{$h as n,Da as r,Fg as i,Fy as a,Gy as o,Hy as s,Jd as c,Mg as l,Tc as u,Tt as d,Ua as f,Yv as p,_h as m,ap as h,dg as g,jg as _,lh as v,ll as y,m_ as b,mv as x,nc as S,ph as C,pl as w,sn as T,ty as E,wd as D,xt as O}from"./index-DDwwBb9e.js";import{t as k}from"./WithPermissionGuard-wX0IC3VF.js";import{t as A}from"./NoDataInfoBlock-B05u0nqM.js";var j=e(o()),M=e(n());function N(){return N=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},N.apply(this,arguments)}function P(e,t){if(e==null)return{};var n=F(e,t),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)r=a[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function F(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}var I=(0,j.forwardRef)(function(e,t){var n=e.color,r=n===void 0?`currentColor`:n,i=e.size,a=i===void 0?24:i,o=P(e,[`color`,`size`]);return j.createElement(`svg`,N({ref:t,xmlns:`http://www.w3.org/2000/svg`,width:a,height:a,viewBox:`0 0 24 24`,fill:`none`,stroke:r,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},o),j.createElement(`path`,{d:`M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z`}),j.createElement(`polyline`,{points:`13 2 13 9 20 9`}))});I.propTypes={color:M.default.string,size:M.default.oneOfType([M.default.string,M.default.number])},I.displayName=`File`;var L={blank:y,custom_evaluator:O},R=s(),z=5*1024*1024;function B(e){let[t,n]=(0,j.useState)(!1),r=(0,j.useRef)(null);return{isDragging:t,fileInputRef:r,handleDragOver:(0,j.useCallback)(e=>{e.preventDefault(),n(!0)},[]),handleDragLeave:(0,j.useCallback)(()=>{n(!1)},[]),handleDrop:(0,j.useCallback)(t=>{t.preventDefault(),n(!1);let r=t.dataTransfer.files[0];r&&e(r)},[e]),handleClick:(0,j.useCallback)(()=>{r.current?.click()},[]),handleFileInputChange:(0,j.useCallback)(t=>{let n=t.target.files?.[0];n&&e(n)},[e])}}var V=({open:e,onClose:n})=>{let[o,s]=(0,j.useState)({step:`select`});(0,j.useEffect)(()=>{e||s({step:`select`})},[e]);let{isDragging:c,fileInputRef:l,handleDragOver:f,handleDragLeave:p,handleDrop:h,handleClick:g,handleFileInputChange:_}=B((0,j.useCallback)(e=>{if(e.size>z){C.create({title:`File too large`,description:`File size must be less than 5MB`,type:`error`,meta:{closable:!0}});return}let t=new FileReader;t.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),r=S.safeParse(n);if(!r.success){let e=r.error.errors.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`
`);throw Error(e)}s({step:`create`,template:r.data})}catch(e){C.create({title:`Invalid workflow file`,description:e instanceof Error?e.message:`Unknown error occurred`,type:`error`,meta:{closable:!0}})}},t.readAsText(e)},[s]));return(0,R.jsx)(u.Root,{open:e,onOpenChange:({open:e})=>!e&&n(),size:`xl`,children:(0,R.jsxs)(u.Content,{bg:`bg`,paddingX:0,children:[(0,R.jsx)(u.Header,{children:(0,R.jsxs)(b,{gap:2,children:[o.step===`create`&&(0,R.jsx)(x,{variant:`ghost`,"data-variant":`ghost`,onClick:()=>s({step:`select`}),size:`sm`,paddingX:0,marginLeft:-2,marginBottom:-2,marginTop:-2,children:(0,R.jsx)(t,{})}),(0,R.jsx)(E,{children:`Create new workflow`})]})}),(0,R.jsx)(i,{}),(0,R.jsx)(u.CloseTrigger,{}),o.step===`select`?(0,R.jsx)(u.Body,{paddingY:6,marginBottom:6,children:(0,R.jsxs)(a,{width:`full`,templateColumns:`repeat(auto-fill, minmax(260px, 1fr))`,gap:6,children:[Object.entries(L).map(([e,t])=>(0,R.jsx)(d,{"data-testid":`new-workflow-card-${e}`,name:t.name,icon:e===`blank`?(0,R.jsx)(I,{color:`var(--chakra-colors-fg-muted)`,size:16}):t.icon,description:t.description,onClick:()=>s({step:`create`,template:e===`blank`?{...t,name:`New Workflow`,icon:`🧩`,description:``}:t})},e)),(0,R.jsx)(d,{"data-testid":`new-workflow-card-import`,name:`From Export`,icon:(0,R.jsx)(m,{color:`var(--chakra-colors-fg-muted)`,size:16}),description:`Import a workflow from an exported JSON file`,onClick:g,onDragOver:f,onDragLeave:p,onDrop:h,...c?{borderStyle:`dashed`,borderColor:`blue.500`}:{},children:(0,R.jsx)(`input`,{ref:l,type:`file`,accept:`.json`,style:{display:`none`},onChange:_})})]})}):(0,R.jsx)(r,{onClose:n,template:o.template})]})})};function H(){let{project:e}=h(),{open:t,onClose:n,onOpen:r}=p(),i=v.workflow.getAll.useQuery({projectId:e?.id??``},{enabled:!!e}),o=i.data&&i.data.length>0,s=!i.isLoading&&!o;return(0,R.jsxs)(T,{children:[(0,R.jsxs)(f.Header,{children:[(0,R.jsx)(f.Heading,{children:`Workflows`}),(0,R.jsx)(_,{}),(0,R.jsxs)(f.HeaderButton,{onClick:r,children:[(0,R.jsx)(c,{size:16}),` New Workflow`]})]}),s?(0,R.jsx)(f.Container,{children:(0,R.jsx)(f.Content,{children:(0,R.jsx)(A,{title:`No workflows yet`,description:`Create reusable workflows with the Optimization Studio.`,icon:(0,R.jsx)(D,{size:24}),color:`blue.500`,children:(0,R.jsxs)(f.HeaderButton,{onClick:r,marginTop:4,children:[(0,R.jsx)(c,{size:16}),` Create your first workflow`]})})})}):(0,R.jsx)(g,{gap:6,width:`full`,align:`start`,padding:6,children:(0,R.jsxs)(a,{templateColumns:`repeat(auto-fill, minmax(260px, 1fr))`,gap:6,width:`full`,children:[i.isLoading&&Array.from({length:3}).map((e,t)=>(0,R.jsx)(l,{height:`200px`},t)),i.data?.map(t=>(0,R.jsx)(w,{href:`/${e?.slug}/studio/${t.id}`,display:`block`,asChild:!0,children:(0,R.jsx)(d,{workflowId:t.id,query:i,name:t.name,icon:t.icon,onClick:e=>{let t=e.target;for(;t.parentElement;){if(t.classList.contains(`js-inner-menu`))return e.stopPropagation(),e.preventDefault(),!1;t=t.parentElement}}})},t.id))]})}),(0,R.jsx)(V,{open:t,onClose:n})]})}var U=k(`workflows:view`,{layoutComponent:T})(H);export{U as default};
//# sourceMappingURL=workflows-V-AuIFnm.js.map