/**
 * 对话框表单保存，页面模板
 * @param {*} saveDataset 保存数据集，命名规范 ds_[数组下标]_[对话框id]
 * @param {*} conf 组件定义配置项
 * @returns 
 */
import { StringUtil } from "@birt/funclib/StringUtil.js";

export function newInstance(saveDataset, conf) {
    const dlgId = StringUtil.randomString(6);
    // 设置数据集id
    saveDataset.controlId += "_" + dlgId;
    // 表单操作工具条
    var hcFormToolbar = {
        controlName: "HcFormToolbar",
        controlId: "HcFormToolbar_" + dlgId,
        dataset: saveDataset.controlId,
        layout: ["cancel", "save"],
        style: "padding:15px;"
    }
    // 应用工具条个性化配置
    Object.assign(hcFormToolbar, conf.hcFormToolbar || {});
    // 表单内容
    var hcForm = {
        controlName: "HcForm",
        controlId: "HcForm_" + dlgId,
        dataset: saveDataset,
        labelWidth: "80px",
        rules: {
        },
        children: [],
    };
    // 应用表单个性化配置
    Object.assign(hcForm, conf.hcForm || {});
    // 返回布局结构
    return {
        controlName: "BirtWorkBook",
        controlId: "BirtWorkBook_" + dlgId,
        showToolBar: false,
        totalPage: 1,
        renderType: "pages",
        height: function (parentHeight) {
            return parentHeight;
        },
        confirm: function (callFun) {

        },
        children: [
            {
                controlName: "BirtSheet",
                controlId: "BirtSheet_" + dlgId,
                name: "sheet_" + dlgId,
                pageIndex: 0,
                dataSets: [saveDataset],
                children: [
                    {
                        controlName: "BirtFormSheet",
                        controlId: "BirtFormSheet_" + dlgId,
                        children: [
                            hcFormToolbar,
                            hcForm
                        ]
                    }
                ]
            }
        ]
    }
}