import { Component, ViewChild } from '@angular/core';
import { Metadata, RunView } from '@memberjunction/core';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-dialog";
import * as i2 from "@memberjunction/ng-shared";
import * as i3 from "@angular/common";
import * as i4 from "@angular/forms";
import * as i5 from "@progress/kendo-angular-grid";
import * as i6 from "@progress/kendo-angular-inputs";
import * as i7 from "@progress/kendo-angular-dropdowns";
import * as i8 from "@progress/kendo-angular-buttons";
const _c0 = ["grid"];
function AgentPermissionsDialogComponent_p_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p", 19);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(ctx_r1.agent.Description);
} }
function AgentPermissionsDialogComponent_div_14_div_14_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 22)(1, "label");
    i0.ɵɵtext(2, "User:");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "kendo-dropdownlist", 40);
    i0.ɵɵtwoWayListener("valueChange", function AgentPermissionsDialogComponent_div_14_div_14_Template_kendo_dropdownlist_valueChange_3_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(2); i0.ɵɵtwoWayBindingSet(ctx_r1.selectedUserId, $event) || (ctx_r1.selectedUserId = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("data", ctx_r1.users)("textField", "Name")("valueField", "ID");
    i0.ɵɵtwoWayProperty("value", ctx_r1.selectedUserId);
    i0.ɵɵproperty("filterable", true)("loading", ctx_r1.loadingUsers);
} }
function AgentPermissionsDialogComponent_div_14_div_15_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 22)(1, "label");
    i0.ɵɵtext(2, "Role:");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "kendo-dropdownlist", 41);
    i0.ɵɵtwoWayListener("valueChange", function AgentPermissionsDialogComponent_div_14_div_15_Template_kendo_dropdownlist_valueChange_3_listener($event) { i0.ɵɵrestoreView(_r5); const ctx_r1 = i0.ɵɵnextContext(2); i0.ɵɵtwoWayBindingSet(ctx_r1.selectedRoleId, $event) || (ctx_r1.selectedRoleId = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("data", ctx_r1.roles)("textField", "Name")("valueField", "ID");
    i0.ɵɵtwoWayProperty("value", ctx_r1.selectedRoleId);
    i0.ɵɵproperty("filterable", true)("loading", ctx_r1.loadingRoles);
} }
function AgentPermissionsDialogComponent_div_14_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 20)(1, "h4");
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "div", 21)(4, "div", 22)(5, "label");
    i0.ɵɵtext(6, "Grant To:");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "kendo-buttongroup", 23)(8, "button", 24);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_div_14_Template_button_click_8_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); ctx_r1.grantType = "user"; ctx_r1.selectedRoleId = null; return i0.ɵɵresetView(ctx_r1.selectedUserId = null); });
    i0.ɵɵelement(9, "i", 25);
    i0.ɵɵtext(10, " User ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(11, "button", 24);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_div_14_Template_button_click_11_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); ctx_r1.grantType = "role"; ctx_r1.selectedRoleId = null; return i0.ɵɵresetView(ctx_r1.selectedUserId = null); });
    i0.ɵɵelement(12, "i", 26);
    i0.ɵɵtext(13, " Role ");
    i0.ɵɵelementEnd()()();
    i0.ɵɵtemplate(14, AgentPermissionsDialogComponent_div_14_div_14_Template, 4, 6, "div", 27)(15, AgentPermissionsDialogComponent_div_14_div_15_Template, 4, 6, "div", 27);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(16, "div", 21)(17, "div", 28)(18, "label", 29)(19, "input", 30);
    i0.ɵɵtwoWayListener("ngModelChange", function AgentPermissionsDialogComponent_div_14_Template_input_ngModelChange_19_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵtwoWayBindingSet(ctx_r1.newPermission.CanView, $event) || (ctx_r1.newPermission.CanView = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(20, "span");
    i0.ɵɵelement(21, "i", 31);
    i0.ɵɵtext(22, " View ");
    i0.ɵɵelementStart(23, "small");
    i0.ɵɵtext(24, "See agent configuration");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(25, "label", 29)(26, "input", 32);
    i0.ɵɵtwoWayListener("ngModelChange", function AgentPermissionsDialogComponent_div_14_Template_input_ngModelChange_26_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵtwoWayBindingSet(ctx_r1.newPermission.CanRun, $event) || (ctx_r1.newPermission.CanRun = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵlistener("change", function AgentPermissionsDialogComponent_div_14_Template_input_change_26_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onPermissionChange("run")); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(27, "span");
    i0.ɵɵelement(28, "i", 33);
    i0.ɵɵtext(29, " Run ");
    i0.ɵɵelementStart(30, "small");
    i0.ɵɵtext(31, "Execute the agent");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(32, "label", 29)(33, "input", 32);
    i0.ɵɵtwoWayListener("ngModelChange", function AgentPermissionsDialogComponent_div_14_Template_input_ngModelChange_33_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵtwoWayBindingSet(ctx_r1.newPermission.CanEdit, $event) || (ctx_r1.newPermission.CanEdit = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵlistener("change", function AgentPermissionsDialogComponent_div_14_Template_input_change_33_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onPermissionChange("edit")); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(34, "span");
    i0.ɵɵelement(35, "i", 34);
    i0.ɵɵtext(36, " Edit ");
    i0.ɵɵelementStart(37, "small");
    i0.ɵɵtext(38, "Modify configuration");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(39, "label", 29)(40, "input", 35);
    i0.ɵɵtwoWayListener("ngModelChange", function AgentPermissionsDialogComponent_div_14_Template_input_ngModelChange_40_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵtwoWayBindingSet(ctx_r1.newPermission.CanDelete, $event) || (ctx_r1.newPermission.CanDelete = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵlistener("change", function AgentPermissionsDialogComponent_div_14_Template_input_change_40_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onPermissionChange("delete")); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(41, "span");
    i0.ɵɵelement(42, "i", 36);
    i0.ɵɵtext(43, " Delete ");
    i0.ɵɵelementStart(44, "small");
    i0.ɵɵtext(45, "Remove the agent");
    i0.ɵɵelementEnd()()()()();
    i0.ɵɵelementStart(46, "div", 21)(47, "div", 37)(48, "label");
    i0.ɵɵtext(49, "Comments (optional):");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(50, "textarea", 38);
    i0.ɵɵtwoWayListener("ngModelChange", function AgentPermissionsDialogComponent_div_14_Template_textarea_ngModelChange_50_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵtwoWayBindingSet(ctx_r1.newPermission.Comments, $event) || (ctx_r1.newPermission.Comments = $event); return i0.ɵɵresetView($event); });
    i0.ɵɵtext(51, "                            ");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(52, "div", 39)(53, "button", 18);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_div_14_Template_button_click_53_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.cancelEdit()); });
    i0.ɵɵtext(54, "Cancel");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(55, "button", 8);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_div_14_Template_button_click_55_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.savePermission()); });
    i0.ɵɵtext(56);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.editingPermission ? "Edit Permission" : "Add New Permission");
    i0.ɵɵadvance(5);
    i0.ɵɵproperty("selection", "single");
    i0.ɵɵadvance();
    i0.ɵɵproperty("toggleable", true)("selected", ctx_r1.grantType === "user");
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("toggleable", true)("selected", ctx_r1.grantType === "role");
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("ngIf", ctx_r1.grantType === "user");
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.grantType === "role");
    i0.ɵɵadvance(4);
    i0.ɵɵtwoWayProperty("ngModel", ctx_r1.newPermission.CanView);
    i0.ɵɵproperty("disabled", ctx_r1.newPermission.CanRun || ctx_r1.newPermission.CanEdit || ctx_r1.newPermission.CanDelete);
    i0.ɵɵadvance(7);
    i0.ɵɵtwoWayProperty("ngModel", ctx_r1.newPermission.CanRun);
    i0.ɵɵproperty("disabled", ctx_r1.newPermission.CanEdit || ctx_r1.newPermission.CanDelete);
    i0.ɵɵadvance(7);
    i0.ɵɵtwoWayProperty("ngModel", ctx_r1.newPermission.CanEdit);
    i0.ɵɵproperty("disabled", ctx_r1.newPermission.CanDelete);
    i0.ɵɵadvance(7);
    i0.ɵɵtwoWayProperty("ngModel", ctx_r1.newPermission.CanDelete);
    i0.ɵɵadvance(10);
    i0.ɵɵtwoWayProperty("ngModel", ctx_r1.newPermission.Comments);
    i0.ɵɵadvance(5);
    i0.ɵɵproperty("disabled", !ctx_r1.canSavePermission());
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", ctx_r1.editingPermission ? "Update" : "Add", " ");
} }
function AgentPermissionsDialogComponent_ng_template_18_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 42);
    i0.ɵɵelement(1, "i", 43);
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const dataItem_r6 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵclassProp("fa-user", dataItem_r6.UserID)("fa-users", dataItem_r6.RoleID);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(dataItem_r6.GrantedToName);
} }
function AgentPermissionsDialogComponent_ng_template_20_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 44);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dataItem_r7 = ctx.$implicit;
    i0.ɵɵclassProp("user", dataItem_r7.UserID)("role", dataItem_r7.RoleID);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", dataItem_r7.UserID ? "User" : "Role", " ");
} }
function AgentPermissionsDialogComponent_ng_template_22_span_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 50);
    i0.ɵɵelement(1, "i", 31);
    i0.ɵɵtext(2, " View ");
    i0.ɵɵelementEnd();
} }
function AgentPermissionsDialogComponent_ng_template_22_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 51);
    i0.ɵɵelement(1, "i", 33);
    i0.ɵɵtext(2, " Run ");
    i0.ɵɵelementEnd();
} }
function AgentPermissionsDialogComponent_ng_template_22_span_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 52);
    i0.ɵɵelement(1, "i", 34);
    i0.ɵɵtext(2, " Edit ");
    i0.ɵɵelementEnd();
} }
function AgentPermissionsDialogComponent_ng_template_22_span_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 53);
    i0.ɵɵelement(1, "i", 36);
    i0.ɵɵtext(2, " Delete ");
    i0.ɵɵelementEnd();
} }
function AgentPermissionsDialogComponent_ng_template_22_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 45);
    i0.ɵɵtemplate(1, AgentPermissionsDialogComponent_ng_template_22_span_1_Template, 3, 0, "span", 46)(2, AgentPermissionsDialogComponent_ng_template_22_span_2_Template, 3, 0, "span", 47)(3, AgentPermissionsDialogComponent_ng_template_22_span_3_Template, 3, 0, "span", 48)(4, AgentPermissionsDialogComponent_ng_template_22_span_4_Template, 3, 0, "span", 49);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dataItem_r8 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", dataItem_r8.EffectiveCanView);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", dataItem_r8.EffectiveCanRun);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", dataItem_r8.EffectiveCanEdit);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", dataItem_r8.EffectiveCanDelete);
} }
function AgentPermissionsDialogComponent_ng_template_24_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 54);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dataItem_r9 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(dataItem_r9.Comments || "-");
} }
function AgentPermissionsDialogComponent_ng_template_26_Template(rf, ctx) { if (rf & 1) {
    const _r10 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 55)(1, "button", 56);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_ng_template_26_Template_button_click_1_listener() { const dataItem_r11 = i0.ɵɵrestoreView(_r10).$implicit; const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.editPermission(dataItem_r11)); });
    i0.ɵɵelement(2, "i", 34);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "button", 57);
    i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_ng_template_26_Template_button_click_3_listener() { const dataItem_r11 = i0.ɵɵrestoreView(_r10).$implicit; const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.deletePermission(dataItem_r11)); });
    i0.ɵɵelement(4, "i", 36);
    i0.ɵɵelementEnd()();
} }
/**
 * Dialog component for managing AI Agent permissions.
 * Allows viewing, adding, editing, and removing permission records for an agent.
 */
