"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@aplus-frontend/utils"),O=require("lodash-unified"),t=require("vue"),l=require("../utils/query.js"),A=f=>{const{saveDataSource:Q,sendToUrl:y,tableKey:r,extraUrlParams:h,searchFormModel:U,urlQueryAdapter:s}=f;let u,c=!1;const n=t.ref({}),i=t.ref(!1),v=e=>{if(!e||Array.isArray(e)||typeof e!="object")return{};const a={...e};return delete a.__tk,delete a[r.value],a},o=t.ref(),d=()=>{if(o.value)return o.value;const e=s.value?.resolveOwnerKey?.({tableKey:r.value});return e&&(o.value=e),o.value},g=()=>{const e=l.getUrlQuery();return s.value?.getQuery?.({tableKey:r.value,ownerKey:d(),defaultQuery:e})??e},m=e=>{const a=s.value;if(!a?.setQuery){l.setUrlQuery(e);return}const p=l.getUrlQuery();a.setQuery(e,{tableKey:r.value,ownerKey:d(),defaultQuery:p,defaultSetQuery:l.setUrlQuery})},b=()=>{try{const e=encodeURIComponent(JSON.stringify(v({...Q?.getSearchFormValues?.(),...h?.value?.()??{}})));e!==u&&(u=e,c=!0)}catch{u=""}c&&(m({[r.value]:u}),c=!1)},K=O.debounce(b,500),S=()=>{try{const e=g()[r.value]??"";n.value=e?v(JSON.parse(decodeURIComponent(e))):{},i.value=!0}catch{n.value={}}};return t.watch(U,()=>{y?.value&&K()},{deep:!0,immediate:!0}),t.onMounted(()=>{y?.value&&S()}),t.onActivated(()=>{d()}),{mountedData:t.computed(()=>n.value),isValidMountedData:t.computed(()=>w.isObjectWithContent(n.value)),isFirstSendToUrl:i}};exports.useSendToUrl=A;
