import { AXComponent, MXBaseComponent } from '@acorex/cdk/common';
import * as i0 from '@angular/core';
import { signal, Injectable, inject, ViewEncapsulation, Component, ChangeDetectionStrategy, input, output, viewChild, effect, afterNextRender, NgModule } from '@angular/core';
import { AXBreadCrumbsComponent, AXBreadCrumbsItemComponent, AXBreadcrumbsModule } from '@acorex/components/breadcrumbs';
import { AXButtonComponent, AXButtonModule } from '@acorex/components/button';
import { AXDecoratorGenericComponent, AXDecoratorIconComponent, AXDecoratorModule } from '@acorex/components/decorators';
import { AXMenuComponent, AXMenuItemComponent, AXContextMenuComponent, AXMenuModule } from '@acorex/components/menu';
import { AXToolBarComponent, AXToolBarModule } from '@acorex/components/toolbar';
import { NgClass, NgStyle, CommonModule } from '@angular/common';
import { AXDrawerComponent, AXDrawerContainerComponent, AXDrawerModule } from '@acorex/components/drawer';
import { AXTreeViewComponent, AXTreeViewModule } from '@acorex/components/tree-view';

class AXFileExplorerInternalService {
    constructor() {
        this.viewMode = signal('ax-large-icon', ...(ngDevMode ? [{ debugName: "viewMode" }] : []));
        this.treeViewState = signal(false, ...(ngDevMode ? [{ debugName: "treeViewState" }] : []));
        this.allData = signal([], ...(ngDevMode ? [{ debugName: "allData" }] : []));
        this.showData = signal([], ...(ngDevMode ? [{ debugName: "showData" }] : []));
        this.breadcrumbsData = signal(['root'], ...(ngDevMode ? [{ debugName: "breadcrumbsData" }] : []));
        this.activeFolderId = signal(null, ...(ngDevMode ? [{ debugName: "activeFolderId" }] : []));
        this.dataCallBack = signal(null, ...(ngDevMode ? [{ debugName: "dataCallBack" }] : []));
        this.treeViewInstant = signal(null, ...(ngDevMode ? [{ debugName: "treeViewInstant" }] : []));
        this.clickedItems = new Set();
    }
    findItemInNestedArray(array, predicate) {
        for (const item of array) {
            if (predicate(item)) {
                return item;
            }
            if (item.children) {
                const found = this.findItemInNestedArray(item.children, predicate);
                if (found)
                    return found;
            }
        }
        return null;
    }
    async dbClickHandler(item, isTreeViewClicked = true) {
        if (item.extension)
            return;
        if (!item?.id)
            return;
        if (isTreeViewClicked) {
            this.treeViewInstant().executeOnTreeNode(item, 'active', true);
            this.treeViewInstant().executeOnTreeNode(item, 'expand', true);
        }
        this.activeFolderId.set(item.id);
        const clickedItem = this.findItemInNestedArray(this.allData(), (e) => e.id === item.id);
        this.breadcrumbsData.update((prev) => [...prev, clickedItem.text]);
        let canPass = true;
        this.clickedItems.forEach((e) => {
            if (e === item.id)
                canPass = false;
        });
        this.clickedItems.add(item.id);
        if (!canPass)
            return;
        const newChild = await this.dataCallBack()(item.id);
        this.allData.update((prev) => {
            const copy = [...prev];
            const find = this.findItemInNestedArray(copy, (e) => e.id === item.id);
            find.children = newChild;
            return copy;
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerInternalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerInternalService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerInternalService, decorators: [{
            type: Injectable
        }] });

class AXFileExplorerService {
    constructor() {
        this.internalService = inject(AXFileExplorerInternalService);
    }
    backButtonHandler() {
        this.internalService.breadcrumbsData.update((prev) => {
            const copy = [...prev];
            if (copy.length !== 1)
                copy.pop();
            return copy;
        });
        const parentId = this.internalService.showData()[0].parentId;
        const parent = this.internalService.findItemInNestedArray(this.internalService.allData(), (item) => item.id === parentId);
        if (parent?.parentId) {
            this.internalService.activeFolderId.set(parent.parentId);
        }
        else {
            this.internalService.activeFolderId.set(null);
        }
        this.internalService.treeViewInstant().executeOnTreeNode(parent, 'active', false);
    }
    menuToggleHandler() {
        this.internalService.treeViewState.update((prev) => !prev);
    }
    changeViewHandler(v) {
        this.internalService.viewMode.set(v);
    }
    async sortItemHandler(sort) {
        await this.internalService.dataCallBack()(this.internalService.activeFolderId(), sort);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerService, decorators: [{
            type: Injectable
        }] });

class AXFileExplorerContainerComponent {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.9", type: AXFileExplorerContainerComponent, isStandalone: true, selector: "ax-file-explorer-container", providers: [
            AXFileExplorerService,
            AXFileExplorerInternalService,
            { provide: AXComponent, useExisting: AXFileExplorerContainerComponent },
        ], ngImport: i0, template: "<ng-content select=\"ax-file-explorer-tree\"></ng-content>\n<ng-content select=\"ax-file-explorer-view\"></ng-content>\n", styles: ["ax-file-explorer-container{display:flex;min-width:30vw;max-height:40vh;overflow:hidden;border:1px solid rgba(var(--ax-sys-color-border-lightest-surface));border-radius:var(--ax-sys-border-radius)}\n"], encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerContainerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-file-explorer-container', encapsulation: ViewEncapsulation.None, providers: [
                        AXFileExplorerService,
                        AXFileExplorerInternalService,
                        { provide: AXComponent, useExisting: AXFileExplorerContainerComponent },
                    ], template: "<ng-content select=\"ax-file-explorer-tree\"></ng-content>\n<ng-content select=\"ax-file-explorer-view\"></ng-content>\n", styles: ["ax-file-explorer-container{display:flex;min-width:30vw;max-height:40vh;overflow:hidden;border:1px solid rgba(var(--ax-sys-color-border-lightest-surface));border-radius:var(--ax-sys-border-radius)}\n"] }]
        }] });

