import {
  getElementId,
  randomCode,
  objAssign,
  deepCopy,
} from "../../plugins/utils";

const EXPLAIN_PROP = {
  type: "EXPLAIN",
  sign: "subjective",
  topicNo: null,
  topicName: "",
  paperStruct: {},
};
// 解答题-小题
const MODEL = {
  type: "EXPLAIN",
  x: 0,
  y: 0,
  w: 0,
  h: 458,
  minHeight: 60,
  sign: "subjective",
  topicName: "",
  topicNo: null,
  isCovered: false,
  // 是否是小题的最后一个答题区，初始每个小题只有一个答题区，默认为true
  isLast: true,
  // 是否是小题扩展的区域
  isExtend: false,
  // 是否展示解答题题目内容，解答题第1小题的第1个答题区需要显示解答题题目内容
  showTitle: false,
  // 小题序号
  serialNumber: "",
  // 每一个解答题小题都可以包含其他基础元件，这些基础元件都用绝对定位
  elements: [],
};
// tip属性存在时的条件：parent:大题的小题，container:题目内的子元素

const getModel = (presetData) => {
  const model = objAssign(deepCopy(EXPLAIN_PROP), presetData);
  model.id = getElementId();
  model.key = randomCode();

  return model;
};

const getFullModel = (modelProp) => {
  const parent = deepCopy(modelProp);
  const childModel = objAssign(MODEL, parent);

  let elements = [];
  const questions = parent.paperStruct.questions || [];
  questions.forEach((item, index) => {
    let child = Object.assign({}, childModel, {
      id: getElementId(),
      key: randomCode(),
      serialNumber: item,
      showTitle: !index,
      elements: [],
      parent,
    });

    elements[index] = child;
  });
  // console.log(elements);

  return elements;
};

export { EXPLAIN_PROP, MODEL, getModel, getFullModel };
