import{_ as S}from"./G7u0egV4.js";import j from"./D42GNhrT.js";import{h as w}from"./CH1bAkoS.js";import{d as R,a4 as U,j as f,M as P,k,b as B,w as O,G as V,g as C,o as _,Y as u,e as x,Z as A,$ as T,f as d,n as E}from"./JQJBiNWj.js";import{b as p,m as N}from"./Dd3ROLQd.js";import{u as q}from"./f6QOa6wf.js";import{u as z}from"./Tk23Dwa0.js";const L={class:"col-span-12 flex flex-wrap justify-end gap-2"},D=R({__name:"FilterForm",props:{schema:{},initialValues:{default:()=>{}},status:{default:()=>{}},partial:{type:Boolean,default:!0},classForm:{default:()=>{}},paginatedUrl:{type:Boolean,default:!1},defaultFilters:{default:()=>{}}},emits:["change"],setup(s,{emit:h}){const i=U(),g=h,l=f(s.paginatedUrl?void 0:{...s.initialValues,...p(s.schema)}),o=P("formRef");q(o),z(o,l);const F=f(w(s.partial?N(s.schema):s.schema));function y(t){if(!t.valid)return;const a=v(t.values);b(a),g("change",a)}function b(t){const a=c(i.query),e=c(t);a.toString()===e.toString()&&e.append("_refresh",new Date().getTime().toString()),E(window.location.pathname+"?"+e.toString(),{replace:!0})}function c(t){const a=new URLSearchParams;return Object.entries(t).forEach(([e,r])=>{r!=null&&(Array.isArray(r)?r.forEach(n=>{n!=null&&a.append(e,String(n))}):a.append(e,String(r)))}),a}function v(t){return Object.fromEntries(Object.entries(t).filter(([a,e])=>e!=null&&e!==""&&!(Array.isArray(e)&&e.length===0)))}function m(t){var a,e;for(const r of Object.keys(t)){const n=t[r];n&&typeof n=="object"&&n.hasOwnProperty("value")&&(t[r].value=(a=s.defaultFilters)!=null&&a[r]?(e=s.defaultFilters)==null?void 0:e[r]:null)}}return k(()=>i.query,()=>{s.paginatedUrl&&(l.value=p(s.schema))},{immediate:!0}),(t,a)=>{const e=S,r=j;return _(),B(r,{ref_key:"formRef",ref:o,resolver:C(F),class:V(["flex flex-col gap-5 mb-5",t.classForm]),onSubmit:y},{default:O(n=>[u(t.$slots,"default",A(T(n))),x("div",L,[u(t.$slots,"actions",{clearFilters:()=>m(n)},()=>[d(e,{mode:"clean",onClick:G=>m(n)},null,8,["onClick"]),d(e,{mode:"search",type:"submit",loading:t.status==="pending"},null,8,["loading"])])])]),_:3},8,["resolver","class"])}}}),Q=Object.assign(D,{__name:"UiFilterForm"});export{Q as _};