class AXFileExplorerHeaderComponent {
    constructor() {
        this.service = inject(AXFileExplorerService);
        this.internalService = inject(AXFileExplorerInternalService);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXFileExplorerHeaderComponent, isStandalone: true, selector: "ax-file-explorer-header", providers: [{ provide: AXComponent, useExisting: AXFileExplorerHeaderComponent }], ngImport: i0, template: "<ax-toolbar>\n  <ax-prefix>\n    <ax-button (onClick)=\"service.menuToggleHandler()\" look=\"blank\">\n      <ax-icon class=\"ax-icon ax-icon-menu\"></ax-icon>\n    </ax-button>\n\n    <ax-divider></ax-divider>\n\n    <ax-button (onClick)=\"service.backButtonHandler()\" look=\"blank\">\n      <ax-icon class=\"ax-icon ax-icon-up-folder\"></ax-icon>\n    </ax-button>\n\n    <ax-divider></ax-divider>\n\n    <ax-breadcrumbs>\n      @if (false) {\n        <ng-template #divider> '|' </ng-template>\n      }\n      @for (item of internalService.breadcrumbsData(); track item; let idx = $last) {\n        <ax-breadcrumbs-item [active]=\"idx\">\n          <ax-text>{{ item }}</ax-text>\n        </ax-breadcrumbs-item>\n      }\n    </ax-breadcrumbs>\n  </ax-prefix>\n\n  <ax-suffix>\n    <ax-menu openOn=\"click\" [hasArrow]=\"false\">\n      <ax-menu-item>\n        <ax-text>View</ax-text>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-large-icon')\">\n          <ax-text>Large</ax-text>\n        </ax-menu-item>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-small-icon')\">\n          <ax-text>Small</ax-text>\n        </ax-menu-item>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-list-icon')\">\n          <ax-text>List</ax-text>\n        </ax-menu-item>\n      </ax-menu-item>\n    </ax-menu>\n\n    <ax-divider></ax-divider>\n\n    <ax-menu openOn=\"click\" [hasArrow]=\"false\">\n      <ax-menu-item>\n        <ax-prefix>\n          <ax-icon class=\"ax-icon ax-icon-sort\"></ax-icon>\n        </ax-prefix>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('name')\"> <ax-text>Name</ax-text> </ax-menu-item>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('date')\"> <ax-text>Date</ax-text> </ax-menu-item>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('type')\"> <ax-text>Type</ax-text> </ax-menu-item>\n      </ax-menu-item>\n    </ax-menu>\n  </ax-suffix>\n</ax-toolbar>\n", styles: ["ax-file-explorer-header ax-toolbar{border-bottom:1px solid rgb(var(--ax-sys-color-border-lightest-surface));width:100%;justify-content:space-between}ax-file-explorer-header ax-toolbar ax-menu.ax-action-list-horizontal{min-width:fit-content}ax-file-explorer-header ax-toolbar ax-prefix{flex-wrap:nowrap}ax-file-explorer-header ax-toolbar .ax-start-toolbar-divider{display:none}\n"], dependencies: [{ kind: "component", type: AXToolBarComponent, selector: "ax-toolbar" }, { kind: "component", type: 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: "component", type: 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: "component", type: AXDecoratorIconComponent, selector: "ax-icon", inputs: ["icon"] }, { kind: "component", type: AXBreadCrumbsComponent, selector: "ax-breadcrumbs" }, { kind: "component", type: AXBreadCrumbsItemComponent, selector: "ax-breadcrumbs-item", inputs: ["disabled", "active"] }, { kind: "component", type: AXMenuComponent, selector: "ax-menu", inputs: ["orientation", "openOn", "closeOn", "items", "hasArrow"], outputs: ["onItemClick"] }, { kind: "component", type: AXMenuItemComponent, selector: "ax-menu-item", inputs: ["name", "data", "disabled", "color"], outputs: ["onClick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerHeaderComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-file-explorer-header', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [
                        AXToolBarComponent,
                        AXDecoratorGenericComponent,
                        AXButtonComponent,
                        AXDecoratorIconComponent,
                        AXBreadCrumbsComponent,
                        AXBreadCrumbsItemComponent,
                        AXMenuComponent,
                        AXMenuItemComponent,
                    ], providers: [{ provide: AXComponent, useExisting: AXFileExplorerHeaderComponent }], template: "<ax-toolbar>\n  <ax-prefix>\n    <ax-button (onClick)=\"service.menuToggleHandler()\" look=\"blank\">\n      <ax-icon class=\"ax-icon ax-icon-menu\"></ax-icon>\n    </ax-button>\n\n    <ax-divider></ax-divider>\n\n    <ax-button (onClick)=\"service.backButtonHandler()\" look=\"blank\">\n      <ax-icon class=\"ax-icon ax-icon-up-folder\"></ax-icon>\n    </ax-button>\n\n    <ax-divider></ax-divider>\n\n    <ax-breadcrumbs>\n      @if (false) {\n        <ng-template #divider> '|' </ng-template>\n      }\n      @for (item of internalService.breadcrumbsData(); track item; let idx = $last) {\n        <ax-breadcrumbs-item [active]=\"idx\">\n          <ax-text>{{ item }}</ax-text>\n        </ax-breadcrumbs-item>\n      }\n    </ax-breadcrumbs>\n  </ax-prefix>\n\n  <ax-suffix>\n    <ax-menu openOn=\"click\" [hasArrow]=\"false\">\n      <ax-menu-item>\n        <ax-text>View</ax-text>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-large-icon')\">\n          <ax-text>Large</ax-text>\n        </ax-menu-item>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-small-icon')\">\n          <ax-text>Small</ax-text>\n        </ax-menu-item>\n\n        <ax-menu-item (onClick)=\"service.changeViewHandler('ax-list-icon')\">\n          <ax-text>List</ax-text>\n        </ax-menu-item>\n      </ax-menu-item>\n    </ax-menu>\n\n    <ax-divider></ax-divider>\n\n    <ax-menu openOn=\"click\" [hasArrow]=\"false\">\n      <ax-menu-item>\n        <ax-prefix>\n          <ax-icon class=\"ax-icon ax-icon-sort\"></ax-icon>\n        </ax-prefix>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('name')\"> <ax-text>Name</ax-text> </ax-menu-item>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('date')\"> <ax-text>Date</ax-text> </ax-menu-item>\n        <ax-menu-item (onClick)=\"service.sortItemHandler('type')\"> <ax-text>Type</ax-text> </ax-menu-item>\n      </ax-menu-item>\n    </ax-menu>\n  </ax-suffix>\n</ax-toolbar>\n", styles: ["ax-file-explorer-header ax-toolbar{border-bottom:1px solid rgb(var(--ax-sys-color-border-lightest-surface));width:100%;justify-content:space-between}ax-file-explorer-header ax-toolbar ax-menu.ax-action-list-horizontal{min-width:fit-content}ax-file-explorer-header ax-toolbar ax-prefix{flex-wrap:nowrap}ax-file-explorer-header ax-toolbar .ax-start-toolbar-divider{display:none}\n"] }]
        }] });

