import{r as u,u as R,j as e,B as x,I as v,f as N,bn as w,R as B,bo as U}from"./index-f9c70843.js";import{u as p}from"./shortcuts-faa601b8.js";function F({children:f,shortcut:l,defaultShortcuts:r,defaultCombination:L,open:m,setOpen:h,disable:j,setSelected:y}){var k;let d=r.length>0?(k=r.find(s=>{var t;return s.name.split(" ")[0].toLowerCase().toLowerCase()===((t=l[0])==null?void 0:t.split(" ")[0].toLowerCase())}))==null?void 0:k.shortcut:"";const[o,c]=u.useState(null),b=R(s=>s.setSuccessData),C=p(s=>s.setShortcuts),a=R(s=>s.setErrorData);function g(s){let t=!0;return r.forEach(({shortcut:n})=>{n.toLowerCase()===s.toLowerCase()&&(t=!1)}),t}const S=p(s=>s.updateUniqueShortcut);function q(){if(o&&g(o)){const s=r.map(i=>i.name===l[0]?{name:i.name,shortcut:o}:{name:i.name,shortcut:i.shortcut}),t=o.split(" ");(t[0].toLowerCase().includes("ctrl")||t[0].toLowerCase().includes("cmd"))&&(t[0]="mod");const n=l[0].split(" ")[0].toLowerCase();S(n,t.join("").toLowerCase()),C(s),localStorage.setItem("langflow-shortcuts",JSON.stringify(s)),c(null),h(!1),b({title:`${l[0]} shortcut successfully changed`});return}a({title:"Error saving key combination",list:["This combination already exists!"]})}u.useEffect(()=>{m||(c(null),y([]))},[m,h,o]);function K({oldKey:s,key:t}){return s===null?`${t.length>0?w(t):w(t)}`:`${s.length>0?w(s):s.toUpperCase()} + ${t.length>0?w(t):t.toUpperCase()}`}function T(s,t){return s.split(" ").some(i=>i.toLowerCase().trim()===t.toLowerCase().trim())}return u.useEffect(()=>{function s(t){var i,E,D;t.preventDefault();let n=t.key;((i=t.key)==null?void 0:i.toLowerCase())==="control"&&(n="Ctrl"),((E=t.key)==null?void 0:E.toLowerCase())==="meta"&&(n="Cmd"),((D=t.key)==null?void 0:D.toLowerCase())===" "&&(n="Space"),!(o&&T(o,n))&&c(A=>K({oldKey:A,key:n}))}return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s)}},[o,c]),e.jsxs(x,{open:m,setOpen:h,size:"x-small",disable:j,children:[e.jsxs(x.Header,{description:"Recording your keyboard",children:[e.jsx("span",{className:"pr-2",children:" Key Combination "}),e.jsx(v,{name:"Keyboard",className:"h-6 w-6 pl-1 text-primary ","aria-hidden":"true"})]}),e.jsx(x.Trigger,{children:f}),e.jsx(x.Content,{children:e.jsx("div",{className:"align-center flex h-full w-full justify-center gap-4 rounded-md border border-border py-2",children:e.jsx("div",{className:"flex items-center justify-center text-center text-lg font-bold",children:o===null?d==null?void 0:d.toUpperCase():o.toUpperCase()})})}),e.jsxs(x.Footer,{children:[e.jsx(N,{variant:"default",onClick:q,children:"Apply"}),e.jsx(N,{className:"mr-5",variant:"destructive",onClick:()=>c(null),children:"Reset"})]})]})}function I(){var C;const[f,l]=u.useState([]),r=p(a=>a.shortcuts),L=p(a=>a.setShortcuts),m=[{headerName:"Functionality",field:"name",flex:1,editable:!1,resizable:!1},{headerName:"Keyboard Shortcut",field:"shortcut",flex:2,editable:!1,resizable:!1}],[h,j]=u.useState([]);u.useEffect(()=>{j(r)},[r]);const y=r.filter(a=>a.name===f[0]),[d,o]=u.useState(!1),c=p(a=>a.updateUniqueShortcut);function b(){L(U),U.forEach(({name:a,shortcut:g})=>{const S=a.split(" ")[0].toLowerCase();c(S,g)}),localStorage.removeItem("langflow-shortcuts")}return e.jsxs("div",{className:"flex h-full w-full flex-col gap-6 ",children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-4 space-y-0.5",children:[e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("h2",{className:"flex items-center text-lg font-semibold tracking-tight",children:["Shortcuts",e.jsx(v,{name:"Keyboard",className:"ml-2 h-5 w-5 text-primary"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage Shortcuts for quick access to frequently used actions."})]}),e.jsx("div",{children:e.jsx("div",{className:"align-end mb-4 flex w-full justify-end",children:e.jsxs("div",{className:"justify center flex items-center",children:[d&&e.jsx(F,{disable:f.length===0,defaultCombination:(C=y[0])==null?void 0:C.shortcut,shortcut:f,defaultShortcuts:r,open:d,setOpen:o,setSelected:l,children:e.jsx("div",{style:{display:"none"}})}),e.jsxs(N,{variant:"primary",className:"ml-3",onClick:b,children:[e.jsx(v,{name:"RotateCcw",className:"mr-2 w-4"}),"Restore"]})]})})})]}),e.jsx("div",{className:"grid gap-6 pb-8",children:e.jsx("div",{children:e.jsx(B,{suppressRowClickSelection:!0,domLayout:"autoHeight",pagination:!1,columnDefs:m,rowData:h,onCellDoubleClicked:a=>{l([a.data.name]),o(!0)}})})})]})}export{I as default};
