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

const MODEL = {
  type: "PAGE",
  pageType: "front", // front:正面,back:反面,cover:封面
  pageSize: "A3",
  columnNumber: 2,
  columnGap: 40,
  showPageNo: true,
  showSide: true,
  showCover: false,
  sides: [],
  columns: [],
};
// 可编辑栏
const COLUMN = {
  type: "COLUMN",
  x: "",
  y: "",
  w: "",
  h: "",
  isFull: false, // 是否已经填满元素
  elements: [],
};

const PAGE_TYPE = {
  cover: "封面",
  front: "正面",
  back: "反面",
};

const getModel = (datas = {}) => {
  let npage = deepCopy(MODEL);
  npage = objAssign(npage, datas);
  npage.id = getElementId();
  const { columnNumber } = npage;

  npage.columns = getNumList(columnNumber).map(() => {
    return { id: `column-${randomCode()}`, ...deepCopy(COLUMN) };
  });
  return npage;
};

export { MODEL, getModel, PAGE_TYPE };
