var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { UmbMediaCollectionRepository } from '../collection/repository/index.js';
import { UMB_MEDIA_COLLECTION_ALIAS } from '../constants.js';
import { UMB_MEDIA_ROOT_ENTITY_TYPE } from '../entity.js';
import { css, html, customElement, state } from '../../../../external/lit/index.js';
import { UmbDataTypeDetailRepository } from '../../../data-type/index.js';
import { UmbEntityContext } from '../../../core/entity/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import { UmbPropertyEditorConfigCollection } from '../../../core/property-editor/index.js';
import { UmbCollectionElement } from '../../../core/collection/index.js';
let UmbMediaDashboardElement = class UmbMediaDashboardElement extends UmbLitElement {
    #dataTypeDetailRepository = new UmbDataTypeDetailRepository(this);
    #entityContext = new UmbEntityContext(this);
    #mediaCollectionRepository = new UmbMediaCollectionRepository(this);
    constructor() {
        super();
        this.#defineRoutes();
        this.#entityContext.setEntityType(UMB_MEDIA_ROOT_ENTITY_TYPE);
        this.#entityContext.setUnique(null);
    }
    async #defineRoutes() {
        const config = await this.#mediaCollectionRepository.getDefaultConfiguration();
        await this.#dataTypeDetailRepository.requestByUnique(config.defaultDataTypeId);
        this.observe(await this.#dataTypeDetailRepository.byUnique(config.defaultDataTypeId), (dataType) => {
            if (!dataType)
                return;
            const dataTypeConfig = this.#mapDataTypeConfigToCollectionConfig(dataType);
            this._routes = [
                {
                    path: 'collection',
                    component: () => {
                        const element = new UmbCollectionElement();
                        element.alias = UMB_MEDIA_COLLECTION_ALIAS;
                        element.config = dataTypeConfig;
                        return element;
                    },
                },
                {
                    path: '',
                    pathMatch: 'full',
                    redirectTo: 'collection',
                },
                {
                    path: `**`,
                    component: async () => (await import('../../../core/router/index.js')).UmbRouteNotFoundElement,
                },
            ];
        }, '_observeConfigDataType');
    }
    #mapDataTypeConfigToCollectionConfig(dataType) {
        const config = new UmbPropertyEditorConfigCollection(dataType.values);
        const pageSize = Number(config.getValueByAlias('pageSize'));
        return {
            unique: '',
            dataTypeId: '',
            layouts: config?.getValueByAlias('layouts'),
            orderBy: config?.getValueByAlias('orderBy') ?? 'updateDate',
            orderDirection: config?.getValueByAlias('orderDirection') ?? 'asc',
            pageSize: isNaN(pageSize) ? 50 : pageSize,
            userDefinedProperties: config?.getValueByAlias('includeProperties'),
        };
    }
    render() {
        if (!this._routes)
            return;
        return html `<umb-router-slot id="router-slot" .routes=${this._routes}></umb-router-slot>`;
    }
    static { this.styles = [
        css `
			:host {
				height: 100%;
			}

			#router-slot {
				height: calc(100% - var(--umb-header-layout-height));
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbMediaDashboardElement.prototype, "_routes", void 0);
UmbMediaDashboardElement = __decorate([
    customElement('umb-media-dashboard')
], UmbMediaDashboardElement);
export { UmbMediaDashboardElement };
export default UmbMediaDashboardElement;
