"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("@aplus-frontend/antdv/es/theme/internal"),c=require("lodash-unified"),s=require("vue");require("../../config-provider/index.js");const A=require("../../utils/index.js"),M=require("../components/setting/utils.js"),J=require("../context.js"),P=require("../utils.js"),U=require("../../config-provider/hooks/use-locale.js"),W=require("../../config-provider/hooks/use-namespace.js");function G(r,t,u,n){return n?n.fixed:t?t.fixed:u&&"fixed"in u?u.fixed:c.isBoolean(r.fixed)?r.fixed?"left":void 0:r.fixed}const y=Number.MAX_SAFE_INTEGER,k=A.randomStr();function R(r,t){const u=c.isNumber(r.order)?r.order:y;let n=c.isNumber(t.order)?t.order:y;return r.fixed==="right"&&t.fixed!=="right"&&(n=u-1),t.fixed==="left"&&r.fixed!=="left"&&(n=u-1),u-n}function X(r,t){t&&r.removeItem(t)}function q(r,t){if(!t)return[];const u=r.getItem(t);if(!u)return[];const n=JSON.parse(u);return Array.isArray(n)?n:(X(r,t),[])}function N(r,t){if(c.isObject(r)&&c.isObject(t))return c.mergeWith({},r,t,N)}const $=(r,t,u)=>{const{columnsBackup:n,size:m,awaitedColumns:T}=J.useInjectApTable(),{t:w}=U.useLocale(),{be:I}=W.useNamespace("ap-table"),[D,z]=F.useToken(),g=s.ref(),l=s.ref([]);let p;p=s.watch(()=>n?.value,(e,i)=>{e?.length&&!i?.length&&(l.value=h(q(localStorage,s.unref(t)),e),p?.())},{immediate:!0}),s.watch([n,m],([e,i])=>{e&&(g.value={label:"basic_template",columnState:f(e),key:k,size:i})},{immediate:!0,deep:!0}),s.watch(()=>t.value,async e=>{const i=T?await T?.value:n?.value,a=h(q(localStorage,e),i);l.value=a,g.value={label:"basic_template",columnState:f(i||[]),key:k,size:m?.value},u(a??[])});function h(e,i){return e.length?e.map(a=>({...a,columnState:f(i||[],a.columnState,!1)})):[{label:w("ap.apTable.setting.defaultTemplate"),key:r.getActiveKey?.("DEFAULT_TEMPLATE")??A.randomStr(),size:m?.value,columnState:f(i||[])}]}function f(e,i={},a=!0){const v=c.mergeWith({},a?r.defaultValue||{}:{},i,N);function x(L,j,B){return L.map((o,C)=>{const b=j?.[o.key]||{},d={key:o.key,label:c.isString(o.title)?P.getTableTitle(o,I("table-header","title"),void 0,z.value.colorTextTertiary):o.title,show:!0,fixed:G(o,i[o.key],a?r.defaultValue?.[o.key]:void 0,B),disabled:!1,...c.omit(b,["children","fixed"])};return d.children=o.children?.length?x(o.children,b.children,d):void 0,d.order=d.order??C,d}).sort(R)}return x(e||[],v)}function S(e){if(s.unref(t)){const i=e.map(a=>({...a,columnState:M.getColumnStateString(a.columnState)}));localStorage.setItem(s.unref(t),JSON.stringify(i))}}function E(e){l.value.push(e)}function O(e){const i=l.value.findIndex(a=>a.key===e);l.value.splice(i,1)}function _(e,i){const a=l.value.findIndex(v=>v.key===e);return l.value[a]={...l.value[a],...i},l.value[a]}return s.watch(()=>l.value,e=>{e.length&&S(e)},{deep:!0,immediate:!0}),{basicTemplate:g,customizeTemplateList:l,syncTemplateListToStorage:S,addTemplate:E,deleteTemplate:O,updateTemplate:_}};exports.useTableTemplateStorage=$;
