import { UMB_SCRIPT_ENTITY_TYPE } from '../entity.js';
import { UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS } from '../constants.js';
import { UMB_SCRIPT_WORKSPACE_ALIAS } from './manifests.js';
import { UmbScriptWorkspaceEditorElement } from './script-workspace-editor.element.js';
import { UmbEntityNamedDetailWorkspaceContextBase, UmbWorkspaceIsNewRedirectController, } from '../../../core/workspace/index.js';
import { UmbServerFileRenameWorkspaceRedirectController } from '../../../core/server-file-system/index.js';
export class UmbScriptWorkspaceContext extends UmbEntityNamedDetailWorkspaceContextBase {
    constructor(host) {
        super(host, {
            workspaceAlias: UMB_SCRIPT_WORKSPACE_ALIAS,
            entityType: UMB_SCRIPT_ENTITY_TYPE,
            detailRepositoryAlias: UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS,
        });
        this.content = this._data.createObservablePartOfCurrent((data) => data?.content);
        this.routes.setRoutes([
            {
                path: 'create/parent/:entityType/:parentUnique',
                component: UmbScriptWorkspaceEditorElement,
                setup: async (component, info) => {
                    const parentEntityType = info.match.params.entityType;
                    const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
                    await this.createScaffold({ parent: { entityType: parentEntityType, unique: parentUnique } });
                    new UmbWorkspaceIsNewRedirectController(this, this, this.getHostElement().shadowRoot.querySelector('umb-router-slot'));
                },
            },
            {
                path: 'edit/:unique',
                component: UmbScriptWorkspaceEditorElement,
                setup: (component, info) => {
                    const unique = info.match.params.unique;
                    this.load(unique);
                    new UmbServerFileRenameWorkspaceRedirectController(this, this, this.getHostElement().shadowRoot.querySelector('umb-router-slot'));
                },
            },
        ]);
    }
    /**
     * @description Set the content of the script
     * @param {string} value The content of the script
     * @memberof UmbScriptWorkspaceContext
     */
    setContent(value) {
        this._data.updateCurrent({ content: value });
    }
}
export { UmbScriptWorkspaceContext as api };
