"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setLegacyMode = setLegacyMode;
exports.handleLegacyConfig = exports.isLegacyMode = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _immer = _interopRequireDefault(require("immer"));

var isLegacyMode = false;
exports.isLegacyMode = isLegacyMode;

function setLegacyMode() {
  if (!isLegacyMode) {
    exports.isLegacyMode = isLegacyMode = true;
    console.log('Legacy mode enabled');
  }
}

var handleLegacyConfig = (0, _immer["default"])(function (config) {
  if (isLegacyMode) {
    if (config.type === 'form') {
      delete config.type;
    }

    if (config.type === 'boolean') {
      config.booleanWidget = {
        radio: 0,
        select: 1,
        "switch": 2,
        switchWithEmptyOption: 3
      }[config.widget]; //delete config.widget;

      config.booleanDefault = config["default"]; //delete config.default;
    }

    if (config.type === 'select') {
      config.selectWidget = {
        radio: 0
      }[config.widget]; //delete config.widget;
    }

    if (config.type === 'multiselect') {
      config.multiselectWidget = {
        checkboxes: 0
      }[config.widget]; //delete config.widget;
    }

    if (config.type === 'text' || config.type === 'textarea' || config.type === 'richtext') {
      config.textDefault = config["default"]; //delete config.default;
    }

    if (config.elements) {
      config.elements = config.elements.map(function (element) {
        return element.type === 'formGroup' ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, element), {}, {
          type: 'formgroup'
        }) : element;
      });
    }

    config.name = config.title; //delete config.title;
  }
});
exports.handleLegacyConfig = handleLegacyConfig;
//# sourceMappingURL=legacyMode.cjs.map