"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("vue"),U=require("@ant-design/icons-vue/CaretDownOutlined"),z=require("@ant-design/icons-vue/CaretUpOutlined"),B=require("../../_util/KeyCode.js"),k=require("../../_util/classNames.js"),G=require("../../_util/hooks/useState.js"),J=require("../../tooltip/index.js"),v=require("../util.js"),C="ascend",T="descend";function D(e){return typeof e.sorter=="object"&&typeof e.sorter.multiple=="number"?e.sorter.multiple:!1}function V(e){return typeof e=="function"?e:e&&typeof e=="object"&&e.compare?e.compare:!1}function Q(e,o){return o?e[e.indexOf(o)+1]:e[0]}function $(e,o,u){let a=[];function p(t,s){a.push({column:t,key:v.getColumnKey(t,s),multiplePriority:D(t),sortOrder:t.sortOrder})}return(e||[]).forEach((t,s)=>{const i=v.getColumnPos(s,u);t.children?("sortOrder"in t&&p(t,i),a=[...a,...$(t.children,o,i)]):t.sorter&&("sortOrder"in t?p(t,i):o&&t.defaultSortOrder&&a.push({column:t,key:v.getColumnKey(t,i),multiplePriority:D(t),sortOrder:t.defaultSortOrder}))}),a}function M(e,o,u,a,p,t,s,i){return(o||[]).map((n,P)=>{const h=v.getColumnPos(P,i);let l=n;if(l.sorter){const g=l.sortDirections||p,r=l.showSorterTooltip===void 0?s:l.showSorterTooltip,c=v.getColumnKey(l,h),m=u.find(({key:N})=>N===c),y=m?m.sortOrder:null,O=Q(g,y),d=g.includes(C)&&S.createVNode(z,{class:k.default(`${e}-column-sorter-up`,{active:y===C}),role:"presentation"},null),q=g.includes(T)&&S.createVNode(U,{role:"presentation",class:k.default(`${e}-column-sorter-down`,{active:y===T})},null),{cancelSort:H,triggerAsc:I,triggerDesc:R}=t||{};let K=H;O===T?K=R:O===C&&(K=I);const A=typeof r=="object"?r:{title:K};l={...l,className:k.default(l.className,{[`${e}-column-sort`]:y}),title:N=>{const f=S.createVNode("div",{class:`${e}-column-sorters`},[S.createVNode("span",{class:`${e}-column-title`},[v.renderColumnTitle(n.title,N)]),S.createVNode("span",{class:k.default(`${e}-column-sorter`,{[`${e}-column-sorter-full`]:!!(d&&q)})},[S.createVNode("span",{class:`${e}-column-sorter-inner`},[d,q])])]);return r?S.createVNode(J.default,A,{default:()=>[f]}):f},customHeaderCell:N=>{const f=n.customHeaderCell&&n.customHeaderCell(N)||{},E=f.onClick,_=f.onKeydown;return f.onClick=w=>{a({column:n,key:c,sortOrder:O,multiplePriority:D(n)}),E&&E(w)},f.onKeydown=w=>{w.keyCode===B.default.ENTER&&(a({column:n,key:c,sortOrder:O,multiplePriority:D(n)}),_?.(w))},y&&(f["aria-sort"]=y==="ascend"?"ascending":"descending"),f.class=k.default(f.class,`${e}-column-has-sorters`),f.tabindex=0,f}}}return"children"in l&&(l={...l,children:M(e,l.children,u,a,p,t,s,h)}),l})}function b(e){const{column:o,sortOrder:u}=e;return{column:o,order:u,field:o.dataIndex,columnKey:o.key}}function j(e){const o=e.filter(({sortOrder:u})=>u).map(b);return o.length===0&&e.length?{...b(e[e.length-1]),column:void 0}:o.length<=1?o[0]||{}:o}function F(e,o,u){const a=o.slice().sort((s,i)=>i.multiplePriority-s.multiplePriority),p=e.slice(),t=a.filter(({column:{sorter:s},sortOrder:i})=>V(s)&&i);return t.length?p.sort((s,i)=>{for(let n=0;n<t.length;n+=1){const P=t[n],{column:{sorter:h},sortOrder:l}=P,g=V(h);if(g&&l){const r=g(s,i,l);if(r!==0)return l===C?r:-r}}return 0}).map(s=>{const i=s[u];return i?{...s,[u]:F(i,o,u)}:s}):p}function W({prefixCls:e,mergedColumns:o,onSorterChange:u,sortDirections:a,tableLocale:p,showSorterTooltip:t}){const[s,i]=G.default($(o.value,!0)),n=S.computed(()=>{let r=!0;const c=$(o.value,!1);if(!c.length)return s.value;const m=[];function y(d){r?m.push(d):m.push({...d,sortOrder:null})}let O=null;return c.forEach(d=>{O===null?(y(d),d.sortOrder&&(d.multiplePriority===!1?r=!1:O=!0)):(O&&d.multiplePriority!==!1||(r=!1),y(d))}),m}),P=S.computed(()=>{const r=n.value.map(({column:c,sortOrder:m})=>({column:c,order:m}));return{sortColumns:r,sortColumn:r[0]&&r[0].column,sortOrder:r[0]&&r[0].order}});function h(r){let c;r.multiplePriority===!1||!n.value.length||n.value[0].multiplePriority===!1?c=[r]:c=[...n.value.filter(({key:m})=>m!==r.key),r],i(c),u(j(c),c)}const l=r=>M(e.value,r,n.value,h,a.value,p.value,t.value),g=S.computed(()=>j(n.value));return[l,n,P,g]}exports.default=W;exports.getSortData=F;
