"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.constructFormParams = constructFormParams;
var _FrameHelpers = require("./FrameHelpers");
var CONST = _interopRequireWildcard(require("./constants"));
var util = _interopRequireWildcard(require("./utils"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function constructFormParams(props, setDocumentation, reference, setReference, setReadOnly, setMessage, display, setDisplay) {
  var frame = props.frame,
    uiFrame = props.uiFrame,
    type = props.type,
    mode = props.mode,
    formData = props.formData,
    compareFormData = props.compareFormData,
    onTraverse = props.onTraverse,
    onSelect = props.onSelect,
    language = props.language;

  // current document class to be display in <Viewer/>
  var current = "".concat(type);

  //let extractedDocumentation= util.extractDocumentation(frame, current, language)
  //store selected language here to get access to ENUM docs based on selected language
  frame[CONST.SELECTED_LANGUAGE] = language ? language : CONST.DEFAULT_LANGUAGE;
  var extractedDocumentation = util.extractDocumentation(frame, type, language);
  setDocumentation(extractedDocumentation);
  var fullFrame = frame;
  var documentFrame = frame[current];
  var properties = (0, _FrameHelpers.getProperties)({
    fullFrame: fullFrame,
    type: type,
    documentFrame: documentFrame,
    uiFrame: uiFrame,
    mode: mode,
    formData: formData,
    compareFormData: compareFormData,
    onTraverse: onTraverse,
    onSelect: onSelect,
    extractedDocumentation: extractedDocumentation,
    reference: reference,
    setReference: setReference
  });
  var schema = {
    type: CONST.OBJECT_TYPE,
    properties: properties.properties,
    required: properties.required,
    dependencies: properties.dependencies
  };
  /*console.log("schema", JSON.stringify(schema, null, 2))
  console.log("uiSchema", JSON.stringify(properties.uiSchema, null, 2))*/
  //console.log("display", display)

  console.log("schema", schema);
  console.log("properties.uiSchema", properties.uiSchema);
  //setUISchema(uiSchema)
  //setSchema(schema)

  // order is set to place @documentation field at the start of the document
  properties.uiSchema["ui:order"] = util.getDocumentOrderBy(documentFrame);
  if (uiFrame && uiFrame.hasOwnProperty(type) && uiFrame[type].hasOwnProperty(CONST.CLASSNAME)) properties.uiSchema["classNames"] = uiFrame[type][CONST.CLASSNAME];
  var schemata = {
    schema: schema,
    uiSchema: properties.uiSchema
  };
  setDisplay(schemata);
  if (mode === CONST.VIEW) {
    setReadOnly(true);
  } else if (mode === CONST.EDIT && util.isValueHashDocument(frame[current])) {
    setMessage(util.getValueHashMessage());
    setReadOnly(true);
  }
}

//else if(mode === CONST.CREATE) setInput(formData)
/*
else {
		setReadOnly(false)
}
setSchema(schema)
const uiSchema = properties.uiSchema
	// get form level ui schema 
if(uiFrame && uiFrame.hasOwnProperty("classNames")) uiSchema["classNames"]= uiFrame.classNames
if(uiFrame && uiFrame.hasOwnProperty("ui:order")) uiSchema["ui:order"]=uiFrame["ui:order"]
if(uiFrame && uiFrame.hasOwnProperty("ui:title")) uiSchema["ui:title"]= uiFrame["ui:title"]
if(uiFrame && uiFrame.hasOwnProperty("ui:description")) uiSchema["ui:description"]= uiFrame["ui:description"]

// order is set to place @documentation field at the start of the document
if(frame) {
	uiSchema["ui:order"] = util.getOrderFromMetaData(frame[type])
}

setUISchema(uiSchema)
	// process form data to check if one ofs are available
if(mode !== CONST.CREATE) {
		setData(util.getFormData(formData))
}*/