import { AXBadgeModule } from '@acorex/components/badge';
import { AXBreadcrumbsModule } from '@acorex/components/breadcrumbs';
import * as i2 from '@acorex/components/button';
import { AXButtonModule } from '@acorex/components/button';
import { AXButtonGroupModule } from '@acorex/components/button-group';
import * as i1 from '@acorex/components/decorators';
import { AXDecoratorModule } from '@acorex/components/decorators';
import { AXDropdownModule } from '@acorex/components/dropdown';
import { AXDropdownButtonModule } from '@acorex/components/dropdown-button';
import { AXLoadingModule } from '@acorex/components/loading';
import { AXMenuModule } from '@acorex/components/menu';
import { AXBasePageComponent } from '@acorex/components/page';
import * as i4 from '@acorex/components/search-box';
import { AXSearchBoxModule } from '@acorex/components/search-box';
import { AXDateTimeModule } from '@acorex/core/date-time';
import { AXFileModule } from '@acorex/core/file';
import { AXFormatModule } from '@acorex/core/format';
import * as i3 from '@acorex/core/translation';
import { AXTranslationModule } from '@acorex/core/translation';
import { AXPSessionService } from '@acorex/platform/auth';
import { AXPFileTypeProviderService } from '@acorex/platform/common';
import { AXPLayoutThemeService } from '@acorex/platform/themes/shared';
import * as i1$1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, signal, viewChild, computed, effect, untracked, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
import { RouterModule } from '@angular/router';
import { R as RootConfig, a as AXMDocumentManagerService, A as AXPDocumentExplorerViewModel, b as AXMDocumentExplorerComponent, d as AXMFolderPathBreadcrumbsComponent } from './acorex-modules-document-management-acorex-modules-document-management-BsfSETMk.mjs';

