import{X as e,T as t,E as n,aR as r,aS as l,aT as o,q as a,aU as i,S as u,bW as g,bo as s,df as c,aW as d,a8 as p,aX as h,bp as v,x as f,an as m}from"./index-C-dDkA_D.js";const b=b=>{var S;const[w,y]=e(null!=(S=b.defaultValue)?S:""),[k,x]=e(""),F=a();let C;const T=()=>{const e=w().lastIndexOf(".");setTimeout(()=>{e>0&&b.isRenamingFile?C.setSelectionRange(0,e):C.select()},10)};t(()=>{C&&(C.focus(),T()),m(()=>{C&&C.setSelectionRange(0,0)})}),t(()=>{b.opened||y("")});const R=()=>{var e;if(b.validateFilename){const e=v(w());if(!e.valid)return void f.warning(F(`global.${e.error}`))}else if(!w()||0===w().trim().length)return void f.warning(F("global.empty_input"));null==(e=b.onSubmit)||e.call(b,w())},$=e=>{if(y(e),b.validateFilename){const t=v(e);x(t.valid?"":t.error||"")}else x("")};return n(h,{blockScrollOnMount:!1,get opened(){return b.opened},get onClose(){return b.onClose},initialFocus:"#modal-input",get children(){return[n(r,{}),n(l,{onDrop:e=>{var t;return null==(t=b.onDrop)?void 0:t.call(b,e,y)},get children(){return[n(o,{get children(){return F(b.title)}}),n(i,{get children(){return[n(u,{get when(){return b.topSlot},get children(){return b.topSlot}}),n(u,{get when(){return"text"===b.type},get fallback(){return n(s,{id:"modal-input",get type(){return b.type},get value(){return w()},ref:e=>C=e,get invalid(){return!!k()},onInput:e=>{$(e.currentTarget.value)},onFocus:T,onKeyDown:e=>{"Enter"===e.key&&R()}})},get children(){return n(g,{id:"modal-input",get value(){return w()},ref:e=>C=e,get invalid(){return!!k()},onInput:e=>{$(e.currentTarget.value)},onFocus:T})}}),n(u,{get when(){return k()},get children(){return n(c,{color:"$danger9",get children(){return F(`global.${k()}`)}})}}),n(u,{get when(){return b.tips},get children(){return n(c,{get children(){return b.tips}})}}),n(u,{get when(){return b.bottomSlot},get children(){return b.bottomSlot}})]}}),n(d,{display:"flex",gap:"$2",get children(){return[n(u,{get when(){return b.footerSlot},get children(){return b.footerSlot}}),n(p,{get onClick(){return b.onClose},colorScheme:"neutral",get children(){return F("global.cancel")}}),n(p,{get loading(){return b.loading},onClick:()=>R(),get children(){return F("global.ok")}})]}})]}})]}})};export{b as M};
