import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import e from"@babel/runtime/helpers/toConsumableArray";import{useState as n,useEffect as o}from"react";import{isEmpty as i}from"lodash";import{SortDirection as c}from"react-virtualized";import{ColumnType as u}from"../constants.js";function f(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?f(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}var p=function(r,t,n){var o=e(r),i=t===u.lastActive;return o.sort((function(r,e){return r[t]||0===r[t]&&!i?e[t]||0===e[t]&&!i?n===c.ASC?r[t]>=e[t]?1:-1:e[t]>=r[t]?1:-1:-1:1})),o};function l(r,e,f,l,s){var m=n(u.distance),b=t(m,2),d=b[0],O=b[1],y=n(c.ASC),j=t(y,2),v=j[0],h=j[1],P=n(null),g=t(P,2),w=g[0],A=g[1];return o((function(){if(e&&!s){var t=f.map((function(r){return r.id})),n=f.filter((function(t){return t.id!==(null==r?void 0:r.id)})),o=p(n,d,v),c=e.filter((function(r){return!t.includes(r.id)})),u=p(c,d,v),m=(i(r)?[]:[r]).concat(o).concat(u).map((function(r){return f.find((function(t){return t.id===r.id}))?a(a({},r),{},{checked:!0}):a(a({},r),{},{checked:!1})}));A(m),l(!1)}}),[e,d,v,r,f,s]),[d,O,v,h,w]}export{l as useSortedWells};
