import { UMB_STYLESHEET_ENTITY_TYPE } from '../entity.js';
import { UMB_STYLESHEET_DETAIL_REPOSITORY_ALIAS } from '../repository/index.js';
import { UMB_STYLESHEET_WORKSPACE_ALIAS } from './manifests.js';
import { UmbStylesheetWorkspaceEditorElement } from './stylesheet-workspace-editor.element.js';
import { UmbWorkspaceIsNewRedirectController, UmbEntityNamedDetailWorkspaceContextBase, } from '../../../core/workspace/index.js';
import { UmbServerFileRenameWorkspaceRedirectController } from '../../../core/server-file-system/index.js';
export class UmbStylesheetWorkspaceContext extends UmbEntityNamedDetailWorkspaceContextBase {
    constructor(host) {
        super(host, {
            workspaceAlias: UMB_STYLESHEET_WORKSPACE_ALIAS,
            entityType: UMB_STYLESHEET_ENTITY_TYPE,
            detailRepositoryAlias: UMB_STYLESHEET_DETAIL_REPOSITORY_ALIAS,
        });
        this.content = this._data.createObservablePartOfCurrent((data) => data?.content);
        this.routes.setRoutes([
            {
                path: 'create/parent/:entityType/:parentUnique',
                component: UmbStylesheetWorkspaceEditorElement,
                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: UmbStylesheetWorkspaceEditorElement,
                setup: (component, info) => {
                    // TODO: Decode uniques [NL]
                    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 stylesheet
     * @param {string} value The content of the stylesheet
     * @memberof UmbStylesheetWorkspaceContext
     */
    setContent(value) {
        this._data.updateCurrent({ content: value });
    }
}
export { UmbStylesheetWorkspaceContext as api };
