"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getTypeData = exports.getSource = exports["default"] = exports.bookDemoTransformDataToJson = void 0;

var _constant = require("./constant");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var getTypeData = function getTypeData(type) {
  return _constant.bookTypeInfo[type];
};

exports.getTypeData = getTypeData;

var getSource = function getSource() {
  var reg = /source=[0-9]*/g;
  var sourceQuery = window.location.href.match(reg);

  if (sourceQuery) {
    var source = decodeURIComponent(sourceQuery[0].split("=")[1]);
    return source;
  }

  return 0;
};

exports.getSource = getSource;

var bookDemoTransformDataToJson = function bookDemoTransformDataToJson(data, source, appliedProduct, content, uid) {
  var result = _objectSpread({}, _constant.defaultBookDemoJsonValue);

  data.forEach(function (item) {
    if (typeof item.value === "string") {
      if (item.id === "employeeRange") {
        if (/-/.test(item.value)) {
          result.employeeCount = item.value.split("-")[1];
        } else if (item.value === "10000+") {
          result.employeeCount = "20000";
        } else if (item.value === "我代表一组公司") {
          result.employeeCount = "30000";
        } else {
          result.employeeCount = item.value;
        }
      }

      result[item.id] = item.value;
    } else if (item.type === "checkbox" && item.multiSelect) {
      Object.keys(item.value).forEach(function (key) {
        result[key] = item.value[key].isSelected ? 1 : 0;
      });
    } else if (item.type === "checkbox" && !item.multiSelect) {
      var filterCheckData = Object.values(item.value).filter(function (val) {
        return val.isSelected;
      });

      if (filterCheckData.length > 0) {
        result[item.id] = filterCheckData[0].text;
      } else {
        result[item.id] = "";
      }
    }
  });
  result.source = source;
  result.appliedProduct = appliedProduct;
  result.content = content;
  result.tenantId = uid;
  delete result.verificationCode;
  return result;
};

exports.bookDemoTransformDataToJson = bookDemoTransformDataToJson;
var _default = {
  getTypeData: getTypeData,
  getSource: getSource
};
exports["default"] = _default;