import "./chunk-BFN3CBP7.js";
import "./chunk-GMPCSGFS.js";
import "./chunk-E6CBXFRG.js";
import {
  MenuMapService
} from "./chunk-3FLJCSSF.js";
import {
  ToastrService
} from "./chunk-2YLAF7RI.js";
import {
  CommonSharedModule,
  DynamicFontSizeDirective
} from "./chunk-7NQGM4EA.js";
import {
  CheckboxControlValueAccessor,
  DefaultValueAccessor,
  FormArray,
  FormArrayName,
  FormBuilder,
  FormControl,
  FormControlName,
  FormGroupDirective,
  FormGroupName,
  NgControlStatus,
  NgControlStatusGroup,
  NgSelectOption,
  RadioControlValueAccessor,
  ReactiveFormsModule,
  SelectControlValueAccessor,
  TranslatePipe,
  TranslateService,
  Validators,
  ɵNgNoValidate,
  ɵNgSelectMultipleOption
} from "./chunk-NLYGDKUR.js";
import "./chunk-ZEL7H2AL.js";
import {
  GridApiService,
  LocalStorageService
} from "./chunk-P7K2QEDI.js";
import {
  NgClass,
  NgForOf,
  NgIf,
  Title,
  ɵsetClassDebugInfo,
  ɵɵStandaloneFeature,
  ɵɵadvance,
  ɵɵdefineComponent,
  ɵɵdirectiveInject,
  ɵɵelement,
  ɵɵelementContainerEnd,
  ɵɵelementContainerStart,
  ɵɵelementEnd,
  ɵɵelementStart,
  ɵɵgetCurrentView,
  ɵɵlistener,
  ɵɵnextContext,
  ɵɵpipe,
  ɵɵpipeBind1,
  ɵɵproperty,
  ɵɵpureFunction1,
  ɵɵresetView,
  ɵɵrestoreView,
  ɵɵtemplate,
  ɵɵtext,
  ɵɵtextInterpolate,
  ɵɵtextInterpolate1
} from "./chunk-GKZIWABI.js";
import {
  __async
} from "./chunk-CVWHNZRK.js";

