'use strict';

/**
 *
 *
 * @author Mai
 * @date
 * @version
 */

const ledgerTreeCol = {
    readOnly: {
        unit_price: function (node) {
            return node.children && node.children.length > 0;
        },
        quantity: function (node) {
            return (node.children && node.children.length > 0);
        },
        total_price: function (node) {
            return node.children && node.children.length > 0;
        },
        dgnQty: function (node) {
            return !_.isEmpty(node.b_code);
        },
    },
    getEvent: function (eventName) {
        const names = eventName.split('.');
        let event = this;
        for (let name of names) {
            if (event[name]) {
                event = event[name];
            } else {
                return null;
            }
        }
        if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
            return null;
        } else {
            return event;
        }
    },
    initSpreadSetting(setting) {
        for (const col of setting.cols) {
            if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
                col.readOnly = this.getEvent(col.readOnly);
            }
        }
    }
};