export class AgentPermissionsDialogComponent {
    get dialogTitle() {
        return `Manage Permissions: ${this.agent?.Name || 'Agent'}`;
    }
    constructor(dialogRef, sharedService) {
        this.dialogRef = dialogRef;
        this.sharedService = sharedService;
        this.permissions = [];
        this.users = [];
        this.roles = [];
        this.gridData = { data: [], total: 0 };
        this.pageSize = 10;
        this.skip = 0;
        this.loading = false;
        this.loadingUsers = false;
        this.loadingRoles = false;
        this.isAddingPermission = false;
        this.editingPermission = null;
        this.grantType = 'user';
        this.selectedUserId = null;
        this.selectedRoleId = null;
        this.ownerName = null;
        this.newPermission = {
            CanView: false,
            CanRun: false,
            CanEdit: false,
            CanDelete: false,
            Comments: ''
        };
    }
    async ngOnInit() {
        await this.loadData();
    }
    async loadData() {
        this.loading = true;
        try {
            await Promise.all([
                this.loadPermissions(),
                this.loadUsers(),
                this.loadRoles(),
                this.loadOwnerName()
            ]);
        }
        finally {
            this.loading = false;
        }
    }
    async loadPermissions() {
        const rv = new RunView();
        const result = await rv.RunView({
            EntityName: 'MJ: AI Agent Permissions',
            ExtraFilter: `AgentID='${this.agent.ID}'`,
            ResultType: 'entity_object'
        });
        if (result.Success && result.Results) {
            this.permissions = result.Results;
            this.updateGridData();
        }
    }
    async loadUsers() {
        this.loadingUsers = true;
        try {
            const rv = new RunView();
            const result = await rv.RunView({
                EntityName: 'Users',
                ExtraFilter: 'IsActive=1',
                OrderBy: 'Name',
                ResultType: 'entity_object'
            });
            if (result.Success && result.Results) {
                this.users = result.Results;
            }
        }
        finally {
            this.loadingUsers = false;
        }
    }
    async loadRoles() {
        this.loadingRoles = true;
        try {
            const md = new Metadata();
            this.roles = md.Roles;
        }
        finally {
            this.loadingRoles = false;
        }
    }
    async loadOwnerName() {
        if (!this.agent.OwnerUserID) {
            this.ownerName = 'Not Set';
            return;
        }
        const user = this.users.find(u => u.ID === this.agent.OwnerUserID);
        if (user) {
            this.ownerName = user.Name;
        }
        else {
            // User might not be in the active users list, load separately
            const md = new Metadata();
            const userEntity = await md.GetEntityObject('Users');
            const loaded = await userEntity.Load(this.agent.OwnerUserID);
            this.ownerName = loaded ? userEntity.Name : 'Unknown';
        }
    }
    updateGridData() {
        // Enrich permissions with display data
        const enrichedData = this.permissions.map(p => {
            const grantedToName = p.UserID
                ? this.users.find(u => u.ID === p.UserID)?.Name || 'Unknown User'
                : this.roles.find(r => r.ID === p.RoleID)?.Name || 'Unknown Role';
            // Calculate effective permissions with hierarchy
            const effectiveCanDelete = p.CanDelete;
            const effectiveCanEdit = p.CanDelete || p.CanEdit;
            const effectiveCanRun = p.CanDelete || p.CanEdit || p.CanRun;
            const effectiveCanView = p.CanDelete || p.CanEdit || p.CanRun || p.CanView;
            return {
                ...p.GetAll(),
                GrantedToName: grantedToName,
                EffectiveCanView: effectiveCanView,
                EffectiveCanRun: effectiveCanRun,
                EffectiveCanEdit: effectiveCanEdit,
                EffectiveCanDelete: effectiveCanDelete
            };
        });
        this.gridData = {
            data: enrichedData.slice(this.skip, this.skip + this.pageSize),
            total: enrichedData.length
        };
    }
    dataStateChange(state) {
        this.skip = state.skip;
        this.pageSize = state.take;
        this.updateGridData();
    }
    addPermission() {
        this.isAddingPermission = true;
        this.editingPermission = null;
        this.grantType = 'user';
        this.selectedUserId = null;
        this.selectedRoleId = null;
        this.newPermission = {
            CanView: false,
            CanRun: false,
            CanEdit: false,
            CanDelete: false,
            Comments: ''
        };
    }
    editPermission(permission) {
        this.editingPermission = this.permissions.find(p => p.ID === permission.ID) || null;
        if (!this.editingPermission)
            return;
        this.isAddingPermission = true;
        this.grantType = this.editingPermission.UserID ? 'user' : 'role';
        this.selectedUserId = this.editingPermission.UserID || null;
        this.selectedRoleId = this.editingPermission.RoleID || null;
        this.newPermission = {
            CanView: this.editingPermission.CanView || false,
            CanRun: this.editingPermission.CanRun || false,
            CanEdit: this.editingPermission.CanEdit || false,
            CanDelete: this.editingPermission.CanDelete || false,
            Comments: this.editingPermission.Comments || ''
        };
    }
    async deletePermission(permission) {
        if (!confirm('Are you sure you want to remove this permission?')) {
            return;
        }
        const entity = this.permissions.find(p => p.ID === permission.ID);
        if (!entity)
            return;
        const deleted = await entity.Delete();
        if (deleted) {
            await this.loadPermissions();
        }
    }
    cancelEdit() {
        this.isAddingPermission = false;
        this.editingPermission = null;
    }
    onPermissionChange(level) {
        // Apply hierarchical logic
        if (level === 'delete' && this.newPermission.CanDelete) {
            this.newPermission.CanEdit = true;
            this.newPermission.CanRun = true;
            this.newPermission.CanView = true;
        }
        else if (level === 'edit' && this.newPermission.CanEdit) {
            this.newPermission.CanRun = true;
            this.newPermission.CanView = true;
        }
        else if (level === 'run' && this.newPermission.CanRun) {
            this.newPermission.CanView = true;
        }
    }
    canSavePermission() {
        // Must have selected user or role
        if (this.grantType === 'user' && !this.selectedUserId)
            return false;
        if (this.grantType === 'role' && !this.selectedRoleId)
            return false;
        // Must have at least one permission checked
        return this.newPermission.CanView || this.newPermission.CanRun ||
            this.newPermission.CanEdit || this.newPermission.CanDelete;
    }
    async savePermission() {
        if (!this.canSavePermission())
            return;
        try {
            const md = new Metadata();
            const entity = this.editingPermission ||
                await md.GetEntityObject('MJ: AI Agent Permissions');
            entity.AgentID = this.agent.ID;
            entity.UserID = this.grantType === 'user' ? this.selectedUserId : null;
            entity.RoleID = this.grantType === 'role' ? this.selectedRoleId : null;
            entity.CanView = this.newPermission.CanView;
            entity.CanRun = this.newPermission.CanRun;
            entity.CanEdit = this.newPermission.CanEdit;
            entity.CanDelete = this.newPermission.CanDelete;
            entity.Comments = this.newPermission.Comments || null;
            const saved = await entity.Save();
            if (saved) {
                this.isAddingPermission = false;
                this.editingPermission = null;
                await this.loadPermissions();
            }
            else {
                console.error('Failed to save permission');
                alert('Failed to save permission. Please try again.');
            }
        }
        catch (error) {
            console.error('Error saving permission:', error);
            alert('Error saving permission: ' + error.message);
        }
    }
    onCancel() {
        this.dialogRef.close();
    }
    static { this.ɵfac = function AgentPermissionsDialogComponent_Factory(t) { return new (t || AgentPermissionsDialogComponent)(i0.ɵɵdirectiveInject(i1.DialogRef), i0.ɵɵdirectiveInject(i2.SharedService)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AgentPermissionsDialogComponent, selectors: [["mj-agent-permissions-dialog"]], viewQuery: function AgentPermissionsDialogComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.grid = _t.first);
        } }, decls: 30, vars: 21, consts: [["grid", ""], [3, "close", "title", "width", "height"], [1, "permissions-dialog-content"], [1, "dialog-header"], [1, "agent-info"], ["class", "agent-description", 4, "ngIf"], [1, "owner-info"], [1, "fas", "fa-crown"], ["kendoButton", "", "themeColor", "primary", 3, "click", "disabled"], [1, "fas", "fa-plus"], ["class", "permission-form", 4, "ngIf"], [3, "dataStateChange", "data", "pageSize", "skip", "pageable", "sortable", "filterable", "loading", "height"], ["field", "GrantedTo", "title", "Granted To", 3, "width"], ["kendoGridCellTemplate", ""], ["field", "Type", "title", "Type", 3, "width"], ["title", "Permissions", 3, "width"], ["field", "Comments", "title", "Comments", 3, "width"], ["title", "Actions", 3, "width"], ["kendoButton", "", 3, "click"], [1, "agent-description"], [1, "permission-form"], [1, "form-row"], [1, "form-field"], [3, "selection"], ["kendoButton", "", 3, "click", "toggleable", "selected"], [1, "fas", "fa-user"], [1, "fas", "fa-users"], ["class", "form-field", 4, "ngIf"], [1, "permissions-checkboxes"], [1, "permission-checkbox"], ["type", "checkbox", 3, "ngModelChange", "ngModel", "disabled"], [1, "fas", "fa-eye"], ["type", "checkbox", 3, "ngModelChange", "change", "ngModel", "disabled"], [1, "fas", "fa-play"], [1, "fas", "fa-edit"], ["type", "checkbox", 3, "ngModelChange", "change", "ngModel"], [1, "fas", "fa-trash"], [1, "form-field", "full-width"], ["kendoTextArea", "", "placeholder", "Why is this permission being granted?", "rows", "2", 3, "ngModelChange", "ngModel"], [1, "form-actions"], ["placeholder", "Select a user...", 3, "valueChange", "data", "textField", "valueField", "value", "filterable", "loading"], ["placeholder", "Select a role...", 3, "valueChange", "data", "textField", "valueField", "value", "filterable", "loading"], [1, "granted-to-cell"], [1, "fas"], [1, "type-badge"], [1, "permission-badges"], ["class", "permission-badge view", 4, "ngIf"], ["class", "permission-badge run", 4, "ngIf"], ["class", "permission-badge edit", 4, "ngIf"], ["class", "permission-badge delete", 4, "ngIf"], [1, "permission-badge", "view"], [1, "permission-badge", "run"], [1, "permission-badge", "edit"], [1, "permission-badge", "delete"], [1, "description-text"], [1, "grid-actions"], ["kendoButton", "", "fillMode", "flat", "size", "small", "title", "Edit", 3, "click"], ["kendoButton", "", "fillMode", "flat", "themeColor", "error", "size", "small", "title", "Delete", 3, "click"]], template: function AgentPermissionsDialogComponent_Template(rf, ctx) { if (rf & 1) {
            const _r1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelementStart(0, "kendo-dialog", 1);
            i0.ɵɵlistener("close", function AgentPermissionsDialogComponent_Template_kendo_dialog_close_0_listener() { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onCancel()); });
            i0.ɵɵelementStart(1, "div", 2)(2, "div", 3)(3, "div", 4)(4, "h3");
            i0.ɵɵtext(5);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(6, AgentPermissionsDialogComponent_p_6_Template, 2, 1, "p", 5);
            i0.ɵɵelementStart(7, "div", 6);
            i0.ɵɵelement(8, "i", 7);
            i0.ɵɵelementStart(9, "span");
            i0.ɵɵtext(10);
            i0.ɵɵelementEnd()()();
            i0.ɵɵelementStart(11, "button", 8);
            i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_Template_button_click_11_listener() { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.addPermission()); });
            i0.ɵɵelement(12, "i", 9);
            i0.ɵɵtext(13, " Add Permission ");
            i0.ɵɵelementEnd()();
            i0.ɵɵtemplate(14, AgentPermissionsDialogComponent_div_14_Template, 57, 18, "div", 10);
            i0.ɵɵelementStart(15, "kendo-grid", 11, 0);
            i0.ɵɵlistener("dataStateChange", function AgentPermissionsDialogComponent_Template_kendo_grid_dataStateChange_15_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.dataStateChange($event)); });
            i0.ɵɵelementStart(17, "kendo-grid-column", 12);
            i0.ɵɵtemplate(18, AgentPermissionsDialogComponent_ng_template_18_Template, 4, 5, "ng-template", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(19, "kendo-grid-column", 14);
            i0.ɵɵtemplate(20, AgentPermissionsDialogComponent_ng_template_20_Template, 2, 5, "ng-template", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(21, "kendo-grid-column", 15);
            i0.ɵɵtemplate(22, AgentPermissionsDialogComponent_ng_template_22_Template, 5, 4, "ng-template", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(23, "kendo-grid-column", 16);
            i0.ɵɵtemplate(24, AgentPermissionsDialogComponent_ng_template_24_Template, 2, 1, "ng-template", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(25, "kendo-grid-column", 17);
            i0.ɵɵtemplate(26, AgentPermissionsDialogComponent_ng_template_26_Template, 5, 0, "ng-template", 13);
            i0.ɵɵelementEnd()()();
            i0.ɵɵelementStart(27, "kendo-dialog-actions")(28, "button", 18);
            i0.ɵɵlistener("click", function AgentPermissionsDialogComponent_Template_button_click_28_listener() { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onCancel()); });
            i0.ɵɵtext(29, "Close");
            i0.ɵɵelementEnd()()();
        } if (rf & 2) {
            i0.ɵɵproperty("title", ctx.dialogTitle)("width", 900)("height", 600);
            i0.ɵɵadvance(5);
            i0.ɵɵtextInterpolate(ctx.agent.Name);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.agent == null ? null : ctx.agent.Description);
            i0.ɵɵadvance(4);
            i0.ɵɵtextInterpolate1("Owner: ", ctx.ownerName || "Not Set", "");
            i0.ɵɵadvance();
            i0.ɵɵproperty("disabled", ctx.isAddingPermission);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngIf", ctx.isAddingPermission || ctx.editingPermission);
            i0.ɵɵadvance();
            i0.ɵɵproperty("data", ctx.gridData)("pageSize", ctx.pageSize)("skip", ctx.skip)("pageable", true)("sortable", true)("filterable", false)("loading", ctx.loading)("height", 400);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("width", 200);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("width", 80);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("width", 300);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("width", 150);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("width", 100);
        } }, dependencies: [i3.NgIf, i4.DefaultValueAccessor, i4.CheckboxControlValueAccessor, i4.NgControlStatus, i4.NgModel, i1.DialogComponent, i1.DialogActionsComponent, i5.GridComponent, i5.ColumnComponent, i5.CellTemplateDirective, i6.TextAreaDirective, i7.DropDownListComponent, i8.ButtonGroupComponent, i8.ButtonComponent], styles: [".permissions-dialog-content[_ngcontent-%COMP%] {\n            display: flex;\n            flex-direction: column;\n            gap: 20px;\n            padding: 20px;\n        }\n\n        .dialog-header[_ngcontent-%COMP%] {\n            display: flex;\n            justify-content: space-between;\n            align-items: flex-start;\n            padding-bottom: 15px;\n            border-bottom: 1px solid #e0e0e0;\n        }\n\n        .agent-info[_ngcontent-%COMP%]   h3[_ngcontent-%COMP%] {\n            margin: 0 0 8px 0;\n            color: #333;\n        }\n\n        .agent-description[_ngcontent-%COMP%] {\n            margin: 0 0 8px 0;\n            color: #666;\n            font-size: 13px;\n        }\n\n        .owner-info[_ngcontent-%COMP%] {\n            display: flex;\n            align-items: center;\n            gap: 6px;\n            color: #666;\n            font-size: 12px;\n        }\n\n        .owner-info[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n            color: #fbbf24;\n        }\n\n        .permission-form[_ngcontent-%COMP%] {\n            background: #f9fafb;\n            padding: 16px;\n            border-radius: 6px;\n            border: 1px solid #e0e0e0;\n        }\n\n        .permission-form[_ngcontent-%COMP%]   h4[_ngcontent-%COMP%] {\n            margin: 0 0 16px 0;\n            color: #333;\n        }\n\n        .form-row[_ngcontent-%COMP%] {\n            display: flex;\n            gap: 16px;\n            margin-bottom: 16px;\n        }\n\n        .form-field[_ngcontent-%COMP%] {\n            flex: 1;\n            display: flex;\n            flex-direction: column;\n            gap: 6px;\n        }\n\n        .form-field.full-width[_ngcontent-%COMP%] {\n            flex: 1 1 100%;\n        }\n\n        .form-field[_ngcontent-%COMP%]   label[_ngcontent-%COMP%] {\n            font-weight: 500;\n            font-size: 13px;\n            color: #555;\n        }\n\n        .permissions-checkboxes[_ngcontent-%COMP%] {\n            display: grid;\n            grid-template-columns: repeat(2, 1fr);\n            gap: 12px;\n            width: 100%;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%] {\n            display: flex;\n            align-items: flex-start;\n            gap: 8px;\n            cursor: pointer;\n            padding: 8px;\n            border-radius: 4px;\n            border: 1px solid #e0e0e0;\n            background: white;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%]:hover {\n            background: #f5f5f5;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%]   input[type=\"checkbox\"][_ngcontent-%COMP%] {\n            margin-top: 2px;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%]   span[_ngcontent-%COMP%] {\n            display: flex;\n            flex-direction: column;\n            gap: 2px;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%]   span[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n            margin-right: 4px;\n        }\n\n        .permission-checkbox[_ngcontent-%COMP%]   small[_ngcontent-%COMP%] {\n            color: #999;\n            font-size: 11px;\n        }\n\n        .form-actions[_ngcontent-%COMP%] {\n            display: flex;\n            justify-content: flex-end;\n            gap: 8px;\n            margin-top: 8px;\n        }\n\n        .granted-to-cell[_ngcontent-%COMP%] {\n            display: flex;\n            align-items: center;\n            gap: 8px;\n        }\n\n        .type-badge[_ngcontent-%COMP%] {\n            display: inline-block;\n            padding: 2px 8px;\n            border-radius: 4px;\n            font-size: 11px;\n            font-weight: 500;\n            text-transform: uppercase;\n        }\n\n        .type-badge.user[_ngcontent-%COMP%] {\n            background: #dbeafe;\n            color: #1e40af;\n        }\n\n        .type-badge.role[_ngcontent-%COMP%] {\n            background: #f3e8ff;\n            color: #6b21a8;\n        }\n\n        .permission-badges[_ngcontent-%COMP%] {\n            display: flex;\n            flex-wrap: wrap;\n            gap: 4px;\n        }\n\n        .permission-badge[_ngcontent-%COMP%] {\n            display: inline-flex;\n            align-items: center;\n            gap: 4px;\n            padding: 2px 6px;\n            border-radius: 3px;\n            font-size: 11px;\n            font-weight: 500;\n        }\n\n        .permission-badge.view[_ngcontent-%COMP%] {\n            background: #e0f2fe;\n            color: #0369a1;\n        }\n\n        .permission-badge.run[_ngcontent-%COMP%] {\n            background: #d1fae5;\n            color: #065f46;\n        }\n\n        .permission-badge.edit[_ngcontent-%COMP%] {\n            background: #fef3c7;\n            color: #92400e;\n        }\n\n        .permission-badge.delete[_ngcontent-%COMP%] {\n            background: #fee2e2;\n            color: #991b1b;\n        }\n\n        .description-text[_ngcontent-%COMP%] {\n            font-size: 12px;\n            color: #666;\n        }\n\n        .grid-actions[_ngcontent-%COMP%] {\n            display: flex;\n            gap: 4px;\n        }"] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AgentPermissionsDialogComponent, [{
        type: Component,
        args: [{ selector: 'mj-agent-permissions-dialog', template: `
        <kendo-dialog
            [title]="dialogTitle"
            [width]="900"
            [height]="600"
            (close)="onCancel()">

            <div class="permissions-dialog-content">
                <!-- Header with agent info and add button -->
                <div class="dialog-header">
                    <div class="agent-info">
                        <h3>{{ agent.Name }}</h3>
                        <p class="agent-description" *ngIf="agent?.Description">{{ agent.Description }}</p>
                        <div class="owner-info">
                            <i class="fas fa-crown"></i>
                            <span>Owner: {{ ownerName || 'Not Set' }}</span>
                        </div>
                    </div>
                    <button kendoButton
                            themeColor="primary"
                            [disabled]="isAddingPermission"
                            (click)="addPermission()">
                        <i class="fas fa-plus"></i> Add Permission
                    </button>
                </div>

                <!-- Add/Edit Permission Form -->
                <div class="permission-form" *ngIf="isAddingPermission || editingPermission">
                    <h4>{{ editingPermission ? 'Edit Permission' : 'Add New Permission' }}</h4>

                    <div class="form-row">
                        <div class="form-field">
                            <label>Grant To:</label>
                            <kendo-buttongroup [selection]="'single'">
                                <button kendoButton
                                        [toggleable]="true"
                                        [selected]="grantType === 'user'"
                                        (click)="grantType = 'user'; selectedRoleId = null; selectedUserId = null">
                                    <i class="fas fa-user"></i> User
                                </button>
                                <button kendoButton
                                        [toggleable]="true"
                                        [selected]="grantType === 'role'"
                                        (click)="grantType = 'role'; selectedRoleId = null; selectedUserId = null">
                                    <i class="fas fa-users"></i> Role
                                </button>
                            </kendo-buttongroup>
                        </div>

                        <div class="form-field" *ngIf="grantType === 'user'">
                            <label>User:</label>
                            <kendo-dropdownlist
                                [data]="users"
                                [textField]="'Name'"
                                [valueField]="'ID'"
                                [(value)]="selectedUserId"
                                [filterable]="true"
                                [loading]="loadingUsers"
                                placeholder="Select a user...">
                            </kendo-dropdownlist>
                        </div>

                        <div class="form-field" *ngIf="grantType === 'role'">
                            <label>Role:</label>
                            <kendo-dropdownlist
                                [data]="roles"
                                [textField]="'Name'"
                                [valueField]="'ID'"
                                [(value)]="selectedRoleId"
                                [filterable]="true"
                                [loading]="loadingRoles"
                                placeholder="Select a role...">
                            </kendo-dropdownlist>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="permissions-checkboxes">
                            <label class="permission-checkbox">
                                <input type="checkbox"
                                       [(ngModel)]="newPermission.CanView"
                                       [disabled]="newPermission.CanRun || newPermission.CanEdit || newPermission.CanDelete">
                                <span>
                                    <i class="fas fa-eye"></i> View
                                    <small>See agent configuration</small>
                                </span>
                            </label>

                            <label class="permission-checkbox">
                                <input type="checkbox"
                                       [(ngModel)]="newPermission.CanRun"
                                       (change)="onPermissionChange('run')"
                                       [disabled]="newPermission.CanEdit || newPermission.CanDelete">
                                <span>
                                    <i class="fas fa-play"></i> Run
                                    <small>Execute the agent</small>
                                </span>
                            </label>

                            <label class="permission-checkbox">
                                <input type="checkbox"
                                       [(ngModel)]="newPermission.CanEdit"
                                       (change)="onPermissionChange('edit')"
                                       [disabled]="newPermission.CanDelete">
                                <span>
                                    <i class="fas fa-edit"></i> Edit
                                    <small>Modify configuration</small>
                                </span>
                            </label>

                            <label class="permission-checkbox">
                                <input type="checkbox"
                                       [(ngModel)]="newPermission.CanDelete"
                                       (change)="onPermissionChange('delete')">
                                <span>
                                    <i class="fas fa-trash"></i> Delete
                                    <small>Remove the agent</small>
                                </span>
                            </label>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-field full-width">
                            <label>Comments (optional):</label>
                            <textarea kendoTextArea
                                      [(ngModel)]="newPermission.Comments"
                                      placeholder="Why is this permission being granted?"
                                      rows="2">
                            </textarea>
                        </div>
                    </div>

                    <div class="form-actions">
                        <button kendoButton (click)="cancelEdit()">Cancel</button>
                        <button kendoButton
                                themeColor="primary"
                                [disabled]="!canSavePermission()"
                                (click)="savePermission()">
                            {{ editingPermission ? 'Update' : 'Add' }}
                        </button>
                    </div>
                </div>

                <!-- Permissions Grid -->
                <kendo-grid
                    #grid
                    [data]="gridData"
                    [pageSize]="pageSize"
                    [skip]="skip"
                    [pageable]="true"
                    [sortable]="true"
                    [filterable]="false"
                    [loading]="loading"
                    (dataStateChange)="dataStateChange($event)"
                    [height]="400">

                    <kendo-grid-column field="GrantedTo" title="Granted To" [width]="200">
                        <ng-template kendoGridCellTemplate let-dataItem>
                            <div class="granted-to-cell">
                                <i class="fas" [class.fa-user]="dataItem.UserID" [class.fa-users]="dataItem.RoleID"></i>
                                <span>{{ dataItem.GrantedToName }}</span>
                            </div>
                        </ng-template>
                    </kendo-grid-column>

                    <kendo-grid-column field="Type" title="Type" [width]="80">
                        <ng-template kendoGridCellTemplate let-dataItem>
                            <span class="type-badge" [class.user]="dataItem.UserID" [class.role]="dataItem.RoleID">
                                {{ dataItem.UserID ? 'User' : 'Role' }}
                            </span>
                        </ng-template>
                    </kendo-grid-column>

                    <kendo-grid-column title="Permissions" [width]="300">
                        <ng-template kendoGridCellTemplate let-dataItem>
                            <div class="permission-badges">
                                <span class="permission-badge view" *ngIf="dataItem.EffectiveCanView">
                                    <i class="fas fa-eye"></i> View
                                </span>
                                <span class="permission-badge run" *ngIf="dataItem.EffectiveCanRun">
                                    <i class="fas fa-play"></i> Run
                                </span>
                                <span class="permission-badge edit" *ngIf="dataItem.EffectiveCanEdit">
                                    <i class="fas fa-edit"></i> Edit
                                </span>
                                <span class="permission-badge delete" *ngIf="dataItem.EffectiveCanDelete">
                                    <i class="fas fa-trash"></i> Delete
                                </span>
                            </div>
                        </ng-template>
                    </kendo-grid-column>

                    <kendo-grid-column field="Comments" title="Comments" [width]="150">
                        <ng-template kendoGridCellTemplate let-dataItem>
                            <span class="description-text">{{ dataItem.Comments || '-' }}</span>
                        </ng-template>
                    </kendo-grid-column>

                    <kendo-grid-column title="Actions" [width]="100">
                        <ng-template kendoGridCellTemplate let-dataItem>
                            <div class="grid-actions">
                                <button kendoButton
                                        fillMode="flat"
                                        size="small"
                                        title="Edit"
                                        (click)="editPermission(dataItem)">
                                    <i class="fas fa-edit"></i>
                                </button>
                                <button kendoButton
                                        fillMode="flat"
                                        themeColor="error"
                                        size="small"
                                        title="Delete"
                                        (click)="deletePermission(dataItem)">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </div>
                        </ng-template>
                    </kendo-grid-column>
                </kendo-grid>
            </div>

            <kendo-dialog-actions>
                <button kendoButton (click)="onCancel()">Close</button>
            </kendo-dialog-actions>
        </kendo-dialog>
    `, styles: ["\n        .permissions-dialog-content {\n            display: flex;\n            flex-direction: column;\n            gap: 20px;\n            padding: 20px;\n        }\n\n        .dialog-header {\n            display: flex;\n            justify-content: space-between;\n            align-items: flex-start;\n            padding-bottom: 15px;\n            border-bottom: 1px solid #e0e0e0;\n        }\n\n        .agent-info h3 {\n            margin: 0 0 8px 0;\n            color: #333;\n        }\n\n        .agent-description {\n            margin: 0 0 8px 0;\n            color: #666;\n            font-size: 13px;\n        }\n\n        .owner-info {\n            display: flex;\n            align-items: center;\n            gap: 6px;\n            color: #666;\n            font-size: 12px;\n        }\n\n        .owner-info i {\n            color: #fbbf24;\n        }\n\n        .permission-form {\n            background: #f9fafb;\n            padding: 16px;\n            border-radius: 6px;\n            border: 1px solid #e0e0e0;\n        }\n\n        .permission-form h4 {\n            margin: 0 0 16px 0;\n            color: #333;\n        }\n\n        .form-row {\n            display: flex;\n            gap: 16px;\n            margin-bottom: 16px;\n        }\n\n        .form-field {\n            flex: 1;\n            display: flex;\n            flex-direction: column;\n            gap: 6px;\n        }\n\n        .form-field.full-width {\n            flex: 1 1 100%;\n        }\n\n        .form-field label {\n            font-weight: 500;\n            font-size: 13px;\n            color: #555;\n        }\n\n        .permissions-checkboxes {\n            display: grid;\n            grid-template-columns: repeat(2, 1fr);\n            gap: 12px;\n            width: 100%;\n        }\n\n        .permission-checkbox {\n            display: flex;\n            align-items: flex-start;\n            gap: 8px;\n            cursor: pointer;\n            padding: 8px;\n            border-radius: 4px;\n            border: 1px solid #e0e0e0;\n            background: white;\n        }\n\n        .permission-checkbox:hover {\n            background: #f5f5f5;\n        }\n\n        .permission-checkbox input[type=\"checkbox\"] {\n            margin-top: 2px;\n        }\n\n        .permission-checkbox span {\n            display: flex;\n            flex-direction: column;\n            gap: 2px;\n        }\n\n        .permission-checkbox span i {\n            margin-right: 4px;\n        }\n\n        .permission-checkbox small {\n            color: #999;\n            font-size: 11px;\n        }\n\n        .form-actions {\n            display: flex;\n            justify-content: flex-end;\n            gap: 8px;\n            margin-top: 8px;\n        }\n\n        .granted-to-cell {\n            display: flex;\n            align-items: center;\n            gap: 8px;\n        }\n\n        .type-badge {\n            display: inline-block;\n            padding: 2px 8px;\n            border-radius: 4px;\n            font-size: 11px;\n            font-weight: 500;\n            text-transform: uppercase;\n        }\n\n        .type-badge.user {\n            background: #dbeafe;\n            color: #1e40af;\n        }\n\n        .type-badge.role {\n            background: #f3e8ff;\n            color: #6b21a8;\n        }\n\n        .permission-badges {\n            display: flex;\n            flex-wrap: wrap;\n            gap: 4px;\n        }\n\n        .permission-badge {\n            display: inline-flex;\n            align-items: center;\n            gap: 4px;\n            padding: 2px 6px;\n            border-radius: 3px;\n            font-size: 11px;\n            font-weight: 500;\n        }\n\n        .permission-badge.view {\n            background: #e0f2fe;\n            color: #0369a1;\n        }\n\n        .permission-badge.run {\n            background: #d1fae5;\n            color: #065f46;\n        }\n\n        .permission-badge.edit {\n            background: #fef3c7;\n            color: #92400e;\n        }\n\n        .permission-badge.delete {\n            background: #fee2e2;\n            color: #991b1b;\n        }\n\n        .description-text {\n            font-size: 12px;\n            color: #666;\n        }\n\n        .grid-actions {\n            display: flex;\n            gap: 4px;\n        }\n    "] }]
    }], () => [{ type: i1.DialogRef }, { type: i2.SharedService }], { grid: [{
            type: ViewChild,
            args: ['grid']
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(AgentPermissionsDialogComponent, { className: "AgentPermissionsDialogComponent", filePath: "src/lib/custom/AIAgents/agent-permissions-dialog.component.ts", lineNumber: 437 }); })();
//# sourceMappingURL=agent-permissions-dialog.component.js.map