import{__assign as e,__awaiter as n,__generator as o}from"tslib";import{jsx as t,jsxs as r}from"react/jsx-runtime";import{useState as i,useRef as l,useEffect as a}from"react";import{X as d}from"lucide-react";var c=function(c){var s=c.isOpen,p=c.onClose,u=c.onSave,f=c.initialName,x=void 0===f?"":f,g=i(x),b=g[0],y=g[1],m=i(""),h=m[0],v=m[1],C=i(!1),S=C[0],E=C[1],k=l(null);if(a(function(){s&&(y(x),v(""),setTimeout(function(){var e,n;null===(e=k.current)||void 0===e||e.focus(),null===(n=k.current)||void 0===n||n.select()},50))},[s,x]),!s)return null;var z=function(){return n(void 0,void 0,void 0,function(){var e,n;return o(this,function(o){switch(o.label){case 0:if(!b.trim())return v("Scope Name is required"),[2];v(""),E(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,u(b.trim())];case 2:return o.sent(),p(),[3,5];case 3:return e=o.sent(),409===(null==(n=e)?void 0:n.status)?v("Scope name already exists."):v("Failed to rename scope. Please try again."),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})};return t("div",e({style:{position:"fixed",inset:0,zIndex:1300,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.3)"},onClick:function(e){e.target===e.currentTarget&&p()}},{children:r("div",e({style:{width:"480px",backgroundColor:"#fff",borderRadius:"12px",boxShadow:"0 20px 60px rgba(0,0,0,0.15)",padding:"24px",fontFamily:"sans-serif"}},{children:[r("div",e({style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"}},{children:[t("span",e({style:{fontSize:"16px",fontWeight:600,color:"#19213D"}},{children:"Rename Scope"})),t("button",e({onClick:p,disabled:S,style:{background:"none",border:"none",cursor:"pointer",color:"#9CA3AF",padding:"4px",lineHeight:0}},{children:t(d,{size:20})}))]})),r("div",e({style:{display:"flex",flexDirection:"column",gap:"6px",marginBottom:"24px"}},{children:[r("label",e({style:{fontSize:"14px",fontWeight:500,color:"#19213D"}},{children:[t("span",e({style:{color:"#E53E3E",marginRight:"3px"}},{children:"*"})),"Scope Name"]})),t("input",{ref:k,type:"text",value:b,onChange:function(e){y(e.target.value),h&&v("")},onKeyDown:function(e){"Enter"===e.key&&z(),"Escape"===e.key&&p()},placeholder:"Enter scope name",style:{padding:"8px 12px",fontSize:"14px",color:"#19213D",borderRadius:"6px",border:"1px solid ".concat(h?"#EF4444":"#E2E8F0"),outline:"none",width:"100%",boxSizing:"border-box"}}),h&&t("p",e({style:{margin:0,fontSize:"12px",color:"#EF4444"}},{children:h}))]})),r("div",e({style:{display:"flex",justifyContent:"flex-end",gap:"10px"}},{children:[t("button",e({onClick:p,disabled:S,style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #E2E8F0",backgroundColor:"#fff",color:"#64748B",fontSize:"14px",fontWeight:500,cursor:S?"not-allowed":"pointer",opacity:S?.6:1}},{children:"Cancel"})),t("button",e({onClick:z,disabled:S,style:{padding:"8px 20px",borderRadius:"6px",border:"none",backgroundColor:"#2563EB",color:"#fff",fontSize:"14px",fontWeight:500,cursor:S?"not-allowed":"pointer",opacity:S?.7:1}},{children:S?"Saving...":"Save"}))]}))]}))}))};export{c as default};
//# sourceMappingURL=RenameScopeModal.js.map
