import { defineProps } from '../types.js';
import { JSONData, JSONArray } from '../json.js';
import { ScriptAttachment, normalizeScriptAttachmentConfig } from '../../../scene/script_attachment.js';

function getScriptAttachmentClass() {
    return {
        ctor: ScriptAttachment,
        name: 'ScriptAttachment',
        noTitle: true,
        createFunc () {
            return {
                obj: new ScriptAttachment()
            };
        },
        getProps () {
            return defineProps([
                {
                    name: 'Script',
                    description: 'TypeScript file attached to this object',
                    type: 'string',
                    options: {
                        mimeTypes: [
                            'text/x-typescript'
                        ],
                        label: ''
                    },
                    isNullable () {
                        return true;
                    },
                    get (value) {
                        value.str[0] = this.script;
                    },
                    set (value) {
                        this.script = value?.str?.[0] ?? '';
                    }
                },
                {
                    name: 'Config',
                    description: 'JSON configuration passed to the attached script',
                    type: 'object',
                    options: {
                        objectTypes: [
                            JSONData,
                            JSONArray
                        ]
                    },
                    isHidden () {
                        return !this.script && this.config == null;
                    },
                    isNullable () {
                        return true;
                    },
                    get (value) {
                        const config = normalizeScriptAttachmentConfig(this.config);
                        value.object[0] = config == null ? null : Array.isArray(config) ? new JSONArray(null, config) : new JSONData(null, config);
                    },
                    set (value) {
                        const data = value?.object?.[0];
                        this.config = data instanceof JSONData || data instanceof JSONArray ? normalizeScriptAttachmentConfig(data.data) : normalizeScriptAttachmentConfig(data);
                    }
                }
            ]);
        }
    };
}

export { getScriptAttachmentClass };
//# sourceMappingURL=script.js.map
