import { WidgetModel, } from '@jupyter-widgets/base';
import { MODULE_NAME, MODULE_VERSION } from '../version';
class Bar3DModel extends WidgetModel {
    defaults() {
        return {
            ...super.defaults(),
            _model_name: Bar3DModel.model_name,
            _model_module: Bar3DModel.model_module,
            _model_module_version: Bar3DModel.model_module_version
        };
    }
    toDict() {
        const dict = {};
        for (const [key, val] of Object.entries(this.attributes)) {
            if (key === 'unknown_attrs') {
                if (val) {
                    for (const [unknown_key, unknown_val] of Object.entries(val)) {
                        dict[unknown_key] = unknown_val;
                    }
                }
                continue;
            }
            if (typeof val === 'string' && val.startsWith('__ipecharts_jsfn__::')) {
                const funcStr = val.replace('__ipecharts_jsfn__::', '');
                const decodedString = atob(funcStr);
                const jsonObject = JSON.parse(decodedString);
                const fn = new Function(...jsonObject);
                dict[key] = fn;
                continue;
            }
            if (val !== undefined && val !== null && !key.startsWith('_')) {
                dict[key] = val;
            }
        }
        return dict;
    }
    initialize(attributes, options) {
        var _a;
        super.initialize(attributes, options);
        if (Bar3DModel.updateManager) {
            Bar3DModel.updateManager.registerModel(this);
            (_a = this.comm) === null || _a === void 0 ? void 0 : _a.on_close(() => {
                Bar3DModel.updateManager.unregisterModel(this);
            });
        }
        this.listenTo(this, 'change', this.valueChanged);
    }
    valueChanged(m) {
        var _a;
        if (m === null || m === void 0 ? void 0 : m.changed) {
            Object.values(m.changed).forEach(it => {
                var _a;
                if (Array.isArray(it)) {
                    it.forEach(subModel => {
                        var _a;
                        if (subModel === null || subModel === void 0 ? void 0 : subModel.model_id) {
                            (_a = Bar3DModel.updateManager) === null || _a === void 0 ? void 0 : _a.registerChildModel({
                                child: subModel,
                                parent: m
                            });
                        }
                    });
                }
                else {
                    if (it === null || it === void 0 ? void 0 : it.model_id) {
                        (_a = Bar3DModel.updateManager) === null || _a === void 0 ? void 0 : _a.registerChildModel({
                            child: it,
                            parent: m
                        });
                    }
                }
            });
        }
        if (Bar3DModel.updateManager) {
            Bar3DModel.updateManager.sendUpdateSignal(this);
            (_a = this.comm) === null || _a === void 0 ? void 0 : _a.on_close(() => {
                Bar3DModel.updateManager.unregisterModel(this);
            });
        }
    }
}
Bar3DModel.serializers = {
    ...WidgetModel.serializers,
};
Bar3DModel.updateManager = null;
Bar3DModel.model_name = 'Bar3DModel';
Bar3DModel.model_module = MODULE_NAME;
Bar3DModel.model_module_version = MODULE_VERSION;
export { Bar3DModel };