class AXFileExplorerItemComponent extends MXBaseComponent {
    constructor() {
        super(...arguments);
        this.data = input(...(ngDevMode ? [undefined, { debugName: "data" }] : []));
        this.dbClick = output();
        this.viewMode = input(...(ngDevMode ? [undefined, { debugName: "viewMode" }] : []));
    }
    dbClickHandler() {
        this.dbClick.emit();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerItemComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXFileExplorerItemComponent, isStandalone: true, selector: "ax-file-explorer-item", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, viewMode: { classPropertyName: "viewMode", publicName: "viewMode", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dbClick: "dbClick" }, providers: [{ provide: AXComponent, useExisting: AXFileExplorerItemComponent }], usesInheritance: true, ngImport: i0, template: "@if (viewMode() === 'ax-list-icon') {\n  <div class=\"ax-list-icon\" (dblclick)=\"dbClickHandler()\">\n    <div class=\"ax-thumb-file\">\n      <ax-icon [icon]=\"data().icon\"></ax-icon>\n      <ax-text>{{ data().text }}</ax-text>\n    </div>\n\n    @if (data().extension) {\n      <ax-text>\n        {{ data().size }}\n      </ax-text>\n    }\n\n    <ax-text>\n      {{ data().description }}\n    </ax-text>\n\n    <ax-text>\n      {{ data().lastModify }}\n    </ax-text>\n  </div>\n} @else {\n  <div [ngClass]=\"viewMode()\" (dblclick)=\"dbClickHandler()\">\n    <ax-icon [icon]=\"data().icon\"></ax-icon>\n    <ax-text>{{ data().text }}</ax-text>\n  </div>\n}\n", styles: ["ax-file-explorer-item{-webkit-user-select:none;user-select:none;cursor:pointer}ax-file-explorer-item .ax-large-icon,ax-file-explorer-item .ax-small-icon{display:flex;flex-direction:column;justify-content:center;align-items:center}ax-file-explorer-item .ax-small-icon ax-icon{font-size:.9rem}ax-file-explorer-item .ax-small-icon ax-text{font-size:.7rem}ax-file-explorer-item .ax-large-icon ax-icon{font-size:3rem}ax-file-explorer-item .ax-large-icon ax-text{font-size:.8rem}ax-file-explorer-item .ax-list-icon{display:grid;grid-template-columns:repeat(auto-fit,minmax(100px,1fr));gap:.1rem;align-items:center;padding:.3rem;border-bottom:1px solid rgb(var(--ax-color-input-border));margin-bottom:.5rem}ax-file-explorer-item .ax-list-icon ax-icon{font-size:1.2rem;margin-inline-end:.5rem}ax-file-explorer-item .ax-list-icon ax-text{font-size:.8rem}ax-file-explorer-item .ax-list-icon .ax-thumb-file{display:flex}ax-file-explorer-item .ax-list-icon .ax-thumb-file ax-text{max-width:5rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}ax-file-explorer-item .ax-list-icon>ax-text{color:rgb(var(--ax-color-neutral-500));max-width:10rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:flex;justify-content:center}\n"], dependencies: [{ kind: "component", type: AXDecoratorIconComponent, selector: "ax-icon", inputs: ["icon"] }, { kind: "component", type: 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: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerItemComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-file-explorer-item', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [AXDecoratorIconComponent, AXDecoratorGenericComponent, NgClass], providers: [{ provide: AXComponent, useExisting: AXFileExplorerItemComponent }], template: "@if (viewMode() === 'ax-list-icon') {\n  <div class=\"ax-list-icon\" (dblclick)=\"dbClickHandler()\">\n    <div class=\"ax-thumb-file\">\n      <ax-icon [icon]=\"data().icon\"></ax-icon>\n      <ax-text>{{ data().text }}</ax-text>\n    </div>\n\n    @if (data().extension) {\n      <ax-text>\n        {{ data().size }}\n      </ax-text>\n    }\n\n    <ax-text>\n      {{ data().description }}\n    </ax-text>\n\n    <ax-text>\n      {{ data().lastModify }}\n    </ax-text>\n  </div>\n} @else {\n  <div [ngClass]=\"viewMode()\" (dblclick)=\"dbClickHandler()\">\n    <ax-icon [icon]=\"data().icon\"></ax-icon>\n    <ax-text>{{ data().text }}</ax-text>\n  </div>\n}\n", styles: ["ax-file-explorer-item{-webkit-user-select:none;user-select:none;cursor:pointer}ax-file-explorer-item .ax-large-icon,ax-file-explorer-item .ax-small-icon{display:flex;flex-direction:column;justify-content:center;align-items:center}ax-file-explorer-item .ax-small-icon ax-icon{font-size:.9rem}ax-file-explorer-item .ax-small-icon ax-text{font-size:.7rem}ax-file-explorer-item .ax-large-icon ax-icon{font-size:3rem}ax-file-explorer-item .ax-large-icon ax-text{font-size:.8rem}ax-file-explorer-item .ax-list-icon{display:grid;grid-template-columns:repeat(auto-fit,minmax(100px,1fr));gap:.1rem;align-items:center;padding:.3rem;border-bottom:1px solid rgb(var(--ax-color-input-border));margin-bottom:.5rem}ax-file-explorer-item .ax-list-icon ax-icon{font-size:1.2rem;margin-inline-end:.5rem}ax-file-explorer-item .ax-list-icon ax-text{font-size:.8rem}ax-file-explorer-item .ax-list-icon .ax-thumb-file{display:flex}ax-file-explorer-item .ax-list-icon .ax-thumb-file ax-text{max-width:5rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}ax-file-explorer-item .ax-list-icon>ax-text{color:rgb(var(--ax-color-neutral-500));max-width:10rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:flex;justify-content:center}\n"] }]
        }], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], dbClick: [{ type: i0.Output, args: ["dbClick"] }], viewMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewMode", required: false }] }] } });

class AXFileExplorerTreeComponent {
    constructor() {
        this.internalService = inject(AXFileExplorerInternalService);
        this.drawer = viewChild(AXDrawerComponent, ...(ngDevMode ? [{ debugName: "drawer" }] : []));
        this.treeView = viewChild(AXTreeViewComponent, ...(ngDevMode ? [{ debugName: "treeView" }] : []));
        this.#effect = effect(() => {
            if (this.internalService.treeViewState()) {
                this.drawer().open();
            }
            else {
                this.drawer().close();
            }
        }, ...(ngDevMode ? [{ debugName: "#effect" }] : []));
        this.#init = afterNextRender(() => {
            this.internalService.treeViewInstant.set(this.treeView());
        });
    }
    #effect;
    #init;
    openFolderOnViewHandler(e) {
        this.internalService.dbClickHandler(e.data, false);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerTreeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.9", type: AXFileExplorerTreeComponent, isStandalone: true, selector: "ax-file-explorer-tree", providers: [{ provide: AXComponent, useExisting: AXFileExplorerTreeComponent }], viewQueries: [{ propertyName: "drawer", first: true, predicate: AXDrawerComponent, descendants: true, isSignal: true }, { propertyName: "treeView", first: true, predicate: AXTreeViewComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<ax-drawer-container\n  [ngClass]=\"this.internalService.treeViewState() && 'ax-file-explore-drawer-border'\"\n  [ngStyle]=\"this.internalService.treeViewState() ? { width: 'fit-content' } : { width: 0 }\"\n>\n  <ax-drawer location=\"start\" mode=\"push\">\n    <ax-content>\n      <ax-tree-view\n        (onCollapsedChanged)=\"openFolderOnViewHandler($event)\"\n        [showCheckbox]=\"false\"\n        hasChildField=\"hasChild\"\n        [items]=\"internalService.dataCallBack()\"\n      ></ax-tree-view>\n    </ax-content>\n  </ax-drawer>\n</ax-drawer-container>\n", styles: ["ax-file-explorer-tree .ax-file-explore-drawer-border{border-inline-end:1px solid rgba(var(--ax-sys-color-border-lightest-surface))}ax-file-explorer-tree ax-drawer-container{height:auto}ax-file-explorer-tree ax-drawer-container ax-drawer ax-content{padding:.5rem;overflow-x:hidden}ax-file-explorer-tree ax-drawer-container ax-drawer ax-text{white-space:nowrap;padding-inline-end:1rem}\n"], dependencies: [{ kind: "component", type: AXDrawerContainerComponent, selector: "ax-drawer-container" }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: AXDrawerComponent, selector: "ax-drawer", inputs: ["location", "showBackdrop", "mode", "transition", "closeOnBackdropClick", "backdropClass", "collapsed", "singleOpenMode"], outputs: ["onBackdropClick", "collapsedStateChanged"] }, { kind: "component", type: 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: "component", type: AXTreeViewComponent, selector: "ax-tree-view", inputs: ["items", "showCheckbox", "hasCheckboxField", "selectionMode", "selectionBehavior", "selectionScope", "focusNodeEnabled", "valueField", "textField", "visibleField", "disableField", "hasChildField", "selectedField", "expandedField", "tooltipField", "childrenField", "activeField", "indeterminateField", "parentField", "iconField", "toggleIcons", "look", "showEmptyNodeMassage", "itemTemplate", "emptyTemplate", "expandOn"], outputs: ["onSelectionChanged", "onItemSelectedChanged", "onNodeClick", "onCollapsedChanged", "onNodedbClick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerTreeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-file-explorer-tree', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [
                        AXDrawerContainerComponent,
                        NgClass,
                        NgStyle,
                        AXDrawerComponent,
                        AXDecoratorGenericComponent,
                        AXTreeViewComponent,
                    ], providers: [{ provide: AXComponent, useExisting: AXFileExplorerTreeComponent }], template: "<ax-drawer-container\n  [ngClass]=\"this.internalService.treeViewState() && 'ax-file-explore-drawer-border'\"\n  [ngStyle]=\"this.internalService.treeViewState() ? { width: 'fit-content' } : { width: 0 }\"\n>\n  <ax-drawer location=\"start\" mode=\"push\">\n    <ax-content>\n      <ax-tree-view\n        (onCollapsedChanged)=\"openFolderOnViewHandler($event)\"\n        [showCheckbox]=\"false\"\n        hasChildField=\"hasChild\"\n        [items]=\"internalService.dataCallBack()\"\n      ></ax-tree-view>\n    </ax-content>\n  </ax-drawer>\n</ax-drawer-container>\n", styles: ["ax-file-explorer-tree .ax-file-explore-drawer-border{border-inline-end:1px solid rgba(var(--ax-sys-color-border-lightest-surface))}ax-file-explorer-tree ax-drawer-container{height:auto}ax-file-explorer-tree ax-drawer-container ax-drawer ax-content{padding:.5rem;overflow-x:hidden}ax-file-explorer-tree ax-drawer-container ax-drawer ax-text{white-space:nowrap;padding-inline-end:1rem}\n"] }]
        }], propDecorators: { drawer: [{ type: i0.ViewChild, args: [i0.forwardRef(() => AXDrawerComponent), { isSignal: true }] }], treeView: [{ type: i0.ViewChild, args: [i0.forwardRef(() => AXTreeViewComponent), { isSignal: true }] }] } });

