'use strict';

import { JpcCommonHelper } from './helper/jpc_helper_common';
import { IBandDetail, IBands, IDefProperties, IOrgBandDetail, IRptTpl, } from '../interface/basic';
import { JpcBandHelper } from './helper/jpc_helper_band';

export const JpcBand = {
    createNew(rptTpl: IRptTpl, defProperties: IDefProperties) {
        let me = this;
        let JpcBandResult: any = {};
        if (rptTpl.布局框_集合) {
            for (let i = 0; i < rptTpl.布局框_集合.length; i++) {
                me.createSingle(rptTpl.布局框_集合[i], JpcBandResult, rptTpl, defProperties);
            }
        }
        return JpcBandResult;
    },
    //根据模板信息生成大板块的数据
    createSingle(bandNode: IOrgBandDetail, parentObj: IBands, rptTpl: IRptTpl, defProperties: IDefProperties) {
        let me = this;
        if (bandNode && bandNode.Name) {
            let item = {
                Left: 0,
                Right: 0,
                Top: 0,
                Bottom: 0,
                style: JpcCommonHelper.getStyle(bandNode.style, defProperties.styles),
                control: JpcCommonHelper.getControl(bandNode.control, defProperties.ctrls),
                Height: (bandNode.Height) ? parseFloat(bandNode.Height) : 0,
                Width: (bandNode.Width) ? parseFloat(bandNode.Width) : 0,
                DisplayType: JpcBandHelper.getBandTypeValByString(bandNode.DisplayType),
                Alignment: JpcCommonHelper.getLayoutAlignment(bandNode.Alignment),
                CalculationType: JpcCommonHelper.getPosCalculationType(bandNode.CalculationType),
            } as IBandDetail;
            if (bandNode.normalOnly) {
                item.normalOnly = JpcCommonHelper.getBoolean(bandNode.normalOnly);
            }
            if (bandNode.exOnly) {
                item.exOnly = JpcCommonHelper.getBoolean(bandNode.exOnly);
            }

            if (bandNode.MergeBorder) {
                item.MergeBorder = bandNode.MergeBorder;
            }
            if (bandNode.band_s) {
                for (let i = 0; i < bandNode.band_s.length; i++) {
                    me.createSingle(bandNode.band_s[i], parentObj, rptTpl, defProperties);
                }
            }
            parentObj[bandNode.Name] = item;
            if (item.MergeBorder !== null && item.MergeBorder !== undefined && item.MergeBorder === 'T') {
                parentObj.MergeBand = item;
            }
        }
    }
};