var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

import { DynamincType, FastTypeKeys } from "./constant";
import dayjs from 'dayjs';
import { FilterTypeKeys } from "./constant";
export var getDurationOfFastType = function getDurationOfFastType(fast, val, type, unit, fastMap) {
  if (!fast) return [null, null];

  if (fast === FastTypeKeys.customer) {
    if (type === DynamincType.after) {
      return [dayjs(), dayjs().add(val || 0, unit)];
    }

    return [dayjs().subtract(val || 0, unit), dayjs()];
  }

  return fastMap[fast];
};
/** 翻译传进来的结构 */

export var translateFilterData = function translateFilterData(data) {
  var $and = data.$and;
  var result = [];
  $and.forEach(function (andArr) {
    var notTrans = andArr.$or.map(function (orObj) {
      var obj;

      if (orObj.$not) {
        var _a = orObj.$not,
            type = _a.type,
            value = _a.value;

        if (type === FilterTypeKeys.empty) {
          obj = {
            value: value,
            type: FilterTypeKeys.unempty
          };
        }

        if (type === FilterTypeKeys.contain) {
          obj = {
            value: value,
            type: FilterTypeKeys.nocontain
          };
        }
      } else {
        obj = orObj;
      }

      return obj;
    });
    result.push(notTrans);
  });
  return result;
};
/** 规范传出结构 */

export var formatFilterData = function formatFilterData(data) {
  var andResult = data.map(function (orArr) {
    var orObj = {
      $or: {}
    };
    orObj.$or = orArr.map(function (obj) {
      var box = obj;

      if (obj.type === FilterTypeKeys.unempty) {
        box = {
          $not: __assign(__assign({}, obj), {
            type: FilterTypeKeys.empty
          })
        };
      }

      if (obj.type === FilterTypeKeys.nocontain) {
        box = {
          $not: __assign(__assign({}, obj), {
            type: FilterTypeKeys.contain
          })
        };
      }

      return box;
    });
    return orObj;
  });
  return {
    $and: andResult
  };
};

