import{g as T,Q as n,Y as J,$ as x,Z as ee,a0 as te,bv as ae,b2 as ne,i as z,a2 as b,ag as re,a1 as E,aV as le,B as C,a9 as W,aa as A,b9 as H,a4 as ie,r as oe,a6 as O,X,C as U,b3 as se,a8 as ue,ai as ce,bw as $,bx as F,br as de,ac as K,by as me}from"./Czresmtb.js";import{_ as N,u as pe}from"./DxTvTv-W.js";import{A as Q}from"./DjyWdKqc.js";import{_ as fe}from"./V_HtkJcz.js";import{R as he}from"./Bmo8YKXy.js";import{A as ve}from"./ZSyOeJ1o.js";import{u as ye}from"./CFdxo1g5.js";const ge=T({name:"ArrowUp",render(){return n("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20"},n("g",{fill:"none"},n("path",{d:"M3.13 9.163a.5.5 0 1 0 .74.674L9.5 3.67V17.5a.5.5 0 0 0 1 0V3.672l5.63 6.165a.5.5 0 0 0 .738-.674l-6.315-6.916a.746.746 0 0 0-.632-.24a.746.746 0 0 0-.476.24L3.131 9.163z",fill:"currentColor"})))}});function be(){return ae}const Ve=J({name:"DynamicInput",common:te,peers:{Input:ee,Button:x},self:be}),M=ne("n-dynamic-input"),Pe=T({name:"DynamicInputInputPreset",props:{clsPrefix:{type:String,required:!0},value:{type:String,default:""},disabled:Boolean,parentPath:String,path:String,onUpdateValue:{type:Function,required:!0}},setup(){const{mergedThemeRef:a,placeholderRef:m}=z(M);return{mergedTheme:a,placeholder:m}},render(){const{mergedTheme:a,placeholder:m,value:c,clsPrefix:i,onUpdateValue:s,disabled:v}=this;return n("div",{class:`${i}-dynamic-input-preset-input`},n(N,{theme:a.peers.Input,"theme-overrides":a.peerOverrides.Input,value:c,placeholder:m,onUpdateValue:s,disabled:v}))}}),Ie=T({name:"DynamicInputPairPreset",props:{clsPrefix:{type:String,required:!0},value:{type:Object,default:()=>({key:"",value:""})},disabled:Boolean,parentPath:String,path:String,onUpdateValue:{type:Function,required:!0}},setup(a){const{mergedThemeRef:m,keyPlaceholderRef:c,valuePlaceholderRef:i}=z(M);return{mergedTheme:m,keyPlaceholder:c,valuePlaceholder:i,handleKeyInput(s){a.onUpdateValue({key:s,value:a.value.value})},handleValueInput(s){a.onUpdateValue({key:a.value.key,value:s})}}},render(){const{mergedTheme:a,keyPlaceholder:m,valuePlaceholder:c,value:i,clsPrefix:s,disabled:v}=this;return n("div",{class:`${s}-dynamic-input-preset-pair`},n(N,{theme:a.peers.Input,"theme-overrides":a.peerOverrides.Input,value:i.key,class:`${s}-dynamic-input-pair-input`,placeholder:m,onUpdateValue:this.handleKeyInput,disabled:v}),n(N,{theme:a.peers.Input,"theme-overrides":a.peerOverrides.Input,value:i.value,class:`${s}-dynamic-input-pair-input`,placeholder:c,onUpdateValue:this.handleValueInput,disabled:v}))}}),Re=b("dynamic-input",{width:"100%"},[b("dynamic-input-item",`
 margin-bottom: 10px;
 display: flex;
 flex-wrap: nowrap;
 `,[b("dynamic-input-preset-input",{flex:1,alignItems:"center"}),b("dynamic-input-preset-pair",`
 flex: 1;
 display: flex;
 align-items: center;
 `,[b("dynamic-input-pair-input",[E("&:first-child",{"margin-right":"12px"})])]),re("action",`
 align-self: flex-start;
 display: flex;
 justify-content: flex-end;
 flex-shrink: 0;
 flex-grow: 0;
 margin: var(--action-margin);
 `,[le("icon",{cursor:"pointer"})]),E("&:last-child",{marginBottom:0})]),b("form-item",`
 padding-top: 0 !important;
 margin-right: 0 !important;
 `,[b("form-item-blank",{paddingTop:"0 !important"})])]),_=new WeakMap,we=Object.assign(Object.assign({},X.props),{max:Number,min:{type:Number,default:0},value:Array,defaultValue:{type:Array,default:()=>[]},preset:{type:String,default:"input"},keyField:String,itemClass:String,itemStyle:[String,Object],keyPlaceholder:{type:String,default:""},valuePlaceholder:{type:String,default:""},placeholder:{type:String,default:""},disabled:Boolean,showSortButton:Boolean,createButtonProps:Object,onCreate:Function,onRemove:Function,"onUpdate:value":[Function,Array],onUpdateValue:[Function,Array],onClear:Function,onInput:[Function,Array]}),Ue=T({name:"DynamicInput",props:we,setup(a,{slots:m}){const{mergedComponentPropsRef:c,mergedClsPrefixRef:i,mergedRtlRef:s,inlineThemeDisabled:v}=ie(),d=z(me,null),y=oe(a.defaultValue),j=O(a,"value"),p=ye(j,y),V=X("DynamicInput","-dynamic-input",Re,Ve,a,i),u=U(()=>{const{value:e}=p;if(Array.isArray(e)){const{max:t}=a;return t!==void 0&&e.length>=t}return!1}),B=U(()=>{const{value:e}=p;return Array.isArray(e)?e.length<=a.min:!0}),S=U(()=>{var e,t;return(t=(e=c==null?void 0:c.value)===null||e===void 0?void 0:e.DynamicInput)===null||t===void 0?void 0:t.buttonSize});function f(e){const{onInput:t,"onUpdate:value":l,onUpdateValue:r}=a;t&&K(t,e),l&&K(l,e),r&&K(r,e),y.value=e}function D(e,t){if(e==null||typeof e!="object")return t;const l=$(e)?F(e):e;let r=_.get(l);return r===void 0&&_.set(l,r=de()),r}function R(e,t){const{value:l}=p,r=Array.from(l??[]),g=r[e];if(r[e]=t,g&&t&&typeof g=="object"&&typeof t=="object"){const Z=$(g)?F(g):g,G=$(t)?F(t):t,q=_.get(Z);q!==void 0&&_.set(G,q)}f(r)}function w(){h(-1)}function h(e){const{value:t}=p,{onCreate:l}=a,r=Array.from(t??[]);if(l)r.splice(e+1,0,l(e+1)),f(r);else if(m.default)r.splice(e+1,0,null),f(r);else switch(a.preset){case"input":r.splice(e+1,0,""),f(r);break;case"pair":r.splice(e+1,0,{key:"",value:""}),f(r);break}}function P(e){const{value:t}=p;if(!Array.isArray(t))return;const{min:l}=a;if(t.length<=l)return;const{onRemove:r}=a;r&&r(e);const g=Array.from(t);g.splice(e,1),f(g)}function o(e,t,l){if(t<0||l<0||t>=e.length||l>=e.length||t===l)return;const r=e[t];e[t]=e[l],e[l]=r}function k(e,t){const{value:l}=p;if(!Array.isArray(l))return;const r=Array.from(l);e==="up"&&o(r,t,t-1),e==="down"&&o(r,t,t+1),f(r)}se(M,{mergedThemeRef:V,keyPlaceholderRef:O(a,"keyPlaceholder"),valuePlaceholderRef:O(a,"valuePlaceholder"),placeholderRef:O(a,"placeholder")});const Y=ue("DynamicInput",s,i),L=U(()=>{const{self:{actionMargin:e,actionMarginRtl:t}}=V.value;return{"--action-margin":e,"--action-margin-rtl":t}}),I=v?ce("dynamic-input",void 0,L,a):void 0;return{locale:pe("DynamicInput").localeRef,rtlEnabled:Y,buttonSize:S,mergedClsPrefix:i,NFormItem:d,uncontrolledValue:y,mergedValue:p,insertionDisabled:u,removeDisabled:B,handleCreateClick:w,ensureKey:D,handleValueChange:R,remove:P,move:k,createItem:h,mergedTheme:V,cssVars:v?void 0:L,themeClass:I==null?void 0:I.themeClass,onRender:I==null?void 0:I.onRender}},render(){const{$slots:a,itemClass:m,buttonSize:c,mergedClsPrefix:i,mergedValue:s,locale:v,mergedTheme:d,keyField:y,itemStyle:j,preset:p,showSortButton:V,NFormItem:u,ensureKey:B,handleValueChange:S,remove:f,createItem:D,move:R,onRender:w,disabled:h}=this;return w==null||w(),n("div",{class:[`${i}-dynamic-input`,this.rtlEnabled&&`${i}-dynamic-input--rtl`,this.themeClass],style:this.cssVars},!Array.isArray(s)||s.length===0?n(C,Object.assign({block:!0,ghost:!0,dashed:!0,size:c},this.createButtonProps,{disabled:this.insertionDisabled||h,theme:d.peers.Button,themeOverrides:d.peerOverrides.Button,onClick:this.handleCreateClick}),{default:()=>W(a["create-button-default"],()=>[v.create]),icon:()=>W(a["create-button-icon"],()=>[n(A,{clsPrefix:i},{default:()=>n(Q,null)})])}):s.map((P,o)=>n("div",{key:y?P[y]:B(P,o),"data-key":y?P[y]:B(P,o),class:[`${i}-dynamic-input-item`,m],style:j},H(a.default,{value:s[o],index:o},()=>[p==="input"?n(Pe,{disabled:h,clsPrefix:i,value:s[o],parentPath:u?u.path.value:void 0,path:u!=null&&u.path.value?`${u.path.value}[${o}]`:void 0,onUpdateValue:k=>{S(o,k)}}):p==="pair"?n(Ie,{disabled:h,clsPrefix:i,value:s[o],parentPath:u?u.path.value:void 0,path:u!=null&&u.path.value?`${u.path.value}[${o}]`:void 0,onUpdateValue:k=>{S(o,k)}}):null]),H(a.action,{value:s[o],index:o,create:D,remove:f,move:R},()=>[n("div",{class:`${i}-dynamic-input-item__action`},n(fe,{size:c},{default:()=>[n(C,{disabled:this.removeDisabled||h,theme:d.peers.Button,themeOverrides:d.peerOverrides.Button,circle:!0,onClick:()=>{f(o)}},{icon:()=>n(A,{clsPrefix:i},{default:()=>n(he,null)})}),n(C,{disabled:this.insertionDisabled||h,circle:!0,theme:d.peers.Button,themeOverrides:d.peerOverrides.Button,onClick:()=>{D(o)}},{icon:()=>n(A,{clsPrefix:i},{default:()=>n(Q,null)})}),V?n(C,{disabled:o===0||h,circle:!0,theme:d.peers.Button,themeOverrides:d.peerOverrides.Button,onClick:()=>{R("up",o)}},{icon:()=>n(A,{clsPrefix:i},{default:()=>n(ge,null)})}):null,V?n(C,{disabled:o===s.length-1||h,circle:!0,theme:d.peers.Button,themeOverrides:d.peerOverrides.Button,onClick:()=>{R("down",o)}},{icon:()=>n(A,{clsPrefix:i},{default:()=>n(ve,null)})}):null]}))]))))}});export{Ue as _};
