import { AXPEntity } from '@acorex/platform/common';
import * as i0 from '@angular/core';
import { Injector, OnInit } from '@angular/core';
import { AXPEntityModel, AXMEntityCrudServiceImpl } from '@acorex/platform/layout/entity';
import { AXPExpression, AXPActionMenuItem, AXPExecuteCommand } from '@acorex/platform/core';
import * as i1 from '@acorex/platform/workflow';
import { AXPWorkflowService } from '@acorex/platform/workflow';
import * as i2 from '@acorex/platform/layout/widget-core';
import { AXPValueWidgetComponent, AXPColumnWidgetComponent, AXPLayoutBaseWidgetComponent, AXPWidgetConfig } from '@acorex/platform/layout/widget-core';
import { AXPPermissionGroupDefinition, AXPPermissionDefinition } from '@acorex/platform/auth';
import { AXValueChangedEvent } from '@acorex/cdk/common';
import { AXPPopupLayoutBaseComponent } from '@acorex/platform/layout/views';

declare const RootConfig: {
    config: {
        i18n: string;
        profileEntity: string;
    };
    module: {
        route: string;
        name: string;
        title: string;
        icon: string;
    };
    entities: {
        policy: {
            name: string;
            title: string;
            titlePlural: string;
            icon: string;
        };
        deviceSessions: {
            name: string;
            title: string;
            titlePlural: string;
            icon: string;
        };
        users: {
            name: string;
            title: string;
            titlePlural: string;
            icon: string;
        };
        roles: {
            name: string;
            title: string;
            titlePlural: string;
            icon: string;
        };
        profile: {
            name: string;
            title: string;
            titlePlural: string;
            icon: string;
        };
    };
};

declare function factory(injector: Injector): Promise<AXPEntity | null>;

declare class AXMSecurityManagementDeviceSessionsEntityModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementDeviceSessionsEntityModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMSecurityManagementDeviceSessionsEntityModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMSecurityManagementDeviceSessionsEntityModule>;
}

interface AXMSecurityManagementRolesEntityModel extends AXPEntityModel<string> {
    name: string;
    title: string;
    description?: string;
    permissions?: string[];
}

declare abstract class AXMSecurityManagementRolesEntityService extends AXMEntityCrudServiceImpl<string, AXMSecurityManagementRolesEntityModel> {
}
declare class AXMSecurityManagementRolesEntityServiceImpl extends AXMSecurityManagementRolesEntityService {
    constructor();
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementRolesEntityServiceImpl, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<AXMSecurityManagementRolesEntityServiceImpl>;
}

interface AXMSecurityManagementUsersEntityModel extends AXPEntityModel<string> {
    id: string;
    username: string;
    displayName: string;
    password: string;
}

declare abstract class AXMUsersEntityService extends AXMEntityCrudServiceImpl<string, AXMSecurityManagementUsersEntityModel> {
}
declare class AXMUsersEntityServiceImpl extends AXMUsersEntityService {
    constructor();
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMUsersEntityServiceImpl, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<AXMUsersEntityServiceImpl>;
}

declare function policyFactory(injector: Injector): Promise<AXPEntity | null>;

interface AXMSecurityManagementPolicyEntityModel extends AXPEntityModel<string> {
    name: string;
    title: string;
    description?: string;
    rules: {
        conditions: AXPExpression;
        effects: AXMPolicyEffectRule[];
    }[];
    permission: string;
    scope: AXMPolicyScope;
    resource: {
        type: string;
        target: string;
    };
}
type AXMPolicyScope = 'system' | 'tenant' | 'user';
type AXMPolicyEffect = 'editable' | 'readonly' | 'hidden' | 'immutable' | 'masked';
interface AXMPolicyEffectRule {
    effect: AXMPolicyEffect;
    target: string;
}

declare abstract class AXMPolicyService extends AXMEntityCrudServiceImpl<string, AXMSecurityManagementPolicyEntityModel> {
}
declare class AXMPolicyServiceImpl extends AXMPolicyService {
    constructor();
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMPolicyServiceImpl, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<AXMPolicyServiceImpl>;
}

declare const AXPSecurityManagementMenuKeys: {
    readonly Root: "security-management:menu";
    readonly Users: "security-management:menu:users";
    readonly Roles: "security-management:menu:roles";
    readonly DeviceSessions: "security-management:menu:device-sessions";
    readonly Policy: "security-management:menu:policy";
    readonly UserProfile: "user:profile";
    readonly MyProfile: "security-management:my-profile";
};

declare class AXMSecurityManagementProfileEntityModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementProfileEntityModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMSecurityManagementProfileEntityModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMSecurityManagementProfileEntityModule>;
}

declare class AXMSecurityManagementRolesEntityModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementRolesEntityModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMSecurityManagementRolesEntityModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMSecurityManagementRolesEntityModule>;
}

declare class AXMSecurityManagementUsersEntityModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementUsersEntityModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMSecurityManagementUsersEntityModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMSecurityManagementUsersEntityModule>;
}

declare class AXMPermissionsModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMPermissionsModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMPermissionsModule, never, [typeof i1.AXPWorkflowModule, typeof i2.AXPWidgetCoreModule], never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMPermissionsModule>;
}

declare class AXMSecurityManagementModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXMSecurityManagementModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<AXMSecurityManagementModule, never, [typeof AXMSecurityManagementDeviceSessionsEntityModule, typeof AXMSecurityManagementProfileEntityModule, typeof AXMSecurityManagementRolesEntityModule, typeof AXMSecurityManagementUsersEntityModule, typeof AXMPermissionsModule, typeof i1.AXPWorkflowModule], never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<AXMSecurityManagementModule>;
}

declare class AXPPermissionsEditorComponent implements OnInit {
    /** Service for fetching permission groups and definitions */
    private permissionService;
    /** Currently selected permission group */
    protected selectedGroup: i0.WritableSignal<AXPPermissionGroupDefinition | null>;
    /** All available permission groups */
    protected groups: i0.WritableSignal<AXPPermissionGroupDefinition[]>;
    /** Initial permissions to be selected - exposed as signal input */
    initialPermissions: i0.InputSignal<string[]>;
    /** Whether the editor is in read-only mode */
    readOnly: i0.InputSignal<boolean>;
    /** List of selected permission names */
    protected selectedPermissions: i0.WritableSignal<string[]>;
    /** Event emitted when permissions selection changes */
    permissionsChanged: i0.OutputEmitterRef<string[]>;
    /** Event emitted when permissions are applied/selected */
    permissionsSelected: i0.OutputEmitterRef<string[]>;
    /**
     * Recursively maps permissions to include selection state and children.
     */
    private mapPermissions;
    /**
     * Computed: Returns mapped permissions for the selected group.
     */
    protected items: i0.Signal<any[]>;
    /**
     * Computed: Returns groups with badge counts.
     */
    protected groupsWithBadge: i0.Signal<{
        badge: string;
        name: string;
        title: string;
        description?: string;
        permissions: AXPPermissionDefinition[];
    }[]>;
    /**
     * Recursively collects all permission names (parents and children) from an array.
     */
    private collectAllPermissionNames;
    /**
     * Returns the badge count for a group (all selected permissions, including parents).
     */
    private getBadge;
    /**
     * Checks if a permission is selected.
     */
    private isSelected;
    /**
     * Checks if a permission is selected.
     */
    protected badgeToNumber(value: unknown): number;
    /**
     * Recursively collects all descendant permission names for a single item (including itself).
     */
    private collectPermissionNames;
    /**
     * Gets the current selected permissions.
     */
    getSelectedPermissions(): string[];
    /**
     * Sets the selected permissions.
     */
    setSelectedPermissions(permissions: string[]): void;
    /**
     * Applies/selects the current permissions.
     */
    selectPermissions(): void;
    /**
     * Initializes the component and loads permission groups.
     */
    ngOnInit(): Promise<void>;
    /**
     * Handles group tab/menu item click.
     */
    protected handleMenuItemClick(item: AXPPermissionGroupDefinition): void;
    /**
     * Handles permission checkbox toggle (checks/unchecks all children recursively).
     */
    protected onPermissionToggle(item: any, e: AXValueChangedEvent): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsEditorComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsEditorComponent, "axm-permissions-editor", never, { "initialPermissions": { "alias": "initialPermissions"; "required": false; "isSignal": true; }; "readOnly": { "alias": "readOnly"; "required": false; "isSignal": true; }; }, { "permissionsChanged": "permissionsChanged"; "permissionsSelected": "permissionsSelected"; }, never, never, true, never>;
}

