import{cy as L,cz as P,cA as U,cB as K,ci as N,q as w,d as W,v as r,av as $,z as G,B as H,bL as q,cC as E,F as J,bV as M,G as Q,r as v,J as j,H as X,I as Y,a as V,L as Z,aG as ee,R as A,cD as te}from"./index-DGnN4tUo.js";import{s as ne,_ as se}from"./Space-CL0I_Xfq.js";import{s as ae}from"./DataTable-srFNopw0.js";const ie=L({name:"DynamicTags",common:N,peers:{Input:K,Button:U,Tag:P,Space:ne},self(){return{inputWidth:"64px"}}}),le=w("dynamic-tags",[w("input",{minWidth:"var(--n-input-width)"})]),ue=Object.assign(Object.assign(Object.assign({},j.props),te),{size:{type:String,default:"medium"},closable:{type:Boolean,default:!0},defaultValue:{type:Array,default:()=>[]},value:Array,inputClass:String,inputStyle:[String,Object],inputProps:Object,max:Number,tagClass:String,tagStyle:[String,Object],renderTag:Function,onCreate:{type:Function,default:t=>t},"onUpdate:value":[Function,Array],onUpdateValue:[Function,Array],onChange:[Function,Array]}),de=W({name:"DynamicTags",props:ue,slots:Object,setup(t){const{mergedClsPrefixRef:y,inlineThemeDisabled:c}=J(t),{localeRef:d}=M("DynamicTags"),m=Q(t),{mergedDisabledRef:a}=m,g=v(""),p=v(!1),h=v(!0),C=v(null),b=j("DynamicTags","-dynamic-tags",le,ie,t,y),T=v(t.defaultValue),F=X(t,"value"),l=Y(F,T),O=V(()=>d.value.add),_=V(()=>ae(t.size)),z=V(()=>a.value||!!t.max&&l.value.length>=t.max);function R(e){const{onChange:n,"onUpdate:value":s,onUpdateValue:o}=t,{nTriggerFormInput:k,nTriggerFormChange:x}=m;n&&A(n,e),o&&A(o,e),s&&A(s,e),T.value=e,k(),x()}function I(e){const n=l.value.slice(0);n.splice(e,1),R(n)}function D(e){switch(e.key){case"Enter":u()}}function u(e){const n=e??g.value;if(n){const s=l.value.slice(0);s.push(t.onCreate(n)),R(s)}p.value=!1,h.value=!0,g.value=""}function B(){u()}function S(){p.value=!0,ee(()=>{var e;(e=C.value)===null||e===void 0||e.focus(),h.value=!1})}const f=V(()=>{const{self:{inputWidth:e}}=b.value;return{"--n-input-width":e}}),i=c?Z("dynamic-tags",void 0,f,t):void 0;return{mergedClsPrefix:y,inputInstRef:C,localizedAdd:O,inputSize:_,inputValue:g,showInput:p,inputForceFocused:h,mergedValue:l,mergedDisabled:a,triggerDisabled:z,handleInputKeyDown:D,handleAddClick:S,handleInputBlur:B,handleCloseClick:I,handleInputConfirm:u,mergedTheme:b,cssVars:c?void 0:f,themeClass:i==null?void 0:i.themeClass,onRender:i==null?void 0:i.onRender}},render(){const{mergedTheme:t,cssVars:y,mergedClsPrefix:c,onRender:d,renderTag:m}=this;return d==null||d(),r(se,{class:[`${c}-dynamic-tags`,this.themeClass],size:"small",style:y,theme:t.peers.Space,themeOverrides:t.peerOverrides.Space,itemStyle:"display: flex;"},{default:()=>{const{mergedTheme:a,tagClass:g,tagStyle:p,type:h,round:C,size:b,color:T,closable:F,mergedDisabled:l,showInput:O,inputValue:_,inputClass:z,inputStyle:R,inputSize:I,inputForceFocused:D,triggerDisabled:u,handleInputKeyDown:B,handleInputBlur:S,handleAddClick:f,handleCloseClick:i,handleInputConfirm:e,$slots:n}=this;return this.mergedValue.map((s,o)=>m?m(s,o):r($,{key:o,theme:a.peers.Tag,themeOverrides:a.peerOverrides.Tag,class:g,style:p,type:h,round:C,size:b,color:T,closable:F,disabled:l,onClose:()=>{i(o)}},{default:()=>typeof s=="string"?s:s.label})).concat(O?n.input?n.input({submit:e,deactivate:S}):r(G,Object.assign({placeholder:"",size:I,style:R,class:z,autosize:!0},this.inputProps,{ref:"inputInstRef",value:_,onUpdateValue:s=>{this.inputValue=s},theme:a.peers.Input,themeOverrides:a.peerOverrides.Input,onKeydown:B,onBlur:S,internalForceFocus:D})):n.trigger?n.trigger({activate:f,disabled:u}):r(H,{dashed:!0,disabled:u,theme:a.peers.Button,themeOverrides:a.peerOverrides.Button,size:I,onClick:f},{icon:()=>r(q,{clsPrefix:c},{default:()=>r(E,null)})}))}})}});export{de as _};
