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

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

const getModel = (preSetData = {}) => {
  const model = Object.assign({}, EXPLAIN_PROP, preSetData);

  return {
    id: getElementId(),
    key: randomCode(),
    ...model,
  };
};

const getFullModel = (explainProp) => {
  const parent = { ...explainProp };

  let elements = [];

  for (let i = 0; i < explainProp.questionsCount; i++) {
    let child = Object.assign({}, deepCopy(MODEL), {
      id: getElementId(),
      key: randomCode(),
      w: parent.w,
      topicNo: parent.topicNo,
      serialNumber: i + explainProp.startNumber,
      parent,
    });

    elements[i] = child;
  }
  elements[0].showTitle = true;

  return elements;
};

export { EXPLAIN_PROP, MODEL, getModel, getFullModel };
