import { UMB_MEDIA_TYPE_ENTITY_TYPE } from '../entity.js';
import { UMB_MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS } from '../constants.js';
import { UmbMediaTypeWorkspaceEditorElement } from './media-type-workspace-editor.element.js';
import { UMB_MEDIA_TYPE_WORKSPACE_ALIAS } from './constants.js';
import { UmbWorkspaceIsNewRedirectController, } from '../../../core/workspace/index.js';
import { UmbContentTypeWorkspaceContextBase } from '../../../content/content-type/index.js';
import { CompositionTypeModel } from '../../../core/backend-api/index.js';
export class UmbMediaTypeWorkspaceContext extends UmbContentTypeWorkspaceContextBase {
    constructor(host) {
        super(host, {
            workspaceAlias: UMB_MEDIA_TYPE_WORKSPACE_ALIAS,
            entityType: UMB_MEDIA_TYPE_ENTITY_TYPE,
            detailRepositoryAlias: UMB_MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS,
        });
        this.routes.setRoutes([
            {
                path: 'create/parent/:parentEntityType/:parentUnique',
                component: UmbMediaTypeWorkspaceEditorElement,
                setup: async (_component, info) => {
                    const parentEntityType = info.match.params.parentEntityType;
                    const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
                    const parent = { entityType: parentEntityType, unique: parentUnique };
                    await this.#onScaffoldSetup(parent);
                    new UmbWorkspaceIsNewRedirectController(this, this, this.getHostElement().shadowRoot.querySelector('umb-router-slot'));
                },
            },
            {
                path: 'edit/:id',
                component: UmbMediaTypeWorkspaceEditorElement,
                setup: (_component, info) => {
                    const id = info.match.params.id;
                    this.load(id);
                },
            },
        ]);
    }
    setAllowedAtRoot(allowedAtRoot) {
        this.structure.updateOwnerContentType({ allowedAtRoot });
    }
    setVariesByCulture(variesByCulture) {
        this.structure.updateOwnerContentType({ variesByCulture });
    }
    setVariesBySegment(variesBySegment) {
        this.structure.updateOwnerContentType({ variesBySegment });
    }
    setIsElement(isElement) {
        this.structure.updateOwnerContentType({ isElement });
    }
    setAllowedContentTypes(allowedContentTypes) {
        this.structure.updateOwnerContentType({ allowedContentTypes });
    }
    setCollection(collection) {
        this.structure.updateOwnerContentType({ collection });
    }
    async #onScaffoldSetup(parent) {
        let preset = undefined;
        if (parent.unique && parent.entityType === UMB_MEDIA_TYPE_ENTITY_TYPE) {
            preset = {
                compositions: [
                    {
                        contentType: { unique: parent.unique },
                        compositionType: CompositionTypeModel.INHERITANCE,
                    },
                ],
            };
        }
        this.createScaffold({ parent, preset });
    }
}
export { UmbMediaTypeWorkspaceContext as api };
