"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("react"),r=require("lodash"),n=require("../../constants.js"),o=require("./sortPads.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=s(e);exports.useFilteredData=function(e){var s=e.data,u=e.searchText,a=e.selectedWellIds,i=e.sortBy,c=e.sortDirection,d=e.filters,f=e.mainItem;return t.useMemo((function(){if(!s||!f)return[];var e=s.filter((function(e){return!u||[e.name,e.fleetName,e.wellsNamesCombined,e.formationsCombined].some((function(e){return e&&r.lowerCase(String(e)).includes(r.lowerCase(u))}))}));if((d.selectedFracFleets.length||d.selectedFormations.length||!!d.tvdMin||d.tvdMax!==n.MAX_TVD)&&(e=e.filter((function(e){var t,r,o=!d.selectedFracFleets.length||d.selectedFracFleets.includes(e.fleetName),s=!d.selectedFormations.length||e.wells.some((function(e){return e.formation&&d.selectedFormations.includes(e.formation)})),l=(t=d.tvdMin,r=d.tvdMax,!t&&r===n.MAX_TVD||(t&&r===n.MAX_TVD?e.wells.some((function(e){return e.totalDepth&&e.totalDepth>=Number(t)})):r===n.MAX_TVD||t?e.wells.some((function(e){return e.totalDepth&&e.totalDepth>=Number(t)&&e.totalDepth<=Number(r)})):e.wells.some((function(e){return e.totalDepth&&e.totalDepth<=Number(r)}))));return o&&s&&l}))),a.length){var t=e.filter((function(e){return e.wells.some((function(e){return a.includes(e.id)}))})),m=e.filter((function(e){return e.wells.every((function(e){return!a.includes(e.id)}))}));i&&(t.sort(o.sortPads(i,c)),m.sort(o.sortPads(i,c))),e=[].concat(l.default(t),l.default(m))}else if(i){e=Array.from(e).sort(o.sortPads(i,c))}return e}),[s,f,d,a,i,u,c])};
//# sourceMappingURL=useFilteredData.js.map
