import { lazy } from 'react';
import { getConf } from '@jbrowse/core/configuration';
import SnackbarModel from '@jbrowse/core/ui/SnackbarModel';
import { getParent, types } from '@jbrowse/mobx-state-tree';
import { BaseSessionModel, ConnectionManagementSessionMixin, DialogQueueSessionMixin, DrawerWidgetSessionMixin, ReferenceManagementSessionMixin, TracksManagerSessionMixin, } from '@jbrowse/product-core';
import InfoIcon from '@mui/icons-material/Info';
const AboutDialog = lazy(() => import("./AboutDialog.js"));
export default function sessionModelFactory(pluginManager) {
    return types
        .compose('ReactCircularGenomeViewSession', BaseSessionModel(pluginManager), DrawerWidgetSessionMixin(pluginManager), ConnectionManagementSessionMixin(pluginManager), DialogQueueSessionMixin(pluginManager), TracksManagerSessionMixin(pluginManager), ReferenceManagementSessionMixin(pluginManager), SnackbarModel())
        .props({
        view: pluginManager.getViewType('CircularView').stateModel,
    })
        .volatile(() => ({
        task: undefined,
    }))
        .views(self => ({
        get version() {
            return getParent(self).version;
        },
        get assemblies() {
            return [getParent(self).config.assembly];
        },
        get assemblyNames() {
            return [getParent(self).config.assemblyName];
        },
        get connections() {
            return getParent(self).config.connections;
        },
        get assemblyManager() {
            return getParent(self).assemblyManager;
        },
        get views() {
            return [self.view];
        },
        renderProps() {
            return {
                theme: getConf(self, 'theme'),
                highResolutionScaling: getConf(self, 'highResolutionScaling'),
            };
        },
    }))
        .actions(self => ({
        addView(typeName, initialState = {}) {
            const typeDefinition = pluginManager.getElementType('view', typeName);
            if (!typeDefinition) {
                throw new Error(`unknown view type ${typeName}`);
            }
            self.view = {
                ...initialState,
                type: typeName,
            };
            return self.view;
        },
        removeView() { },
    }))
        .views(self => ({
        getTrackActionMenuItems(config, extraTrackActions) {
            return [
                {
                    label: 'About track',
                    onClick: () => {
                        self.queueDialog(doneCallback => [
                            AboutDialog,
                            { config, session: self, handleClose: doneCallback },
                        ]);
                    },
                    icon: InfoIcon,
                },
                ...(extraTrackActions || []),
            ];
        },
    }));
}
function z(x) {
    return x;
}