// src/app/@lcp-framework/pages/user-role-permission/user-role-permission.component.ts
var _c0 = (a0) => ({ "flex items-center": a0 });
function UserRolePermissionComponent_div_25_option_5_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "option", 25);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const role_r3 = ctx.$implicit;
    \u0275\u0275property("value", role_r3.id);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(role_r3.name);
  }
}
function UserRolePermissionComponent_div_25_Template(rf, ctx) {
  if (rf & 1) {
    const _r1 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 21)(1, "select", 22);
    \u0275\u0275listener("change", function UserRolePermissionComponent_div_25_Template_select_change_1_listener() {
      \u0275\u0275restoreView(_r1);
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.getEntityList());
    });
    \u0275\u0275elementStart(2, "option", 23);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275template(5, UserRolePermissionComponent_div_25_option_5_Template, 2, 2, "option", 24);
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    const ctx_r1 = \u0275\u0275nextContext();
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(4, 2, "select_any"));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.roleList);
  }
}
function UserRolePermissionComponent_div_26_option_5_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "option", 25);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const user_r5 = ctx.$implicit;
    \u0275\u0275property("value", user_r5.id);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(user_r5.name);
  }
}
function UserRolePermissionComponent_div_26_Template(rf, ctx) {
  if (rf & 1) {
    const _r4 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 21)(1, "select", 26);
    \u0275\u0275listener("change", function UserRolePermissionComponent_div_26_Template_select_change_1_listener() {
      \u0275\u0275restoreView(_r4);
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.getEntityList());
    });
    \u0275\u0275elementStart(2, "option", 23);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275template(5, UserRolePermissionComponent_div_26_option_5_Template, 2, 2, "option", 24);
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    const ctx_r1 = \u0275\u0275nextContext();
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(4, 2, "select_any"));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.userList);
  }
}
function UserRolePermissionComponent_ng_container_30_input_4_Template(rf, ctx) {
  if (rf & 1) {
    const _r8 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "input", 35);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_input_4_Template_input_change_0_listener($event) {
      \u0275\u0275restoreView(_r8);
      const entityGroup_r7 = \u0275\u0275nextContext().$implicit;
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.toggleAllRights(entityGroup_r7, ctx_r1.getCheckboxChecked($event)));
    });
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const entityGroup_r7 = \u0275\u0275nextContext().$implicit;
    const ctx_r1 = \u0275\u0275nextContext();
    \u0275\u0275property("checked", ctx_r1.isAllChecked(entityGroup_r7));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_1_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0);
    \u0275\u0275element(1, "i", 39);
    \u0275\u0275elementContainerEnd();
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_3_label_1_Template(rf, ctx) {
  if (rf & 1) {
    const _r9 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "label", 41)(1, "input", 42);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_3_label_1_Template_input_change_1_listener($event) {
      \u0275\u0275restoreView(_r9);
      const rightGroup_r10 = \u0275\u0275nextContext().$implicit;
      const entityGroup_r7 = \u0275\u0275nextContext(2).$implicit;
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.onCheckboxChange(rightGroup_r10, $event, entityGroup_r7));
    });
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(2, "span", 43);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    let tmp_8_0;
    const rightGroup_r10 = \u0275\u0275nextContext().$implicit;
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(4, 1, (tmp_8_0 = rightGroup_r10.get("name")) == null ? null : tmp_8_0.value));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_3_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275template(1, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_3_label_1_Template, 5, 3, "label", 40);
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_8_0;
    const rightGroup_r10 = ctx.$implicit;
    const j_r11 = ctx.index;
    \u0275\u0275property("formGroupName", j_r11);
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", (tmp_8_0 = rightGroup_r10.get("name")) == null ? null : tmp_8_0.value);
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_input_4_Template(rf, ctx) {
  if (rf & 1) {
    const _r12 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "input", 35);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_input_4_Template_input_change_0_listener($event) {
      \u0275\u0275restoreView(_r12);
      const childGroup_r13 = \u0275\u0275nextContext().$implicit;
      const ctx_r1 = \u0275\u0275nextContext(3);
      return \u0275\u0275resetView(ctx_r1.toggleAllRights(childGroup_r13, ctx_r1.getCheckboxChecked($event)));
    });
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const childGroup_r13 = \u0275\u0275nextContext().$implicit;
    const ctx_r1 = \u0275\u0275nextContext(3);
    \u0275\u0275property("checked", ctx_r1.isAllChecked(childGroup_r13));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_10_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0);
    \u0275\u0275element(1, "i", 39);
    \u0275\u0275elementContainerEnd();
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_12_label_1_Template(rf, ctx) {
  if (rf & 1) {
    const _r14 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "label", 41)(1, "input", 47);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_12_label_1_Template_input_change_1_listener($event) {
      \u0275\u0275restoreView(_r14);
      const rightGroup_r15 = \u0275\u0275nextContext().$implicit;
      const childGroup_r13 = \u0275\u0275nextContext().$implicit;
      const ctx_r1 = \u0275\u0275nextContext(3);
      return \u0275\u0275resetView(ctx_r1.onCheckboxChange(rightGroup_r15, $event, childGroup_r13));
    });
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(2, "span", 48);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    let tmp_11_0;
    const rightGroup_r15 = \u0275\u0275nextContext().$implicit;
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(4, 1, (tmp_11_0 = rightGroup_r15.get("name")) == null ? null : tmp_11_0.value));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_12_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275template(1, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_12_label_1_Template, 5, 3, "label", 40);
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_11_0;
    const rightGroup_r15 = ctx.$implicit;
    const l_r16 = ctx.index;
    \u0275\u0275property("formGroupName", l_r16);
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", (tmp_11_0 = rightGroup_r15.get("name")) == null ? null : tmp_11_0.value);
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_input_4_Template(rf, ctx) {
  if (rf & 1) {
    const _r17 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "input", 35);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_input_4_Template_input_change_0_listener($event) {
      \u0275\u0275restoreView(_r17);
      const grandchildGroup_r18 = \u0275\u0275nextContext().$implicit;
      const ctx_r1 = \u0275\u0275nextContext(4);
      return \u0275\u0275resetView(ctx_r1.toggleAllRights(grandchildGroup_r18, ctx_r1.getCheckboxChecked($event)));
    });
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const grandchildGroup_r18 = \u0275\u0275nextContext().$implicit;
    const ctx_r1 = \u0275\u0275nextContext(4);
    \u0275\u0275property("checked", ctx_r1.isAllChecked(grandchildGroup_r18));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_10_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0);
    \u0275\u0275element(1, "i", 39);
    \u0275\u0275elementContainerEnd();
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_12_label_1_Template(rf, ctx) {
  if (rf & 1) {
    const _r19 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "label", 41)(1, "input", 47);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_12_label_1_Template_input_change_1_listener($event) {
      \u0275\u0275restoreView(_r19);
      const rightGroup_r20 = \u0275\u0275nextContext().$implicit;
      const grandchildGroup_r18 = \u0275\u0275nextContext().$implicit;
      const ctx_r1 = \u0275\u0275nextContext(4);
      return \u0275\u0275resetView(ctx_r1.onCheckboxChange(rightGroup_r20, $event, grandchildGroup_r18));
    });
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(2, "span", 48);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    let tmp_14_0;
    const rightGroup_r20 = \u0275\u0275nextContext().$implicit;
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(4, 1, (tmp_14_0 = rightGroup_r20.get("name")) == null ? null : tmp_14_0.value));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_12_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275template(1, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_12_label_1_Template, 5, 3, "label", 40);
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_14_0;
    const rightGroup_r20 = ctx.$implicit;
    const n_r21 = ctx.index;
    \u0275\u0275property("formGroupName", n_r21);
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", (tmp_14_0 = rightGroup_r20.get("name")) == null ? null : tmp_14_0.value);
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275elementStart(1, "div", 44)(2, "button", 45);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275template(4, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_input_4_Template, 1, 1, "input", 30);
    \u0275\u0275element(5, "i", 31);
    \u0275\u0275elementStart(6, "span", 46);
    \u0275\u0275text(7);
    \u0275\u0275pipe(8, "translate");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementContainerStart(9);
    \u0275\u0275template(10, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_10_Template, 2, 0, "ng-container", 36);
    \u0275\u0275elementStart(11, "div", 37);
    \u0275\u0275template(12, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_ng_container_12_Template, 2, 2, "ng-container", 18);
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_12_0;
    let tmp_14_0;
    let tmp_15_0;
    const grandchildGroup_r18 = ctx.$implicit;
    const m_r22 = ctx.index;
    const ctx_r1 = \u0275\u0275nextContext(4);
    \u0275\u0275property("formGroupName", m_r22);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", \u0275\u0275pureFunction1(12, _c0, ctx_r1.getSortedRightsControls(grandchildGroup_r18).length > 0));
    \u0275\u0275advance();
    \u0275\u0275property("title", \u0275\u0275pipeBind1(3, 8, (tmp_12_0 = grandchildGroup_r18.get("name")) == null ? null : tmp_12_0.value));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(grandchildGroup_r18).length > 0);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", (tmp_14_0 = grandchildGroup_r18.get("menu_img")) == null ? null : tmp_14_0.value);
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(8, 10, (tmp_15_0 = grandchildGroup_r18.get("name")) == null ? null : tmp_15_0.value));
    \u0275\u0275advance(3);
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(grandchildGroup_r18).length > 0);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.getSortedRightsControls(grandchildGroup_r18));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275elementStart(1, "div", 44)(2, "button", 45);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275template(4, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_input_4_Template, 1, 1, "input", 30);
    \u0275\u0275element(5, "i", 31);
    \u0275\u0275elementStart(6, "span", 46);
    \u0275\u0275text(7);
    \u0275\u0275pipe(8, "translate");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementContainerStart(9);
    \u0275\u0275template(10, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_10_Template, 2, 0, "ng-container", 36);
    \u0275\u0275elementStart(11, "div", 37);
    \u0275\u0275template(12, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_12_Template, 2, 2, "ng-container", 18);
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(13, "div", 38);
    \u0275\u0275template(14, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_ng_container_14_Template, 13, 14, "ng-container", 18);
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_9_0;
    let tmp_11_0;
    let tmp_12_0;
    const childGroup_r13 = ctx.$implicit;
    const k_r23 = ctx.index;
    const ctx_r1 = \u0275\u0275nextContext(3);
    \u0275\u0275property("formGroupName", k_r23);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", \u0275\u0275pureFunction1(13, _c0, ctx_r1.getSortedRightsControls(childGroup_r13).length > 0));
    \u0275\u0275advance();
    \u0275\u0275property("title", \u0275\u0275pipeBind1(3, 9, (tmp_9_0 = childGroup_r13.get("name")) == null ? null : tmp_9_0.value));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(childGroup_r13).length > 0);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", (tmp_11_0 = childGroup_r13.get("menu_img")) == null ? null : tmp_11_0.value);
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(8, 11, (tmp_12_0 = childGroup_r13.get("name")) == null ? null : tmp_12_0.value));
    \u0275\u0275advance(3);
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(childGroup_r13).length > 0);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.getSortedRightsControls(childGroup_r13));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.getChildrenControls(childGroup_r13));
  }
}
function UserRolePermissionComponent_ng_container_30_ng_container_14_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementContainerStart(0);
    \u0275\u0275template(1, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_1_Template, 2, 0, "ng-container", 36);
    \u0275\u0275elementStart(2, "div", 37);
    \u0275\u0275template(3, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_3_Template, 2, 2, "ng-container", 18);
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(4, "div", 38);
    \u0275\u0275template(5, UserRolePermissionComponent_ng_container_30_ng_container_14_ng_container_5_Template, 15, 15, "ng-container", 18);
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    const entityGroup_r7 = \u0275\u0275nextContext().$implicit;
    const ctx_r1 = \u0275\u0275nextContext();
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(entityGroup_r7).length > 0);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.getSortedRightsControls(entityGroup_r7));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngForOf", ctx_r1.getChildrenControls(entityGroup_r7));
  }
}
function UserRolePermissionComponent_ng_container_30_Template(rf, ctx) {
  if (rf & 1) {
    const _r6 = \u0275\u0275getCurrentView();
    \u0275\u0275elementContainerStart(0, 27);
    \u0275\u0275elementStart(1, "div", 28)(2, "button", 29);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275listener("click", function UserRolePermissionComponent_ng_container_30_Template_button_click_2_listener() {
      const entityGroup_r7 = \u0275\u0275restoreView(_r6).$implicit;
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.toggleExpand(entityGroup_r7));
    });
    \u0275\u0275template(4, UserRolePermissionComponent_ng_container_30_input_4_Template, 1, 1, "input", 30);
    \u0275\u0275element(5, "i", 31);
    \u0275\u0275elementStart(6, "span", 32);
    \u0275\u0275text(7);
    \u0275\u0275pipe(8, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275element(9, "i", 33);
    \u0275\u0275elementStart(10, "label", 34);
    \u0275\u0275listener("click", function UserRolePermissionComponent_ng_container_30_Template_label_click_10_listener($event) {
      \u0275\u0275restoreView(_r6);
      return \u0275\u0275resetView($event.stopPropagation());
    });
    \u0275\u0275elementStart(11, "input", 35);
    \u0275\u0275listener("change", function UserRolePermissionComponent_ng_container_30_Template_input_change_11_listener($event) {
      const entityGroup_r7 = \u0275\u0275restoreView(_r6).$implicit;
      const ctx_r1 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r1.toggleAllRightsO(entityGroup_r7, ctx_r1.getCheckboxChecked($event)));
    });
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(12, "span", 5);
    \u0275\u0275text(13, "Select All");
    \u0275\u0275elementEnd()()();
    \u0275\u0275template(14, UserRolePermissionComponent_ng_container_30_ng_container_14_Template, 6, 3, "ng-container", 36);
    \u0275\u0275elementEnd();
    \u0275\u0275elementContainerEnd();
  }
  if (rf & 2) {
    let tmp_5_0;
    let tmp_7_0;
    let tmp_8_0;
    let tmp_9_0;
    let tmp_11_0;
    const entityGroup_r7 = ctx.$implicit;
    const i_r24 = ctx.index;
    const ctx_r1 = \u0275\u0275nextContext();
    \u0275\u0275property("formGroupName", i_r24);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", \u0275\u0275pureFunction1(13, _c0, ctx_r1.getSortedRightsControls(entityGroup_r7).length > 0));
    \u0275\u0275advance();
    \u0275\u0275property("title", \u0275\u0275pipeBind1(3, 9, (tmp_5_0 = entityGroup_r7.get("name")) == null ? null : tmp_5_0.value));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ctx_r1.getSortedRightsControls(entityGroup_r7).length > 0);
    \u0275\u0275advance();
    \u0275\u0275property("ngClass", (tmp_7_0 = entityGroup_r7.get("menu_img")) == null ? null : tmp_7_0.value);
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(8, 11, (tmp_8_0 = entityGroup_r7.get("name")) == null ? null : tmp_8_0.value));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngClass", ((tmp_9_0 = entityGroup_r7.get("expanded")) == null ? null : tmp_9_0.value) ? "fa-chevron-up" : "fa-chevron-down");
    \u0275\u0275advance(2);
    \u0275\u0275property("checked", ctx_r1.isAllChecked(entityGroup_r7));
    \u0275\u0275advance(3);
    \u0275\u0275property("ngIf", (tmp_11_0 = entityGroup_r7.get("expanded")) == null ? null : tmp_11_0.value);
  }
}
var _UserRolePermissionComponent = class _UserRolePermissionComponent {
  constructor(fb, toastr, gridApiService, translate, commonService, localStorageService, titleService) {
    this.fb = fb;
    this.toastr = toastr;
    this.gridApiService = gridApiService;
    this.translate = translate;
    this.commonService = commonService;
    this.localStorageService = localStorageService;
    this.titleService = titleService;
    this.entityList = [];
    this.roleList = [];
    this.userList = [];
    this.order_permissions = ["view", "add", "edit", "details", "delete", "export_excel", "assign"];
    this.mappingForm = this.fb.group({
      permission_type: ["user", Validators.required],
      user: [""],
      role: [""],
      entities: this.fb.array([])
    });
    this.user_info = JSON.parse(this.localStorageService.getData("user_data"));
  }
  ngOnInit() {
    const translateTitle = this.translate.instant("entity_user_role_map_page");
    this.titleService.setTitle(translateTitle);
    this.resetComponent();
  }
  resetComponent() {
    this.mappingForm.reset({
      permission_type: "user",
      user: "",
      role: ""
    });
    this.getActionTypes();
    this.getEntityList();
    this.getUserList();
    this.getRoleList();
  }
  populateEntities(data) {
    const entitiesArray = this.mappingForm.get("entities");
    entitiesArray.clear();
    data.forEach((entity) => {
      const rightsArray = new FormArray([]);
      if (entity.permissions && entity.permissions.length > 0) {
        entity.permissions.forEach((right) => {
          const isSelectedRight = right.entity_permission_value == "true" && (right.permission_value == "true" || !right.permission_id);
          rightsArray.push(this.fb.group({
            id: new FormControl(right.id),
            name: new FormControl(right.name),
            entity_id: new FormControl(right.entity_id),
            link_type: new FormControl(right.link_type),
            permission_id: new FormControl(right.permission_id),
            entity_permission_id: new FormControl(right.entity_permission_id),
            permission_value: new FormControl(right.permission_value == "true"),
            entity_permission_value: new FormControl(right.entity_permission_value == "true"),
            selected: new FormControl(isSelectedRight)
          }));
        });
      }
      const childrenArray = new FormArray([]);
      if (!entity.permissions && entity.children && entity.children.length > 0) {
        this.addChildEntities(entity.children, childrenArray);
      }
      if (entity.permissions?.length || entity.children?.length) {
        const entityGroup = this.fb.group({
          id: new FormControl(entity.id),
          name: new FormControl(entity.parent_name),
          menu_img: new FormControl(entity.menu_img),
          expanded: [true],
          rights: rightsArray,
          children: childrenArray
        });
        entitiesArray.push(entityGroup);
      }
    });
    this.loadDashboardWizards();
  }
  loadDashboardWizards() {
    return __async(this, null, function* () {
      const entitiesArray = this.mappingForm.get("entities");
      const permission_type = `${this.mappingForm.get("permission_type")?.value}`;
      const user_id = this.mappingForm.get("user")?.value || 0;
      const role_id = this.mappingForm.get("role")?.value || 0;
      const params = {
        company_id: 1,
        primary_table: "wizard_group",
        sort_columns: [["wizard_group.id", "asc"]],
        limit_range: 1e3,
        print_query: true,
        search_all: [
          {
            value: 1,
            operator: "=",
            column_name: "wizard_group.status_id"
          }
        ],
        select_columns: [
          ["wizard_group.id", "id"],
          ["wizard_group.name", "name"],
          [
            `CASE
            WHEN COUNT(subquery.id) = 0 THEN null
            ELSE COALESCE(
                Json_agg(
                    subquery.jsonb_object
                    ORDER BY subquery.order_no
                )
            )
        END`,
            "cards"
          ]
        ],
        includes: [
          {
            table_name: `LATERAL (
              SELECT
                DISTINCT ON (master_entities.id)
                master_entities.id,
                jsonb_build_object(
                  'id', master_entities.id,
                  'title', master_entities.name,
                  'type', master_entities.dashboard_wizard_type,
                  'order_no', master_entities.dashboard_wizard_order_no,
                  'entity_name', master_entities.entity_name,
                  'permission_id', permissions.id,
                  'has_permission',
                    CASE
                      WHEN '${permission_type}' = 'user' THEN
                        CASE
                          WHEN EXISTS (
                            SELECT 1
                            FROM user_permissions
                            WHERE user_permissions.permission_id = permissions.id
                            AND user_permissions.user_id = ${user_id}
                          ) THEN true
                          ELSE false
                        END
                      WHEN '${permission_type}' = 'role' THEN
                        CASE
                          WHEN EXISTS (
                            SELECT 1
                            FROM role_permissions
                            WHERE role_permissions.permission_id = permissions.id
                            AND role_permissions.role_id = ${role_id}
                          ) THEN true
                          ELSE false
                        END
                      ELSE false
                    END
                ) AS jsonb_object,
                master_entities.dashboard_wizard_order_no AS order_no
              FROM
                master_entities
              LEFT JOIN
                permissions ON permissions.entity_id = master_entities.id
              WHERE
                master_entities.dashboard_wizard_group_id = wizard_group.id AND master_entities.status_id = 1
              ORDER BY
                master_entities.id, master_entities.dashboard_wizard_order_no
            ) AS subquery`,
            join_type: "LEFT",
            join_condition: "TRUE"
          }
        ],
        group_by: ["wizard_group.id"]
      };
      this.gridApiService.getAllList(params).subscribe((response) => __async(this, null, function* () {
        if (response.status && response.code === 200) {
          const dashboardItems = response.data.records;
          let dashboard = this.fb.group({
            id: new FormControl(7777),
            name: new FormControl("dashboard"),
            menu_img: new FormControl("fa-gauge"),
            expanded: [true],
            children: this.fb.array([]),
            // Use FormArray for children
            rights: this.fb.array([])
          });
          dashboardItems.map((elem, index) => {
            if (elem.cards) {
              let tab = this.fb.group({
                id: new FormControl(7777 + index),
                name: new FormControl(elem.name),
                menu_img: new FormControl("fa-folder-open"),
                expanded: [true],
                children: this.fb.array([]),
                // Use FormArray for children
                rights: this.fb.array([])
              });
              elem.cards.map((ielem) => {
                let card = this.fb.group({
                  id: new FormControl(ielem.id),
                  name: new FormControl(ielem.entity_name),
                  menu_img: ielem.type == "chart" ? new FormControl("fa-chart-simple") : new FormControl("fa-palette"),
                  expanded: [true],
                  children: this.fb.array([]),
                  // If card has children, it's an array
                  rights: this.fb.array([
                    this.fb.group({
                      entity_id: new FormControl(ielem.id),
                      entity_permission_id: new FormControl(ielem.permission_id),
                      permission_id: new FormControl(ielem.permission_id),
                      name: new FormControl("view"),
                      permission_value: new FormControl(ielem.has_permission),
                      entity_permission_value: new FormControl(ielem.has_permission),
                      link_type: new FormControl(1),
                      id: new FormControl(ielem.id),
                      selected: new FormControl(ielem.has_permission)
                    })
                  ])
                });
                tab.get("children").push(card);
              });
              dashboard.get("children").push(tab);
            }
          });
          if (entitiesArray && entitiesArray.controls.length > 0) {
            if (dashboard.get("children").length > 0) {
              entitiesArray.insert(0, dashboard);
            }
          }
        }
      }), (error) => {
        const key = "failed_to_load";
        const errorMessage = this.translate.instant(key);
        this.toastr.error(errorMessage, "Error");
      });
    });
  }
  addChildEntities(children, parentArray) {
    children.forEach((child) => {
      const rightsArray = new FormArray([]);
      if (child.permissions && child.permissions.length > 0) {
        child.permissions.forEach((right) => {
          const isSelectedRight = right.entity_permission_value == "true" && (right.permission_value == "true" || !right.permission_id);
          rightsArray.push(this.fb.group({
            id: new FormControl(right.id),
            name: new FormControl(right.permission_name ?? right.entity_permission_name),
            entity_id: new FormControl(right.entity_id),
            link_type: new FormControl(right.link_type),
            permission_id: new FormControl(right.permission_id),
            entity_permission_id: new FormControl(right.entity_permission_id),
            permission_value: new FormControl(right.permission_value == "true"),
            entity_permission_value: new FormControl(right.entity_permission_value == "true"),
            selected: new FormControl(isSelectedRight)
          }));
        });
      }
      const childrenArray = new FormArray([]);
      if (!child.permissions && child.children && child.children.length > 0) {
        this.addChildEntities(child.children, childrenArray);
      }
      if (child.permissions?.length || child.children?.length) {
        const childGroup = this.fb.group({
          id: new FormControl(child.id),
          name: new FormControl(child.parent_name),
          menu_img: new FormControl(child.menu_img),
          expanded: [true],
          rights: rightsArray,
          children: childrenArray
        });
        parentArray.push(childGroup);
      }
    });
  }
  getRightsControls(entityGroup) {
    return entityGroup.get("rights").controls;
  }
  onCheckboxChange(rightGroup, event, parentGroup) {
    const rightsArray = parentGroup.get("rights");
    const viewControl = rightsArray.at(0).get("selected");
    const isChecked = rightGroup.get("selected")?.value;
    if (rightGroup.get("name")?.value === "view") {
      if (!isChecked) {
        rightsArray.controls.forEach((control) => {
          control.get("selected")?.setValue(false);
        });
      }
    } else {
      if (isChecked) {
        if (rightGroup.get("name")?.value !== "view") {
          viewControl.setValue(true);
        }
      } else {
        const otherChecked = rightsArray.controls.some((control, index) => {
          const isView = index === 0;
          return control.get("selected")?.value && !isView;
        });
      }
    }
  }
  getSortedRightsControls(entityGroup) {
    const rightsControls = this.getRightsControls(entityGroup);
    if (rightsControls) {
      return rightsControls.sort((a, b) => {
        const aName = a.get("name")?.value;
        const bName = b.get("name")?.value;
        const aIndex = this.order_permissions.indexOf(aName);
        const bIndex = this.order_permissions.indexOf(bName);
        return aIndex - bIndex;
      });
    } else {
      return [];
    }
  }
  getChildrenControls(entityGroup) {
    return entityGroup.get("children").controls;
  }
  mapPermissions() {
    if (this.mappingForm.invalid) {
      const key = "please_select_all_the_required_fields";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
      return;
    }
    const permission_type = this.mappingForm.get("permission_type")?.value;
    const role_id = this.mappingForm.get("role")?.value;
    const user_id = this.mappingForm.get("user")?.value;
    if (permission_type === "user") {
      this.executeUserMap(user_id);
    } else {
      this.executeRoleMap(role_id);
    }
  }
  selectedUserPermissions(entitiesArray, selectedPermissions) {
    entitiesArray.controls.forEach((entityGroup) => {
      const rightsArray = entityGroup.get("rights");
      rightsArray.controls.forEach((rightControl) => {
        if (rightControl.get("selected")?.value) {
          if (rightControl.get("permission_id")?.value) {
            selectedPermissions.push({
              user_id: this.mappingForm.get("user")?.value,
              // or replace this with dynamic user_id if necessary
              permission_id: rightControl.get("permission_id")?.value
            });
          }
          if (rightControl.get("entity_permission_id")?.value) {
            selectedPermissions.push({
              user_id: this.mappingForm.get("user")?.value,
              // or replace this with dynamic user_id if necessary
              permission_id: rightControl.get("entity_permission_id")?.value
            });
          }
        }
      });
      const childrenArray = entityGroup.get("children");
      if (childrenArray && childrenArray.length > 0) {
        this.selectedUserPermissions(childrenArray, selectedPermissions);
      }
    });
  }
  toggleExpand(entityGroup) {
    const isExpanded = entityGroup.get("expanded")?.value;
    entityGroup.get("expanded")?.setValue(!isExpanded);
  }
  // Ensure that each entity group has an 'expanded' property
  /* getEntitiesControls() {
    return (this.mappingForm.get('entities') as FormArray).controls.map(entityGroup => {
      if (!entityGroup.expanded) {
        entityGroup.expanded = false; // Default to collapsed
      }
      return entityGroup;
    });
  }*/
  getEntitiesControls() {
    return this.mappingForm.get("entities").controls;
  }
  selectedRolePermissions(entitiesArray, selectedPermissions) {
    entitiesArray.controls.forEach((entityGroup) => {
      const rightsArray = entityGroup.get("rights");
      rightsArray.controls.forEach((rightControl) => {
        if (rightControl.get("selected")?.value) {
          if (rightControl.get("permission_id")?.value) {
            selectedPermissions.push({
              role_id: this.mappingForm.get("role")?.value,
              // or replace this with dynamic role_id if necessary
              permission_id: rightControl.get("permission_id")?.value
            });
          }
          if (rightControl.get("entity_permission_id")?.value) {
            selectedPermissions.push({
              role_id: this.mappingForm.get("role")?.value,
              // or replace this with dynamic role_id if necessary
              permission_id: rightControl.get("entity_permission_id")?.value
            });
          }
        }
      });
      const childrenArray = entityGroup.get("children");
      if (childrenArray && childrenArray.length > 0) {
        this.selectedRolePermissions(childrenArray, selectedPermissions);
      }
    });
  }
  getActionTypes() {
    const param = {
      company_id: 1,
      print_query: false,
      primary_table: "action_types",
      start_index: 0,
      limit_range: 100,
      sort_columns: [["action_types.id", "asc"]],
      select_columns: [["action_types.id"], ["action_types.name", "name"], ["action_types.description", "description"]]
    };
    this.gridApiService.getListData(param).subscribe((response) => {
      if (response.status) {
        console.log(response.data?.records);
        if (response.data?.records) {
          let finalList = [];
          response.data?.records.map(function(elem) {
            finalList.push(elem.name);
          });
          this.order_permissions = finalList;
        }
      } else if (!response.status) {
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  getEntityList() {
    const permission_type = `${this.mappingForm.get("permission_type")?.value}wise`;
    const user_id = this.mappingForm.get("user")?.value || 0;
    const role_id = this.mappingForm.get("role")?.value || 0;
    const param = { proc_name: "get_menu_permissions", params: { user_id, menu_id: 1, role_id, permission_type } };
    this.commonService.procedureCall(param).subscribe((response) => {
      if (response.status) {
        const records = response.data.length && response.data[0].result || [];
        this.entityList = this.mapPermissionsToHierarchy(records);
        this.populateEntities(this.entityList);
      } else if (!response.status) {
        this.entityList = [];
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      this.entityList = [];
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  mapPermissionsToHierarchy(permissions) {
    const permissionMap = {};
    const hierarchy = [];
    permissions.forEach((permission) => {
      permission.permissions = typeof permission.permissions === "string" ? JSON.parse(permission.permissions) : permission.permissions;
      permission.children = [];
      permissionMap[permission.id] = permission;
    });
    permissions.forEach((permission) => {
      if (permission.parent_id === null) {
        hierarchy.push(permission);
      } else {
        const parent = permissionMap[permission.parent_id];
        if (parent) {
          parent.children.push(permission);
        }
      }
    });
    return hierarchy;
  }
  getRoleList() {
    const param = {
      company_id: 1,
      print_query: false,
      primary_table: "roles",
      start_index: 0,
      limit_range: 1e3,
      sort_columns: [["roles.name", "asc"]],
      search_all: [
        {
          column_name: "roles.status_id",
          value: "1",
          operator: "="
        }
      ],
      select_columns: [["roles.id"], ["roles.name"], ["roles.uuid"]]
    };
    this.gridApiService.getListData(param).subscribe((response) => {
      if (response.status) {
        this.roleList = response.data?.records || [];
      } else if (!response.status) {
        this.roleList = [];
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      this.roleList = [];
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  getUserList() {
    const param = {
      company_id: 1,
      print_query: false,
      primary_table: "users",
      start_index: 0,
      limit_range: 1e3,
      sort_columns: [["concat(user_details.first_name, ' ', user_details.last_name)", "asc"]],
      search_all: [
        {
          column_name: "users.status_id",
          value: "1",
          operator: "="
        },
        {
          value: ["super_admin", "company_admin"],
          operator: "NOT IN",
          column_name: "users.role"
        }
      ],
      includes: [
        {
          table_name: "user_details",
          join_type: "INNER",
          join_condition: "users.id = user_details.user_id"
        }
      ],
      select_columns: [["users.id"], ["concat(user_details.first_name, ' ', user_details.last_name)", "name"], ["users.uuid"]]
    };
    this.gridApiService.getListData(param).subscribe((response) => {
      if (response.status) {
        this.userList = response.data?.records || [];
      } else if (!response.status) {
        this.userList = [];
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      this.userList = [];
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  executeUserMap(user_id) {
    let param = {
      action: ["hard_delete", "insert"],
      table: ["user_permissions", "user_permissions"],
      table_mapping: ["table1", "table2"],
      conditions: {
        table1: [{ user_id }]
      },
      data: {
        table2: []
      }
    };
    let selectedPermissions = [];
    const entitiesArray = this.mappingForm.get("entities");
    this.selectedUserPermissions(entitiesArray, selectedPermissions);
    if (selectedPermissions.length === 0) {
      const key = "please_select_atleast_one_permission";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
      return;
    }
    const uniqueData = selectedPermissions.filter((item, index, self) => index === self.findIndex((t) => t.user_id === item.user_id && t.permission_id === item.permission_id));
    param.data.table2 = uniqueData;
    this.gridApiService.executeTransaction(param).subscribe((response) => {
      if (response.status) {
        const key = "user_permission_mapping_successfully";
        const successMessage = this.translate.instant(key);
        this.toastr.success(successMessage);
      } else if (!response.status) {
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  executeRoleMap(role_id) {
    let param = {
      action: ["hard_delete", "insert"],
      table: ["role_permissions", "role_permissions"],
      table_mapping: ["table1", "table2"],
      conditions: {
        table1: [{ role_id }]
      },
      data: {
        table2: []
      }
    };
    let selectedPermissions = [];
    const entitiesArray = this.mappingForm.get("entities");
    this.selectedRolePermissions(entitiesArray, selectedPermissions);
    if (selectedPermissions.length === 0) {
      const key = "please_select_atleast_one_permission";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
      return;
    }
    const uniqueData = selectedPermissions.filter((item, index, self) => index === self.findIndex((t) => t.role_id === item.role_id && t.permission_id === item.permission_id));
    param.data.table2 = uniqueData;
    this.gridApiService.executeTransaction(param).subscribe((response) => {
      if (response.status) {
        const key = "role_permission_mapping_successfully";
        const successMessage = this.translate.instant(key);
        this.toastr.success(successMessage);
      } else if (!response.status) {
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(`Code: ${response.code} , ${errorMessage}`);
      }
    }, (error) => {
      const key = "error_mapping_role_permissions";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
  isAllChecked(group) {
    const rightsArray = group.get("rights");
    return rightsArray && rightsArray.length > 0 && rightsArray.controls.every((control) => control.get("selected")?.value);
  }
  toggleAllRights(group, checked) {
    const rightsArray = group.get("rights");
    rightsArray.controls.forEach((control) => {
      control.get("selected")?.setValue(checked);
    });
    if (checked) {
      const viewControl = rightsArray.controls.find((c) => c.get("name")?.value === "view");
      if (viewControl) {
        viewControl.get("selected")?.setValue(true);
      }
    }
  }
  getCheckboxChecked(event) {
    return event.target.checked;
  }
  areAllEntitiesChecked() {
    const entities = this.getEntitiesControls();
    return entities.length > 0 && entities.every((entity) => this.isAllChecked(entity));
  }
  toggleAllEntities(event) {
    const checked = event.target.checked;
    const entities = this.getEntitiesControls();
    entities.forEach((entity) => this.toggleAllRightsO(entity, checked));
  }
  toggleAllRightsO(group, checked) {
    const rightsArray = group.get("rights");
    if (rightsArray) {
      rightsArray.controls.forEach((control) => {
        control.get("selected")?.setValue(checked);
      });
      if (checked) {
        const viewControl = rightsArray.controls.find((c) => c.get("name")?.value === "view");
        if (viewControl) {
          viewControl.get("selected")?.setValue(true);
        }
      }
    }
    const childrenArray = group.get("children");
    if (childrenArray) {
      childrenArray.controls.forEach((child) => {
        this.toggleAllRightsO(child, checked);
      });
    }
  }
};
_UserRolePermissionComponent.\u0275fac = function UserRolePermissionComponent_Factory(t) {
  return new (t || _UserRolePermissionComponent)(\u0275\u0275directiveInject(FormBuilder), \u0275\u0275directiveInject(ToastrService), \u0275\u0275directiveInject(GridApiService), \u0275\u0275directiveInject(TranslateService), \u0275\u0275directiveInject(MenuMapService), \u0275\u0275directiveInject(LocalStorageService), \u0275\u0275directiveInject(Title));
};
_UserRolePermissionComponent.\u0275cmp = /* @__PURE__ */ \u0275\u0275defineComponent({ type: _UserRolePermissionComponent, selectors: [["app-user-role-permission"]], standalone: true, features: [\u0275\u0275StandaloneFeature], decls: 34, vars: 14, consts: [[1, "space-y-6", 3, "ngSubmit", "formGroup"], [1, "header-panel", "mb-1", "mt-0", "flex", "flex-col", "gap-5", "px-2", "md:flex-row", "md:items-center"], ["appDynamicFontSize", "title", 1, "font-bold", "dark:text-white-light"], [1, "flex", "items-center", "text-sm"], ["type", "checkbox", 1, "form-checkbox", "ml-2", "h-4", "w-4", "rounded", "border-gray-300", "text-primary", 3, "change", "checked"], [1, "ml-1"], [1, "flex", "items-center", "gap-4", "md:flex-row", "md:items-center", "md:ltr:ml-auto", "md:rtl:mr-auto"], [1, "flex", "flex-col", "gap-2", "md:flex-row", "md:items-center"], ["appDynamicFontSize", "body", 1, "relative", "mb-2", "flex-grow", "md:mb-0"], [1, "flex", "list-inside", "space-x-3", "pt-2", "font-semibold", "text-gray-700", "dark:text-[#d0d2d6]", "rtl:space-x-reverse"], [1, "flex", "cursor-pointer", "items-center"], ["type", "radio", "name", "permission_type", "value", "role", "formControlName", "permission_type", 1, "form-radio"], [1, "text-gray-900", "dark:text-white-dark"], ["type", "radio", "name", "permission_type", "value", "user", "formControlName", "permission_type", 1, "form-radio"], ["class", "align-center inline-contents relative justify-center", 4, "ngIf"], [1, "relative", "h-full", "w-full"], [1, "h-full", "w-full"], ["formArrayName", "entities", 1, "ml-2", "min-w-full", "sm:min-w-[700px]", "lg:min-w-[1200px]"], [3, "formGroupName", 4, "ngFor", "ngForOf"], [1, "mt-4", "flex", "justify-end"], ["type", "submit", 1, "hover:bg-primary-dark", "dark:bg-primary-dark", "dark:focus:ring-primary-dark", "rounded-md", "bg-primary", "px-6", "py-2", "text-white", "shadow-sm", "focus:outline-none", "focus:ring-2", "focus:ring-primary", "focus:ring-offset-2", "dark:text-white"], [1, "align-center", "inline-contents", "relative", "justify-center"], ["appDynamicFontSize", "body", "id", "role", "formControlName", "role", 1, "form-select", "mr-2", "flex", "w-full", "items-center", "text-gray-700", "dark:bg-gray-800", "dark:text-white-dark", 3, "change"], ["value", ""], [3, "value", 4, "ngFor", "ngForOf"], [3, "value"], ["appDynamicFontSize", "body", "id", "user", "formControlName", "user", 1, "form-select", "mr-2", "flex", "w-full", "items-center", "text-gray-700", "dark:bg-gray-800", "dark:text-white-dark", 3, "change"], [3, "formGroupName"], [1, "mb-2", "overflow-x-auto", "rounded-lg", "border", "bg-gray-100", "p-4", "shadow-sm", "dark:bg-black", 3, "ngClass"], ["type", "button", "appDynamicFontSize", "title", 1, "flex", "items-center", "font-semibold", "text-gray-900", "dark:text-white", "md:w-80", 3, "click", "title"], ["type", "checkbox", "class", "form-checkbox h-4 w-4 rounded border-gray-300 text-primary", 3, "checked", "change", 4, "ngIf"], [1, "fas", 3, "ngClass"], ["appDynamicFontSize", "title", 1, "ml-2"], [1, "fas", "ml-4", 3, "ngClass"], [1, "ml-4", "flex", "items-center", "text-sm", 3, "click"], ["type", "checkbox", 1, "form-checkbox", "h-4", "w-4", "rounded", "border-gray-300", "text-primary", 3, "change", "checked"], [4, "ngIf"], ["formArrayName", "rights", 1, "ml-7", "mt-2", "flex", "flex-wrap", "gap-2"], ["formArrayName", "children", 1, "ml-7", "mt-2"], [1, "fas", "fa-arrow-right", "mx-2"], ["class", "flex items-center justify-center whitespace-nowrap", 4, "ngIf"], [1, "flex", "items-center", "justify-center", "whitespace-nowrap"], ["type", "checkbox", "formControlName", "selected", 1, "form-checkbox", "h-4", "w-4", "rounded", "border-gray-300", "align-middle", "text-primary", 3, "change"], ["appDynamicFontSize", "subtitle", 1, "leading-none"], [1, "mb-2", "overflow-x-auto", 3, "ngClass"], ["type", "button", "appDynamicFontSize", "subtitle", 1, "font-semibold", "sm:flex", "sm:items-center", "md:w-80", 3, "title"], ["appDynamicFontSize", "subtitle", 1, "ml-2"], ["type", "checkbox", "formControlName", "selected", "appDynamicFontSize", "body", 1, "form-checkbox", "h-4", "w-4", "rounded", "border-gray-300", "align-middle", "text-primary", 3, "change"], ["appDynamicFontSize", "body", 1, "leading-none"]], template: function UserRolePermissionComponent_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "form", 0);
    \u0275\u0275listener("ngSubmit", function UserRolePermissionComponent_Template_form_ngSubmit_0_listener() {
      return ctx.mapPermissions();
    });
    \u0275\u0275elementStart(1, "div", 1)(2, "div", 2);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(5, "label", 3)(6, "input", 4);
    \u0275\u0275listener("change", function UserRolePermissionComponent_Template_input_change_6_listener($event) {
      return ctx.toggleAllEntities($event);
    });
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(7, "span", 5);
    \u0275\u0275text(8, "Select All");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(9, "div", 6)(10, "div", 7)(11, "div", 8)(12, "ul", 9)(13, "li")(14, "label", 10);
    \u0275\u0275element(15, "input", 11);
    \u0275\u0275elementStart(16, "span", 12);
    \u0275\u0275text(17);
    \u0275\u0275pipe(18, "translate");
    \u0275\u0275elementEnd()()();
    \u0275\u0275elementStart(19, "li")(20, "label", 10);
    \u0275\u0275element(21, "input", 13);
    \u0275\u0275elementStart(22, "span", 12);
    \u0275\u0275text(23);
    \u0275\u0275pipe(24, "translate");
    \u0275\u0275elementEnd()()()()();
    \u0275\u0275template(25, UserRolePermissionComponent_div_25_Template, 6, 4, "div", 14)(26, UserRolePermissionComponent_div_26_Template, 6, 4, "div", 14);
    \u0275\u0275elementEnd()()();
    \u0275\u0275elementStart(27, "div", 15)(28, "div", 16)(29, "div", 17);
    \u0275\u0275template(30, UserRolePermissionComponent_ng_container_30_Template, 15, 15, "ng-container", 18);
    \u0275\u0275elementEnd()()();
    \u0275\u0275elementStart(31, "div", 19)(32, "button", 20);
    \u0275\u0275text(33, " Submit ");
    \u0275\u0275elementEnd()()();
  }
  if (rf & 2) {
    let tmp_5_0;
    let tmp_6_0;
    \u0275\u0275property("formGroup", ctx.mappingForm);
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(4, 8, "entity_user_role_map_page"), " ");
    \u0275\u0275advance(3);
    \u0275\u0275property("checked", ctx.areAllEntitiesChecked());
    \u0275\u0275advance(11);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(18, 10, "role_permission"));
    \u0275\u0275advance(6);
    \u0275\u0275textInterpolate(\u0275\u0275pipeBind1(24, 12, "user_permission"));
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ((tmp_5_0 = ctx.mappingForm.get("permission_type")) == null ? null : tmp_5_0.value) === "role");
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ((tmp_6_0 = ctx.mappingForm.get("permission_type")) == null ? null : tmp_6_0.value) === "user");
    \u0275\u0275advance(4);
    \u0275\u0275property("ngForOf", ctx.getEntitiesControls());
  }
}, dependencies: [CommonSharedModule, NgClass, NgForOf, NgIf, \u0275NgNoValidate, NgSelectOption, \u0275NgSelectMultipleOption, DefaultValueAccessor, CheckboxControlValueAccessor, SelectControlValueAccessor, RadioControlValueAccessor, NgControlStatus, NgControlStatusGroup, DynamicFontSizeDirective, TranslatePipe, ReactiveFormsModule, FormGroupDirective, FormControlName, FormGroupName, FormArrayName], styles: ["\n\n.overflow-x-auto[_ngcontent-%COMP%]::-webkit-scrollbar {\n  display: none;\n}\n.overflow-x-auto[_ngcontent-%COMP%] {\n  -ms-overflow-style: none;\n  scrollbar-width: none;\n}\n/*# sourceMappingURL=user-role-permission.component.css.map */"] });
var UserRolePermissionComponent = _UserRolePermissionComponent;
(() => {
  (typeof ngDevMode === "undefined" || ngDevMode) && \u0275setClassDebugInfo(UserRolePermissionComponent, { className: "UserRolePermissionComponent", filePath: "src\\app\\@lcp-framework\\pages\\user-role-permission\\user-role-permission.component.ts", lineNumber: 64 });
})();
export {
  UserRolePermissionComponent
};
//# sourceMappingURL=chunk-C75HUCTF.js.map
