function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
import { CycleTimeUnit } from '@zgfe/business-lib/es/cycleTime';
import _ from 'lodash';
import { ajax } from '@zgfe/business-lib';
import apis from '../../../../constants/api';
import moment from 'moment';
//
export var mappingList = [[{
  id: 'eventName',
  label: '事件名称',
  defaultTarget: '【字符串】$eid',
  required: true,
  type: 'string'
}, {
  id: 'userIdentify',
  label: '主体标识字段',
  defaultTarget: '【数值】$cuid',
  required: true,
  type: 'number'
}, {
  id: 'timeField',
  label: '事件发生时间字段',
  defaultTarget: '【数值】$ct',
  type: 'number',
  required: true
}, {
  id: 'attrs',
  label: '事件属性字段',
  type: 'list'
}], [{
  id: 'userIdentify',
  label: '主体标识字段',
  defaultTarget: '【数值】$cuid',
  required: true
}, {
  id: 'timeField',
  label: '时间字段',
  defaultTarget: '【数值】$ct',
  type: 'number',
  required: true
}, {
  id: 'attrs',
  label: '主体属性字段',
  type: 'list'
}]];
// 数据集类型列表
export var datasetTypeList = [{
  value: 1,
  label: '事件数据'
}, {
  value: 2,
  label: '主体数据'
}
// {
//   value: 3,
//   label: '明细数据',
// },
];
// 更新频率列表
export var updateFrequencyList = [{
  value: 1,
  label: '手动更新'
}, {
  value: 2,
  label: '定时更新'
}
// {
//   value: 3,
//   label: '依赖数据集类型',
//   tip: '该任务调度依赖于所选择的数据集，数据集任务调度完成时，数据融合任务才能开始。',
// },
];
// 更新方式列表
export var updateWays = [{
  value: 2,
  label: '增量更新',
  tip: '增量更新表示任务只更新发生变化的数据，只能选择日期和数值类型的字段'
}, {
  value: 1,
  label: '全量更新'
}];
// 日期格式列表
export var dateFormatList = [{
  value: 'yyyyMMddHHmmss',
  label: 'yyyyMMddHHmmss'
}, {
  value: 'yyyy-MM-dd HH:mm:ss',
  label: 'yyyy-MM-dd HH:mm:ss'
}, {
  value: 'yyyy/MM/dd HH:mm:ss',
  label: 'yyyy/MM/dd HH:mm:ss'
}];
// 时间类型列表
export var timeUnitList = [{
  label: '每小时',
  value: CycleTimeUnit.hour
}, {
  label: '每日',
  value: CycleTimeUnit.day
}, {
  label: '每周',
  value: CycleTimeUnit.week
}, {
  label: '每月',
  value: CycleTimeUnit.month
}, {
  label: '指定时间',
  value: CycleTimeUnit.custom,
  disabledDate: function disabledDate(current) {
    return current && current < moment().startOf('day');
  },
  disabledTime: function disabledTime(current) {
    var range = function range(start, end) {
      var result = [];
      for (var i = start; i < end; i++) {
        result.push(i);
      }
      return result;
    };
    var minutes = Number(moment().minutes());
    var hour = Number(moment().hours());
    var disMinutes = 0;
    var disHour = 0;
    if (moment().date() === (current === null || current === void 0 ? void 0 : current.date())) {
      disHour = hour;
      if (current.hour() > hour) {
        disMinutes = 0;
      } else {
        disMinutes = minutes;
      }
    }
    return {
      disabledHours: function disabledHours() {
        return range(0, disHour);
      },
      disabledMinutes: function disabledMinutes() {
        return range(0, disMinutes);
      }
    };
  }
}];
// 目标表字段
export var targetTableColumns = [[{
  label: '【数值】$sid (会话ID)',
  value: '$sid',
  webType: 'number'
}, {
  label: '【字符串】$vn (版本)',
  value: '$vn',
  webType: 'string'
}, {
  label: '【字符串】$cn (渠道)',
  value: '$cn',
  webType: 'string'
}, {
  label: '【数值】$cr (运营商)',
  value: '$cr',
  webType: 'number'
}, {
  label: '【字符串】$os (系统)',
  value: '$os',
  webType: 'string'
}, {
  label: '【数值】$ov (系统版本)',
  value: '$ov',
  webType: 'number'
}, {
  label: '【数值】$net(网络类型)',
  value: '$net',
  webType: 'number'
}, {
  label: '【字符串】$pl (平台信息)',
  value: '$pl',
  info: '$pl (平台信息)为枚举字段，需要配置映射关系，如果未配置或配置错误默认值为JS',
  webType: 'string'
}, {
  label: '【字符串】$did (设备ID)',
  value: '$did',
  info: '$did (设备ID)选填字段，如果未填写则自动生成',
  webType: 'string'
}], [{
  label: '【字符串】$pl (平台信息)',
  value: '$pl',
  info: '$pl (平台信息)为枚举字段，需要配置映射关系，如果未配置或配置错误默认值为JS',
  webType: 'string'
}, {
  label: '【字符串】$did (设备ID)',
  value: '$did',
  info: '$did (设备ID)选填字段，如果未填写则自动生成',
  webType: 'string'
}]];
// 用户属性目标表字段
export var userTargetTableColumns = [{
  name: 'pl (平台信息)'
}, {
  name: 'did (设备ID)'
}];
//
export var mappingButtons = [{
  key: 1,
  label: '内置属性'
}, {
  key: 2,
  label: '自定义属性'
}];
// 字段类型列表
export var fieldsList = [{
  label: '字符串',
  value: 'string'
}, {
  label: '数值',
  value: 'number'
}, {
  label: '日期',
  value: 'date'
}];
export var initParams = {
  datasetType: 1,
  syncType: 2,
  updateFrequency: {
    type: 1
  },
  attrs: [{
    target: {
      hasMapping: true
    }
  }]
};
export var initAttrParams = {
  attrs: [{
    target: {
      hasMapping: true
    }
  }]
};
export var initPlatform = [{
  source: '',
  target: 'JS(H5网页)'
}, {
  source: '',
  target: 'Android'
}, {
  source: '',
  target: 'IOS'
}];
export var formatParams = function formatParams(params, type) {
  var _params$attrs;
  if (!params || type === 3) return;
  var result = _.cloneDeep(params);
  result.attrs = (_params$attrs = params.attrs) === null || _params$attrs === void 0 ? void 0 : _params$attrs.filter(function (item) {
    var _item$target;
    if (!item.source || !((_item$target = item.target) === null || _item$target === void 0 ? void 0 : _item$target.name)) return;
    return true;
  });
  return result;
};
export var getAttrData = function getAttrData(params) {
  if (params.datasetType === 3) return;
  return {
    eventName: params.eventName,
    userIdentify: params.userIdentify,
    timeField: params.timeField,
    attrs: _toConsumableArray(params.attrs || [{
      target: {
        hasMapping: true
      }
    }])
  };
};
// 判断自定义属性是否符合要求
export var nameIsFine = function nameIsFine(type, text) {
  var reg = new RegExp("[^\u4E00-\u9FA5]+$");
  var msg = '';
  if (reg.test(text)) {
    var hasAttr = targetTableColumns[type - 1].filter(function (item) {
      return item.value === text;
    });
    if (hasAttr.length) {
      msg = '属性名称重复';
    }
  } else {
    msg = '只能输入英文、符号、数字';
  }
  return msg;
};
// 获取已登记的数据集列表
export var getRegisterDataset = function getRegisterDataset(appId) {
  return new Promise(function (resolve, reject) {
    ajax(apis.queryRegisterDataset, {
      method: 'post',
      data: {
        appId: appId
      }
    }).then(function (res) {
      if (!res) return reject();
      resolve(res.data);
    });
  });
};
// 获取登记详情
export var getRegisterDetail = function getRegisterDetail(id, appId) {
  return new Promise(function (resolve, reject) {
    ajax(apis.queryRegisterDetail, {
      method: 'post',
      data: {
        id: id,
        appId: appId
      }
    }).then(function (res) {
      if (!res) return reject();
      resolve(res.data);
    });
  });
};
export var webTypeMap = {
  string: '【字符串】',
  number: '【数值】',
  date: '【日期】'
};