class AXMDocumentDriveChooseComponent extends AXBasePageComponent {
    constructor() {
        super(...arguments);
        this.layout = inject(AXPLayoutThemeService);
        this.rootConfig = RootConfig;
        this.fileTypeService = inject(AXPFileTypeProviderService);
        this.driveService = inject(AXMDocumentManagerService);
        this.vm = inject(AXPDocumentExplorerViewModel);
        this.sessionService = inject(AXPSessionService);
        this.filterItems = signal([], ...(ngDevMode ? [{ debugName: "filterItems" }] : []));
        this.selectedFilter = signal('all', ...(ngDevMode ? [{ debugName: "selectedFilter" }] : []));
        this.browseMode = 'file';
        this.selectionMode = 'single';
        this.sortItems = signal([
            { key: 'name', textKey: 'actions.sort-by-name', icon: 'fa-light fa-font' },
            { key: 'modified', textKey: 'actions.sort-by-date', icon: 'fa-light fa-calendar' },
            { key: 'size', textKey: 'actions.sort-by-size', icon: 'fa-light fa-weight-hanging' },
        ], ...(ngDevMode ? [{ debugName: "sortItems" }] : []));
        this.documentExplorer = viewChild(AXMDocumentExplorerComponent, ...(ngDevMode ? [{ debugName: "documentExplorer" }] : []));
        this.selectedSort = computed(() => {
            const items = this.sortItems();
            return items.find((item) => item.key === this.vm.sortField()) || items[0];
        }, ...(ngDevMode ? [{ debugName: "selectedSort" }] : []));
        this.selectText = computed(() => {
            return this.vm.browseMode() == 'file' ? 'actions.select-file' : 'actions.select-folder';
        }, ...(ngDevMode ? [{ debugName: "selectText" }] : []));
        this.searchQuery = '';
        this.#navigateEffect = effect(() => {
            const navigatingFolderId = this.vm.navigatingFolderId();
            if (navigatingFolderId) {
                this.loadDrive(navigatingFolderId);
                // Clear search when navigating to a folder
                setTimeout(() => {
                    this.searchQuery = null;
                }, 200);
            }
        }, ...(ngDevMode ? [{ debugName: "#navigateEffect" }] : []));
        this.#loadingEffect = effect(() => {
            const isLoading = this.vm.isLoading();
            untracked(() => {
                this.layout.setNavigationLoading(isLoading);
            });
        }, ...(ngDevMode ? [{ debugName: "#loadingEffect" }] : []));
    }
    #navigateEffect;
    #loadingEffect;
    async handleSearchChange(event) {
        if (event.value == null) {
            return;
        }
        if (event.value?.length > 0) {
            const result = await this.driveService.searchNodes(event.value, this.scope, {
                tenantId: this.sessionService.tenant?.id,
                userId: this.sessionService.user?.id,
            });
            this.vm.virtualFolder(result, {
                name: 'Search Result',
                parentId: this.vm.currentNode()?.id == 'virtual' ?
                    this.vm.currentNode()?.parentId ?? undefined : this.vm.currentNode()?.id,
            });
        }
        else {
            this.vm.navigateToUp();
        }
    }
    async ngOnInit() {
        super.ngOnInit();
        await this.loadFilterItems();
        await this.vm.initialize({
            browseMode: this.browseMode,
            scope: this.scope,
        });
        this.loadDrive();
    }
    async loadDrive(folderId) {
        if (folderId) {
            await this.vm.loadFolderContents(folderId);
        }
        else {
            const root = await this.driveService.getRoot(this.scope, {
                tenantId: this.sessionService.tenant?.id,
                userId: this.sessionService.user?.id,
            });
            if (root.result) {
                await this.vm.loadFolderContents(root.result.id);
            }
        }
    }
    async loadFilterItems() {
        const types = await this.fileTypeService.items();
        const items = [
            { key: 'all', textKey: 'file-types.all', icon: 'fa-light fa-folder-closed' },
            ...types.map((type) => ({
                key: type.name,
                textKey: `file-types.${type.name}`,
                icon: type.icon || 'fa-light fa-file',
            })),
        ];
        this.filterItems.set(items);
    }
    setFilter(key) {
        this.selectedFilter.set(key);
    }
    getFilterIcon() {
        if (this.selectedFilter() === 'all') {
            return 'fa-light fa-folder-closed';
        }
        const item = this.filterItems().find((item) => item.key === this.selectedFilter());
        return item?.icon || 'fa-light fa-file';
    }
    getFilterText() {
        if (this.selectedFilter() === 'all') {
            return 'file-types.all';
        }
        const item = this.filterItems().find((item) => item.key === this.selectedFilter());
        return item?.textKey || 'file-types.all';
    }
    handleNavigateToFolder(folderId) {
        this.vm.navigateToFolder(folderId);
    }
    async handleSubmitButton() {
        this.close({
            result: true,
            items: this.vm.browseMode() == 'file' ? this.vm.selectedNodes() : [this.vm.currentFolder()],
        });
    }
    handleCancelClick() {
        this.close({
            result: false,
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMDocumentDriveChooseComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.4", type: AXMDocumentDriveChooseComponent, isStandalone: true, selector: "ax-document-drive-choose", providers: [AXPDocumentExplorerViewModel], viewQueries: [{ propertyName: "documentExplorer", first: true, predicate: AXMDocumentExplorerComponent, descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "<div class=\"ax-flex ax-p-2 ax-items-center ax-w-full ax-light-surface ax-border-b\" *translate=\"let t\">\n  <!-- Breadcrumbs Section -->\n  <axm-folder-path-breadcrumbs></axm-folder-path-breadcrumbs>\n  <!-- Search Box -->\n  <ax-search-box\n    [(value)]=\"searchQuery\"\n    (onValueChanged)=\"handleSearchChange($event)\"\n    class=\"ax-w-72 ax-sm\"\n    [placeholder]=\"t('actions.search', { scope: rootConfig.config.i18n }) | async\"\n    ><ax-clear-button></ax-clear-button\n  ></ax-search-box>\n</div>\n<div class=\"ax-p-2\">\n  <axm-document-explorer\n    [browseMode]=\"browseMode\"\n    [selectionMode]=\"selectionMode\"\n    [viewMode]=\"'list'\"\n    [showContextMenu]=\"false\"\n  >\n  </axm-document-explorer>\n</div>\n<ax-footer *translate=\"let t\">\n  <ax-suffix>\n    <ax-button (onClick)=\"handleCancelClick()\" [text]=\"'@general:actions.cancel.title' | translate | async\"></ax-button>\n    <ax-button\n      look=\"solid\"\n      color=\"primary\"\n      (onClick)=\"handleSubmitButton()\"\n      [text]=\"t(selectText(), { scope: rootConfig.config.i18n }) | async\"\n    >\n    </ax-button>\n  </ax-suffix>\n</ax-footer>\n", styles: ["ax-document-drive-choose{display:block;min-height:50vh;width:100%;background-color:rgb(var(--ax-sys-color-lightest-surface));color:rgb(var(--ax-sys-color-on-lightest-surface));border-color:rgb(var(--ax-sys-color-border-lightest-surface))}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: RouterModule }, { kind: "ngmodule", type: AXMenuModule }, { kind: "ngmodule", type: AXButtonModule }, { kind: "component", type: i2.AXButtonComponent, selector: "ax-button", inputs: ["disabled", "size", "tabIndex", "color", "look", "text", "toggleable", "selected", "iconOnly", "type", "loadingText"], outputs: ["onBlur", "onFocus", "onClick", "selectedChange", "toggleableChange", "lookChange", "colorChange", "disabledChange", "loadingTextChange"] }, { kind: "ngmodule", type: AXButtonGroupModule }, { kind: "ngmodule", type: AXDropdownButtonModule }, { kind: "ngmodule", type: AXDropdownModule }, { kind: "ngmodule", type: AXTranslationModule }, { kind: "directive", type: i3.AXTranslatorDirective, selector: "[translate]" }, { kind: "ngmodule", type: AXDecoratorModule }, { kind: "component", type: i1.AXDecoratorClearButtonComponent, selector: "ax-clear-button", inputs: ["icon"] }, { kind: "component", type: i1.AXDecoratorGenericComponent, selector: "ax-footer, ax-header, ax-content, ax-divider, ax-form-hint, ax-prefix, ax-suffix, ax-text, ax-title, ax-subtitle, ax-placeholder, ax-overlay" }, { kind: "ngmodule", type: AXLoadingModule }, { kind: "ngmodule", type: AXBadgeModule }, { kind: "ngmodule", type: AXSearchBoxModule }, { kind: "component", type: i4.AXSearchBoxComponent, selector: "ax-search-box", inputs: ["disabled", "readonly", "tabIndex", "placeholder", "value", "state", "name", "id", "look", "class", "delayTime", "type"], outputs: ["valueChange", "stateChange", "onValueChanged", "onBlur", "onFocus", "readonlyChange", "disabledChange", "onKeyDown", "onKeyUp", "onKeyPress"] }, { kind: "ngmodule", type: AXFormatModule }, { kind: "ngmodule", type: AXFileModule }, { kind: "ngmodule", type: AXBreadcrumbsModule }, { kind: "ngmodule", type: AXDateTimeModule }, { kind: "component", type: AXMDocumentExplorerComponent, selector: "axm-document-explorer", inputs: ["browseMode", "viewMode", "selectionMode", "showContextMenu"] }, { kind: "component", type: AXMFolderPathBreadcrumbsComponent, selector: "axm-folder-path-breadcrumbs" }, { kind: "pipe", type: i1$1.AsyncPipe, name: "async" }, { kind: "pipe", type: i3.AXTranslatorPipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMDocumentDriveChooseComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-document-drive-choose', standalone: true, imports: [
                        CommonModule,
                        RouterModule,
                        AXMenuModule,
                        AXButtonModule,
                        AXButtonGroupModule,
                        AXDropdownButtonModule,
                        AXDropdownModule,
                        AXTranslationModule,
                        AXDecoratorModule,
                        AXLoadingModule,
                        AXBadgeModule,
                        AXSearchBoxModule,
                        AXFormatModule,
                        AXFileModule,
                        AXBreadcrumbsModule,
                        AXDateTimeModule,
                        AXMDocumentExplorerComponent,
                        AXMFolderPathBreadcrumbsComponent,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [AXPDocumentExplorerViewModel], template: "<div class=\"ax-flex ax-p-2 ax-items-center ax-w-full ax-light-surface ax-border-b\" *translate=\"let t\">\n  <!-- Breadcrumbs Section -->\n  <axm-folder-path-breadcrumbs></axm-folder-path-breadcrumbs>\n  <!-- Search Box -->\n  <ax-search-box\n    [(value)]=\"searchQuery\"\n    (onValueChanged)=\"handleSearchChange($event)\"\n    class=\"ax-w-72 ax-sm\"\n    [placeholder]=\"t('actions.search', { scope: rootConfig.config.i18n }) | async\"\n    ><ax-clear-button></ax-clear-button\n  ></ax-search-box>\n</div>\n<div class=\"ax-p-2\">\n  <axm-document-explorer\n    [browseMode]=\"browseMode\"\n    [selectionMode]=\"selectionMode\"\n    [viewMode]=\"'list'\"\n    [showContextMenu]=\"false\"\n  >\n  </axm-document-explorer>\n</div>\n<ax-footer *translate=\"let t\">\n  <ax-suffix>\n    <ax-button (onClick)=\"handleCancelClick()\" [text]=\"'@general:actions.cancel.title' | translate | async\"></ax-button>\n    <ax-button\n      look=\"solid\"\n      color=\"primary\"\n      (onClick)=\"handleSubmitButton()\"\n      [text]=\"t(selectText(), { scope: rootConfig.config.i18n }) | async\"\n    >\n    </ax-button>\n  </ax-suffix>\n</ax-footer>\n", styles: ["ax-document-drive-choose{display:block;min-height:50vh;width:100%;background-color:rgb(var(--ax-sys-color-lightest-surface));color:rgb(var(--ax-sys-color-on-lightest-surface));border-color:rgb(var(--ax-sys-color-border-lightest-surface))}\n"] }]
        }] });

export { AXMDocumentDriveChooseComponent };
//# sourceMappingURL=acorex-modules-document-management-drive-choose.component-BcLME_up.mjs.map