class AXFileExplorerViewComponent {
    constructor() {
        this.dataCallBack = input.required(...(ngDevMode ? [{ debugName: "dataCallBack" }] : []));
        this.contextMenu = viewChild(AXContextMenuComponent, ...(ngDevMode ? [{ debugName: "contextMenu" }] : []));
        this.internalService = inject(AXFileExplorerInternalService);
        this.#init = effect(() => {
            this.setInitialAllData();
            this.internalService.dataCallBack.set(this.dataCallBack());
        }, ...(ngDevMode ? [{ debugName: "#init" }] : []));
        this.#effect2 = effect(() => {
            if (this.internalService.activeFolderId()) {
                const result = this.internalService.findItemInNestedArray(this.internalService.allData(), (item) => item.id === this.internalService.activeFolderId());
                this.internalService.showData.set(result.children);
            }
            else {
                this.internalService.showData.set(this.internalService.allData());
            }
            setTimeout(() => {
                this.contextMenu().refresh();
            });
        }, ...(ngDevMode ? [{ debugName: "#effect2" }] : []));
    }
    #init;
    #effect2;
    async setInitialAllData() {
        const rootData = await this.dataCallBack()();
        this.internalService.allData.set(rootData);
    }
    handleContextMenuOpening(e) {
        const target = e.targetElement['__axContext__'];
        const items = [{ text: 'open', data: target }, { text: 'delete', data: target }];
        e.items.push(...items);
        // if (items.length) {
        //   e.items.push(...items);
        // } else {
        //   e.canceled = true;
        // }
    }
    handleContextMenuItemClick(e) {
        this.internalService.dbClickHandler(e.item.data.data());
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXFileExplorerViewComponent, isStandalone: true, selector: "ax-file-explorer-view", inputs: { dataCallBack: { classPropertyName: "dataCallBack", publicName: "dataCallBack", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: AXComponent, useExisting: AXFileExplorerViewComponent }], viewQueries: [{ propertyName: "contextMenu", first: true, predicate: AXContextMenuComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<ng-content select=\"ax-file-explorer-header\"></ng-content>\n\n<div [ngClass]=\"internalService.viewMode()\" class=\"ax-file-container\">\n  @for (item of internalService.showData(); track item.id) {\n    <ax-file-explorer-item\n      id=\"ax-file-explore-item-ref\"\n      (dbClick)=\"internalService.dbClickHandler(item)\"\n      [data]=\"item\"\n      [viewMode]=\"internalService.viewMode()\"\n    ></ax-file-explorer-item>\n  }\n</div>\n<ax-context-menu\n  target=\"#ax-file-explore-item-ref\"\n  orientation=\"vertical\"\n  (onOpening)=\"handleContextMenuOpening($event)\"\n  (onItemClick)=\"handleContextMenuItemClick($event)\"\n>\n</ax-context-menu>\n", styles: ["ax-file-explorer-view{flex-grow:1;overflow:hidden}ax-file-explorer-view .ax-file-container.ax-large-icon,ax-file-explorer-view .ax-file-container.ax-small-icon{display:flex;flex-wrap:wrap;padding:.5rem;overflow:auto;gap:.6rem}ax-file-explorer-view .ax-file-container.ax-list-icon{overflow:auto;height:100%;padding:.5rem}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: AXFileExplorerItemComponent, selector: "ax-file-explorer-item", inputs: ["data", "viewMode"], outputs: ["dbClick"] }, { kind: "component", type: AXContextMenuComponent, selector: "ax-context-menu", inputs: ["orientation", "openOn", "closeOn", "items", "target"], outputs: ["onItemClick", "onOpening"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerViewComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-file-explorer-view', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgClass, AXFileExplorerItemComponent, AXContextMenuComponent], providers: [{ provide: AXComponent, useExisting: AXFileExplorerViewComponent }], template: "<ng-content select=\"ax-file-explorer-header\"></ng-content>\n\n<div [ngClass]=\"internalService.viewMode()\" class=\"ax-file-container\">\n  @for (item of internalService.showData(); track item.id) {\n    <ax-file-explorer-item\n      id=\"ax-file-explore-item-ref\"\n      (dbClick)=\"internalService.dbClickHandler(item)\"\n      [data]=\"item\"\n      [viewMode]=\"internalService.viewMode()\"\n    ></ax-file-explorer-item>\n  }\n</div>\n<ax-context-menu\n  target=\"#ax-file-explore-item-ref\"\n  orientation=\"vertical\"\n  (onOpening)=\"handleContextMenuOpening($event)\"\n  (onItemClick)=\"handleContextMenuItemClick($event)\"\n>\n</ax-context-menu>\n", styles: ["ax-file-explorer-view{flex-grow:1;overflow:hidden}ax-file-explorer-view .ax-file-container.ax-large-icon,ax-file-explorer-view .ax-file-container.ax-small-icon{display:flex;flex-wrap:wrap;padding:.5rem;overflow:auto;gap:.6rem}ax-file-explorer-view .ax-file-container.ax-list-icon{overflow:auto;height:100%;padding:.5rem}\n"] }]
        }], propDecorators: { dataCallBack: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataCallBack", required: true }] }], contextMenu: [{ type: i0.ViewChild, args: [i0.forwardRef(() => AXContextMenuComponent), { isSignal: true }] }] } });

const COMPONENT = [
    AXFileExplorerContainerComponent,
    AXFileExplorerViewComponent,
    AXFileExplorerItemComponent,
    AXFileExplorerHeaderComponent,
    AXFileExplorerTreeComponent,
];
const MODULES = [
    AXDecoratorModule,
    AXButtonModule,
    AXBreadcrumbsModule,
    CommonModule,
    AXToolBarModule,
    AXMenuModule,
    AXDrawerModule,
    AXTreeViewModule,
];
class AXFileExplorerModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerModule, imports: [AXDecoratorModule,
            AXButtonModule,
            AXBreadcrumbsModule,
            CommonModule,
            AXToolBarModule,
            AXMenuModule,
            AXDrawerModule,
            AXTreeViewModule, AXFileExplorerContainerComponent,
            AXFileExplorerViewComponent,
            AXFileExplorerItemComponent,
            AXFileExplorerHeaderComponent,
            AXFileExplorerTreeComponent], exports: [AXFileExplorerContainerComponent,
            AXFileExplorerViewComponent,
            AXFileExplorerItemComponent,
            AXFileExplorerHeaderComponent,
            AXFileExplorerTreeComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerModule, imports: [MODULES, AXFileExplorerViewComponent,
            AXFileExplorerItemComponent,
            AXFileExplorerHeaderComponent,
            AXFileExplorerTreeComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXFileExplorerModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [...MODULES, ...COMPONENT],
                    exports: [...COMPONENT],
                    providers: [],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { AXFileExplorerContainerComponent, AXFileExplorerHeaderComponent, AXFileExplorerItemComponent, AXFileExplorerModule, AXFileExplorerService, AXFileExplorerTreeComponent, AXFileExplorerViewComponent };
//# sourceMappingURL=acorex-components-file-explorer.mjs.map
