const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DynamicField-BdQhWNNS.js","assets/DynamicField.vue_vue_type_script_setup_true_lang-DYH52Q2k.js","assets/registry-DyIszw9-.js","assets/vendor/inertia-CR4tWtMT.js","assets/vendor-reka-Edfq1EPl.js","assets/Input.vue_vue_type_script_setup_true_lang-D6nVx0lb.js"])))=>i.map(i=>d[i]);
import{d as M,l as N}from"./registry-DyIszw9-.js";import{usePage as D}from"./vendor/inertia-CR4tWtMT.js";import{d as E,r as U,e as L,aT as a,W as u,X as r,bh as v,U as p,F as k,b2 as y,Q as P,u as T,a3 as K,bK as z,a2 as H,a4 as O}from"./vendor-reka-Edfq1EPl.js";const Q={class:"space-y-3"},S={class:"inline-flex items-center text-sm font-medium text-foreground"},W={key:0,class:"text-sm text-destructive"},X={class:"flex items-center justify-between"},q={class:"text-xs font-medium text-muted-foreground uppercase tracking-wide"},G={class:"flex items-center gap-1"},J=["disabled","onClick"],Y=["disabled","onClick"],Z=["onClick"],F={key:1,class:"rounded-md border border-dashed border-border py-6 text-center text-sm text-muted-foreground"},oe=E({__name:"RepeaterInput",props:{field:{},modelValue:{},error:{}},emits:["update:modelValue"],setup(i,{emit:h}){const b=O(()=>N(()=>import("./DynamicField-BdQhWNNS.js"),__vite__mapDeps([0,1,2,3,4,5]))),d=i,_=h,g=D();let x=0;function f(t={}){return{...t,_key:x++}}function w(t){return Array.isArray(t)?t.map(e=>f(typeof e=="object"&&e!==null?e:{})):[]}const o=U(w(d.modelValue));L(()=>d.modelValue,t=>{if(!Array.isArray(t)){o.value=[];return}o.value=t.map((e,l)=>{var m;const n=typeof e=="object"&&e!==null?e:{},s=(m=o.value[l])==null?void 0:m._key;return s!==void 0?{...n,_key:s}:f(n)})});function c(){_("update:modelValue",o.value.map(({_key:t,...e})=>e))}function C(){const t={};for(const e of d.field.fields??[])t[e.name]=e.default??null;o.value=[...o.value,f(t)],c()}function V(t){o.value=o.value.filter((e,l)=>l!==t),c()}function j(t){if(t===0)return;const e=[...o.value];[e[t-1],e[t]]=[e[t],e[t-1]],o.value=e,c()}function $(t){if(t===o.value.length-1)return;const e=[...o.value];[e[t],e[t+1]]=[e[t+1],e[t]],o.value=e,c()}function A(t,e,l){o.value=o.value.map((n,s)=>s!==t?n:{...n,[e]:l}),c()}function R(t,e){const l=g.props.errors;if(l)return l[`${d.field.name}.${t}.${e}`]}const B=()=>d.field.maxRows!=null&&o.value.length>=d.field.maxRows;return(t,e)=>(a(),u("div",Q,[r("label",S,v(i.field.label),1),i.error?(a(),u("p",W,v(i.error),1)):p("",!0),(a(!0),u(k,null,y(o.value,(l,n)=>(a(),u("div",{key:l._key,class:"rounded-md border border-border bg-muted/30 p-4 space-y-4"},[r("div",X,[r("span",q," #"+v(n+1),1),r("div",G,[r("button",{type:"button",disabled:n===0,class:"inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent disabled:opacity-30 disabled:pointer-events-none transition-colors",onClick:s=>j(n)},[...e[0]||(e[0]=[r("svg",{class:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"2.5"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M5 15l7-7 7 7"})],-1)])],8,J),r("button",{type:"button",disabled:n===o.value.length-1,class:"inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent disabled:opacity-30 disabled:pointer-events-none transition-colors",onClick:s=>$(n)},[...e[1]||(e[1]=[r("svg",{class:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"2.5"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M19 9l-7 7-7-7"})],-1)])],8,Y),r("button",{type:"button",class:"inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",onClick:s=>V(n)},[...e[2]||(e[2]=[r("svg",{class:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"2.5"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,Z)])]),(a(!0),u(k,null,y(i.field.fields??[],s=>(a(),P(T(b),{key:s.name,field:{...s,name:`${i.field.name}_${n}_${s.name}`},"model-value":l[s.name],error:R(n,s.name),"onUpdate:modelValue":m=>A(n,s.name,m)},null,8,["field","model-value","error","onUpdate:modelValue"]))),128))]))),128)),o.value.length===0?(a(),u("p",F,' No items yet. Click "Add" to create the first one. ')):p("",!0),K(M,{type:"button",variant:"outline",size:"sm",disabled:B(),onClick:C},{default:z(()=>[...e[3]||(e[3]=[r("svg",{class:"mr-1.5 h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"2.5"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M12 4v16m8-8H4"})],-1),H(" Add ",-1)])]),_:1},8,["disabled"])]))}});export{oe as _};
