import{d as j,am as n,b8 as f,bQ as J,bs as v,bt as $,by as U,b9 as ee,cB as se,bS as te,e3 as ue,cI as re,b2 as ce,b3 as de,b4 as pe,b5 as me,e4 as fe,bH as he,bI as G,D as x,e5 as ge,r as be,bd as K,be as ve,bc as ne,a as N,bf as ye,ba as Pe,B as D,cu as X,dr as Y,e6 as L,e7 as M,dq as Ve,bg as O,bh as Z,e8 as $e,bj as q}from"./index-BlU6DPnP.js";import{A as Ie}from"./Grid-Cpsk88_v.js";const Re=j({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"})))}}),o="0!important",ae="-1px!important";function B(e){return $(`${e}-type`,[v("& +",[f("button",{},[$(`${e}-type`,[U("border",{borderLeftWidth:o}),U("state-border",{left:ae})])])])])}function C(e){return $(`${e}-type`,[v("& +",[f("button",[$(`${e}-type`,[U("border",{borderTopWidth:o}),U("state-border",{top:ae})])])])])}const we=f("button-group",`
 flex-wrap: nowrap;
 display: inline-flex;
 position: relative;
`,[J("vertical",{flexDirection:"row"},[J("rtl",[f("button",[v("&:first-child:not(:last-child)",`
 margin-right: ${o};
 border-top-right-radius: ${o};
 border-bottom-right-radius: ${o};
 `),v("&:last-child:not(:first-child)",`
 margin-left: ${o};
 border-top-left-radius: ${o};
 border-bottom-left-radius: ${o};
 `),v("&:not(:first-child):not(:last-child)",`
 margin-left: ${o};
 margin-right: ${o};
 border-radius: ${o};
 `),B("default"),$("ghost",[B("primary"),B("info"),B("success"),B("warning"),B("error")])])])]),$("vertical",{flexDirection:"column"},[f("button",[v("&:first-child:not(:last-child)",`
 margin-bottom: ${o};
 margin-left: ${o};
 margin-right: ${o};
 border-bottom-left-radius: ${o};
 border-bottom-right-radius: ${o};
 `),v("&:last-child:not(:first-child)",`
 margin-top: ${o};
 margin-left: ${o};
 margin-right: ${o};
 border-top-left-radius: ${o};
 border-top-right-radius: ${o};
 `),v("&:not(:first-child):not(:last-child)",`
 margin: ${o};
 border-radius: ${o};
 `),C("default"),$("ghost",[C("primary"),C("info"),C("success"),C("warning"),C("error")])])])]),Be={size:{type:String,default:void 0},vertical:Boolean},Ce=j({name:"ButtonGroup",props:Be,setup(e){const{mergedClsPrefixRef:c,mergedRtlRef:d}=ee(e);return se("-button-group",we,c),te(ue,e),{rtlEnabled:re("ButtonGroup",d,c),mergedClsPrefix:c}},render(){const{mergedClsPrefix:e}=this;return n("div",{class:[`${e}-button-group`,this.rtlEnabled&&`${e}-button-group--rtl`,this.vertical&&`${e}-button-group--vertical`],role:"group"},this.$slots)}});function Se(){return fe}const ke=ce({name:"DynamicInput",common:de,peers:{Input:pe,Button:me},self:Se}),W=he("n-dynamic-input"),Ae=j({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:e,placeholderRef:c}=G(W);return{mergedTheme:e,placeholder:c}},render(){const{mergedTheme:e,placeholder:c,value:d,clsPrefix:l,onUpdateValue:u,disabled:y}=this;return n("div",{class:`${l}-dynamic-input-preset-input`},n(x,{theme:e.peers.Input,"theme-overrides":e.peerOverrides.Input,value:d,placeholder:c,onUpdateValue:u,disabled:y}))}}),De=j({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(e){const{mergedThemeRef:c,keyPlaceholderRef:d,valuePlaceholderRef:l}=G(W);return{mergedTheme:c,keyPlaceholder:d,valuePlaceholder:l,handleKeyInput(u){e.onUpdateValue({key:u,value:e.value.value})},handleValueInput(u){e.onUpdateValue({key:e.value.key,value:u})}}},render(){const{mergedTheme:e,keyPlaceholder:c,valuePlaceholder:d,value:l,clsPrefix:u,disabled:y}=this;return n("div",{class:`${u}-dynamic-input-preset-pair`},n(x,{theme:e.peers.Input,"theme-overrides":e.peerOverrides.Input,value:l.key,class:`${u}-dynamic-input-pair-input`,placeholder:c,onUpdateValue:this.handleKeyInput,disabled:y}),n(x,{theme:e.peers.Input,"theme-overrides":e.peerOverrides.Input,value:l.value,class:`${u}-dynamic-input-pair-input`,placeholder:d,onUpdateValue:this.handleValueInput,disabled:y}))}}),Oe=f("dynamic-input",{width:"100%"},[f("dynamic-input-item",`
 margin-bottom: 10px;
 display: flex;
 flex-wrap: nowrap;
 `,[f("dynamic-input-preset-input",{flex:1,alignItems:"center"}),f("dynamic-input-preset-pair",`
 flex: 1;
 display: flex;
 align-items: center;
 `,[f("dynamic-input-pair-input",[v("&:first-child",{"margin-right":"12px"})])]),U("action",`
 align-self: flex-start;
 display: flex;
 justify-content: flex-end;
 flex-shrink: 0;
 flex-grow: 0;
 margin: var(--action-margin);
 `,[$("icon",{cursor:"pointer"})]),v("&:last-child",{marginBottom:0})]),f("form-item",`
 padding-top: 0 !important;
 margin-right: 0 !important;
 `,[f("form-item-blank",{paddingTop:"0 !important"})])]),z=new WeakMap,Ue=Object.assign(Object.assign({},ne.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]}),Fe=j({name:"DynamicInput",props:Ue,setup(e,{slots:c}){const{mergedComponentPropsRef:d,mergedClsPrefixRef:l,mergedRtlRef:u,inlineThemeDisabled:y}=ee(),m=G(ge,null),P=be(e.defaultValue),E=K(e,"value"),h=ve(E,P),I=ne("DynamicInput","-dynamic-input",Oe,ke,e,l),p=N(()=>{const{value:t}=h;if(Array.isArray(t)){const{max:r}=e;return r!==void 0&&t.length>=r}return!1}),T=N(()=>{const{value:t}=h;return Array.isArray(t)?t.length<=e.min:!0}),F=N(()=>{var t,r;return(r=(t=d==null?void 0:d.value)===null||t===void 0?void 0:t.DynamicInput)===null||r===void 0?void 0:r.buttonSize});function g(t){const{onInput:r,"onUpdate:value":i,onUpdateValue:a}=e;r&&q(r,t),i&&q(i,t),a&&q(a,t),P.value=t}function _(t,r){if(t==null||typeof t!="object")return r;const i=L(t)?M(t):t;let a=z.get(i);return a===void 0&&z.set(i,a=Ve()),a}function S(t,r){const{value:i}=h,a=Array.from(i??[]),V=a[t];if(a[t]=r,V&&r&&typeof V=="object"&&typeof r=="object"){const ie=L(V)?M(V):V,oe=L(r)?M(r):r,Q=z.get(ie);Q!==void 0&&z.set(oe,Q)}g(a)}function k(){b(-1)}function b(t){const{value:r}=h,{onCreate:i}=e,a=Array.from(r??[]);if(i)a.splice(t+1,0,i(t+1)),g(a);else if(c.default)a.splice(t+1,0,null),g(a);else switch(e.preset){case"input":a.splice(t+1,0,""),g(a);break;case"pair":a.splice(t+1,0,{key:"",value:""}),g(a);break}}function R(t){const{value:r}=h;if(!Array.isArray(r))return;const{min:i}=e;if(r.length<=i)return;const{onRemove:a}=e;a&&a(t);const V=Array.from(r);V.splice(t,1),g(V)}function s(t,r,i){if(r<0||i<0||r>=t.length||i>=t.length||r===i)return;const a=t[r];t[r]=t[i],t[i]=a}function A(t,r){const{value:i}=h;if(!Array.isArray(i))return;const a=Array.from(i);t==="up"&&s(a,r,r-1),t==="down"&&s(a,r,r+1),g(a)}te(W,{mergedThemeRef:I,keyPlaceholderRef:K(e,"keyPlaceholder"),valuePlaceholderRef:K(e,"valuePlaceholder"),placeholderRef:K(e,"placeholder")});const le=re("DynamicInput",u,l),H=N(()=>{const{self:{actionMargin:t,actionMarginRtl:r}}=I.value;return{"--action-margin":t,"--action-margin-rtl":r}}),w=y?ye("dynamic-input",void 0,H,e):void 0;return{locale:Pe("DynamicInput").localeRef,rtlEnabled:le,buttonSize:F,mergedClsPrefix:l,NFormItem:m,uncontrolledValue:P,mergedValue:h,insertionDisabled:p,removeDisabled:T,handleCreateClick:k,ensureKey:_,handleValueChange:S,remove:R,move:A,createItem:b,mergedTheme:I,cssVars:y?void 0:H,themeClass:w==null?void 0:w.themeClass,onRender:w==null?void 0:w.onRender}},render(){const{$slots:e,itemClass:c,buttonSize:d,mergedClsPrefix:l,mergedValue:u,locale:y,mergedTheme:m,keyField:P,itemStyle:E,preset:h,showSortButton:I,NFormItem:p,ensureKey:T,handleValueChange:F,remove:g,createItem:_,move:S,onRender:k,disabled:b}=this;return k==null||k(),n("div",{class:[`${l}-dynamic-input`,this.rtlEnabled&&`${l}-dynamic-input--rtl`,this.themeClass],style:this.cssVars},!Array.isArray(u)||u.length===0?n(D,Object.assign({block:!0,ghost:!0,dashed:!0,size:d},this.createButtonProps,{disabled:this.insertionDisabled||b,theme:m.peers.Button,themeOverrides:m.peerOverrides.Button,onClick:this.handleCreateClick}),{default:()=>X(e["create-button-default"],()=>[y.create]),icon:()=>X(e["create-button-icon"],()=>[n(O,{clsPrefix:l},{default:()=>n(Z,null)})])}):u.map((R,s)=>n("div",{key:P?R[P]:T(R,s),"data-key":P?R[P]:T(R,s),class:[`${l}-dynamic-input-item`,c],style:E},Y(e.default,{value:u[s],index:s},()=>[h==="input"?n(Ae,{disabled:b,clsPrefix:l,value:u[s],parentPath:p?p.path.value:void 0,path:p!=null&&p.path.value?`${p.path.value}[${s}]`:void 0,onUpdateValue:A=>{F(s,A)}}):h==="pair"?n(De,{disabled:b,clsPrefix:l,value:u[s],parentPath:p?p.path.value:void 0,path:p!=null&&p.path.value?`${p.path.value}[${s}]`:void 0,onUpdateValue:A=>{F(s,A)}}):null]),Y(e.action,{value:u[s],index:s,create:_,remove:g,move:S},()=>[n("div",{class:`${l}-dynamic-input-item__action`},n(Ce,{size:d},{default:()=>[n(D,{disabled:this.removeDisabled||b,theme:m.peers.Button,themeOverrides:m.peerOverrides.Button,circle:!0,onClick:()=>{g(s)}},{icon:()=>n(O,{clsPrefix:l},{default:()=>n($e,null)})}),n(D,{disabled:this.insertionDisabled||b,circle:!0,theme:m.peers.Button,themeOverrides:m.peerOverrides.Button,onClick:()=>{_(s)}},{icon:()=>n(O,{clsPrefix:l},{default:()=>n(Z,null)})}),I?n(D,{disabled:s===0||b,circle:!0,theme:m.peers.Button,themeOverrides:m.peerOverrides.Button,onClick:()=>{S("up",s)}},{icon:()=>n(O,{clsPrefix:l},{default:()=>n(Re,null)})}):null,I?n(D,{disabled:s===u.length-1||b,circle:!0,theme:m.peers.Button,themeOverrides:m.peerOverrides.Button,onClick:()=>{S("down",s)}},{icon:()=>n(O,{clsPrefix:l},{default:()=>n(Ie,null)})}):null]}))]))))}});export{Fe as _};