declare class AXPPermissionsEditorPopupComponent extends AXPPopupLayoutBaseComponent {
    /** Reference to the core permission editor component */
    permissionEditor: AXPPermissionsEditorComponent;
    /** Initial permissions to be selected */
    protected initialPermissions: string[];
    /**
     * Initializes the component.
     */
    ngOnInit(): Promise<void>;
    /**
     * Returns the primary menu items for the popup layout.
     */
    protected getPrimaryMenuItems(): AXPActionMenuItem[] | Promise<AXPActionMenuItem[]>;
    /**
     * Handles permission selection changes from the editor component.
     */
    protected onPermissionsChanged(permissions: string[]): void;
    /**
     * Handles when permissions are selected from the editor component.
     */
    protected onPermissionsSelected(permissions: string[]): void;
    /**
     * Executes popup commands.
     */
    execute(command: AXPExecuteCommand): void | Promise<void>;
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsEditorPopupComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsEditorPopupComponent, "axm-permissions-editor-popup", never, {}, {}, never, never, true, never>;
}

interface PermissionPath {
    group: AXPPermissionGroupDefinition;
    path: AXPPermissionDefinition[];
    displayPath: string;
}
declare class AXPPermissionsWidgetViewComponent extends AXPValueWidgetComponent<string[]> {
    private permissionService;
    private workflowService;
    protected groups: i0.WritableSignal<AXPPermissionGroupDefinition[]>;
    private loadGroupsEffect;
    protected selectedPermissionsByGroup: i0.Signal<Record<string, PermissionPath[]>>;
    protected isEmpty: i0.Signal<boolean>;
    protected openPermissionsEditor(): Promise<void>;
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsWidgetViewComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsWidgetViewComponent, "ng-component", never, {}, {}, never, never, true, never>;
}

declare class AXPPermissionsWidgetEditComponent extends AXPValueWidgetComponent<string[]> {
    /**
     * Handles permissions changes from the editor.
     */
    protected onPermissionsChanged(permissions: string[]): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsWidgetEditComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsWidgetEditComponent, "ng-component", never, {}, {}, never, never, true, never>;
}

declare class AXPPermissionsWidgetColumnComponent extends AXPColumnWidgetComponent<any> {
    protected count: i0.Signal<number>;
    protected workflowService: AXPWorkflowService;
    openPermissionsEditor(): Promise<void>;
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsWidgetColumnComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsWidgetColumnComponent, "ng-component", never, { "rawValue": { "alias": "rawValue"; "required": false; }; "rowData": { "alias": "rowData"; "required": false; }; }, {}, never, never, true, never>;
}

declare class AXPPermissionsWidgetPrintComponent extends AXPLayoutBaseWidgetComponent {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsWidgetPrintComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsWidgetPrintComponent, "ng-component", never, {}, {}, never, never, true, never>;
}

declare class AXPPermissionsWidgetDesignerComponent extends AXPLayoutBaseWidgetComponent {
    static ɵfac: i0.ɵɵFactoryDeclaration<AXPPermissionsWidgetDesignerComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<AXPPermissionsWidgetDesignerComponent, "ng-component", never, {}, {}, never, never, true, never>;
}

declare const AXPPermissionsWidget: AXPWidgetConfig;

export { AXMPermissionsModule, AXMPolicyService, AXMPolicyServiceImpl, AXMSecurityManagementDeviceSessionsEntityModule, AXMSecurityManagementModule, AXMSecurityManagementRolesEntityService, AXMSecurityManagementRolesEntityServiceImpl, AXMUsersEntityService, AXMUsersEntityServiceImpl, AXPPermissionsEditorComponent, AXPPermissionsEditorPopupComponent, AXPPermissionsWidget, AXPPermissionsWidgetColumnComponent, AXPPermissionsWidgetDesignerComponent, AXPPermissionsWidgetEditComponent, AXPPermissionsWidgetPrintComponent, AXPPermissionsWidgetViewComponent, AXPSecurityManagementMenuKeys, RootConfig, factory, policyFactory };
export type { AXMPolicyEffect, AXMPolicyEffectRule, AXMPolicyScope, AXMSecurityManagementPolicyEntityModel, AXMSecurityManagementRolesEntityModel, AXMSecurityManagementUsersEntityModel };
