import {
  FormlyBootstrapModule,
  FormlyConfigModule,
  FormlyModule
} from "./chunk-NFRJCL7R.js";
import "./chunk-62OL73TD.js";
import "./chunk-IGGXREIH.js";
import {
  MenuMapService
} from "./chunk-3FLJCSSF.js";
import {
  ToastrService
} from "./chunk-2YLAF7RI.js";
import {
  CommonSharedModule,
  DynamicFontSizeDirective,
  NgOptionComponent,
  NgSelectComponent,
  NgSelectModule
} from "./chunk-7NQGM4EA.js";
import {
  DefaultValueAccessor,
  FormArrayName,
  FormBuilder,
  FormControlName,
  FormGroupDirective,
  FormGroupName,
  FormsModule,
  NgControlStatus,
  NgControlStatusGroup,
  NgSelectOption,
  ReactiveFormsModule,
  RequiredValidator,
  SelectControlValueAccessor,
  TranslatePipe,
  TranslateService,
  Validators,
  ɵNgNoValidate,
  ɵNgSelectMultipleOption
} from "./chunk-NLYGDKUR.js";
import "./chunk-ZEL7H2AL.js";
import {
  GridApiService,
  LocalStorageService,
  Router
} from "./chunk-P7K2QEDI.js";
import {
  CommonModule,
  Location,
  NgIf,
  ɵsetClassDebugInfo,
  ɵɵStandaloneFeature,
  ɵɵadvance,
  ɵɵconditional,
  ɵɵdefineComponent,
  ɵɵdirectiveInject,
  ɵɵelement,
  ɵɵelementEnd,
  ɵɵelementStart,
  ɵɵgetCurrentView,
  ɵɵlistener,
  ɵɵnextContext,
  ɵɵpipe,
  ɵɵpipeBind1,
  ɵɵproperty,
  ɵɵrepeater,
  ɵɵrepeaterCreate,
  ɵɵrepeaterTrackByIdentity,
  ɵɵresetView,
  ɵɵrestoreView,
  ɵɵtemplate,
  ɵɵtext,
  ɵɵtextInterpolate,
  ɵɵtextInterpolate1
} from "./chunk-GKZIWABI.js";
import {
  __async
} from "./chunk-CVWHNZRK.js";

// src/app/@lcp-framework/pages/whatsapp-template-assignment/whatsapp-template-assignment.component.ts
function WhatsappTemplateAssignmentComponent_For_25_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "option", 14);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const process_r1 = ctx.$implicit;
    \u0275\u0275property("value", process_r1.id);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(process_r1.name);
  }
}
function WhatsappTemplateAssignmentComponent_For_30_For_10_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "option", 14);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const template_r3 = ctx.$implicit;
    \u0275\u0275property("value", template_r3.value);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(template_r3.label);
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_11_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 27);
    \u0275\u0275text(1);
    \u0275\u0275pipe(2, "translate");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(2, 1, "whatsapp_template_is_required"), " ");
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_25_For_8_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "option", 14);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const tag_r7 = ctx.$implicit;
    \u0275\u0275property("value", tag_r7.id);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(tag_r7.name);
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_25_div_9_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 27);
    \u0275\u0275text(1);
    \u0275\u0275pipe(2, "translate");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(2, 1, "whatsapp_tag_is_required"), " ");
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_25_div_10_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 30);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    let tmp_12_0;
    const assignment_r4 = \u0275\u0275nextContext(2).$implicit;
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1("sends to : ", (tmp_12_0 = assignment_r4.get("whatsapp_tag_number")) == null ? null : tmp_12_0.value, "");
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_25_Template(rf, ctx) {
  if (rf & 1) {
    const _r6 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 9)(1, "label");
    \u0275\u0275text(2);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275elementStart(4, "span", 11);
    \u0275\u0275text(5, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(6, "select", 28);
    \u0275\u0275listener("change", function WhatsappTemplateAssignmentComponent_For_30_div_25_Template_select_change_6_listener() {
      let tmp_12_0;
      \u0275\u0275restoreView(_r6);
      const assignment_r4 = \u0275\u0275nextContext().$implicit;
      const ctx_r4 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r4.getTemplateAssignmentTags((tmp_12_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_12_0.value, assignment_r4));
    });
    \u0275\u0275repeaterCreate(7, WhatsappTemplateAssignmentComponent_For_30_div_25_For_8_Template, 2, 2, "option", 14, \u0275\u0275repeaterTrackByIdentity);
    \u0275\u0275elementEnd();
    \u0275\u0275template(9, WhatsappTemplateAssignmentComponent_For_30_div_25_div_9_Template, 3, 3, "div", 20)(10, WhatsappTemplateAssignmentComponent_For_30_div_25_div_10_Template, 2, 1, "div", 29);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    let tmp_13_0;
    let tmp_14_0;
    const assignment_r4 = \u0275\u0275nextContext().$implicit;
    const ctx_r4 = \u0275\u0275nextContext();
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(3, 3, "whatsapp_tag"), " ");
    \u0275\u0275advance(5);
    \u0275\u0275repeater(ctx_r4.recipientTags);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.invalid) && (((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.touched) || ((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.dirty)));
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", (tmp_14_0 = assignment_r4.get("whatsapp_tag_number")) == null ? null : tmp_14_0.value);
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_26_For_8_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "ng-option", 14);
    \u0275\u0275text(1);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const user_r9 = ctx.$implicit;
    \u0275\u0275property("value", user_r9.value);
    \u0275\u0275advance();
    \u0275\u0275textInterpolate(user_r9.label);
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_26_div_9_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 27);
    \u0275\u0275text(1);
    \u0275\u0275pipe(2, "translate");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(2, 1, "user_phoneno_is_required"), " ");
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_26_Template(rf, ctx) {
  if (rf & 1) {
    const _r8 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 9)(1, "label");
    \u0275\u0275text(2);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275elementStart(4, "span", 11);
    \u0275\u0275text(5, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(6, "ng-select", 31);
    \u0275\u0275listener("search", function WhatsappTemplateAssignmentComponent_For_30_div_26_Template_ng_select_search_6_listener($event) {
      \u0275\u0275restoreView(_r8);
      const assignment_r4 = \u0275\u0275nextContext().$implicit;
      const ctx_r4 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r4.getUsers(assignment_r4, $event.term || ""));
    })("clear", function WhatsappTemplateAssignmentComponent_For_30_div_26_Template_ng_select_clear_6_listener() {
      \u0275\u0275restoreView(_r8);
      const assignment_r4 = \u0275\u0275nextContext().$implicit;
      const ctx_r4 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r4.getUsers(assignment_r4, ""));
    });
    \u0275\u0275repeaterCreate(7, WhatsappTemplateAssignmentComponent_For_30_div_26_For_8_Template, 2, 2, "ng-option", 14, \u0275\u0275repeaterTrackByIdentity);
    \u0275\u0275elementEnd();
    \u0275\u0275template(9, WhatsappTemplateAssignmentComponent_For_30_div_26_div_9_Template, 3, 3, "div", 20);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    let tmp_14_0;
    let tmp_15_0;
    const assignment_r4 = \u0275\u0275nextContext().$implicit;
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(3, 4, "user_phoneno"), " ");
    \u0275\u0275advance(4);
    \u0275\u0275property("clearable", true)("searchable", true);
    \u0275\u0275advance();
    \u0275\u0275repeater((tmp_14_0 = assignment_r4.get("user_list")) == null ? null : tmp_14_0.value);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ((tmp_15_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_15_0.invalid) && (((tmp_15_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_15_0.touched) || ((tmp_15_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_15_0.dirty)));
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_27_div_9_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 27);
    \u0275\u0275text(1);
    \u0275\u0275pipe(2, "translate");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(2, 1, "whatsapp_is_required"), " ");
  }
}
function WhatsappTemplateAssignmentComponent_For_30_div_27_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 9)(1, "label");
    \u0275\u0275text(2);
    \u0275\u0275pipe(3, "translate");
    \u0275\u0275elementStart(4, "span", 11);
    \u0275\u0275text(5, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275element(6, "input", 32);
    \u0275\u0275elementStart(7, "div", 30);
    \u0275\u0275text(8);
    \u0275\u0275elementEnd();
    \u0275\u0275template(9, WhatsappTemplateAssignmentComponent_For_30_div_27_div_9_Template, 3, 3, "div", 20);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    let tmp_13_0;
    const assignment_r4 = \u0275\u0275nextContext().$implicit;
    \u0275\u0275advance(2);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(3, 3, "phone"), " ");
    \u0275\u0275advance(6);
    \u0275\u0275textInterpolate1("Note : Can add multiple whatsapp numbers as comma seperated values eg: ", "example1@gmail.com, example2@gmail.com", "");
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.invalid) && (((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.touched) || ((tmp_13_0 = assignment_r4.get("whatsapp_to")) == null ? null : tmp_13_0.dirty)));
  }
}
function WhatsappTemplateAssignmentComponent_For_30_Conditional_28_Template(rf, ctx) {
  if (rf & 1) {
    const _r10 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "i", 33);
    \u0275\u0275listener("click", function WhatsappTemplateAssignmentComponent_For_30_Conditional_28_Template_i_click_0_listener() {
      \u0275\u0275restoreView(_r10);
      const i_r11 = \u0275\u0275nextContext().$index;
      const ctx_r4 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r4.removeWhatsappTemplateAssignment(i_r11));
    });
    \u0275\u0275elementEnd();
  }
}
function WhatsappTemplateAssignmentComponent_For_30_Template(rf, ctx) {
  if (rf & 1) {
    const _r2 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 17)(1, "div", 18)(2, "div", 9)(3, "label");
    \u0275\u0275text(4);
    \u0275\u0275pipe(5, "translate");
    \u0275\u0275elementStart(6, "span", 11);
    \u0275\u0275text(7, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(8, "select", 19);
    \u0275\u0275repeaterCreate(9, WhatsappTemplateAssignmentComponent_For_30_For_10_Template, 2, 2, "option", 14, \u0275\u0275repeaterTrackByIdentity);
    \u0275\u0275elementEnd();
    \u0275\u0275template(11, WhatsappTemplateAssignmentComponent_For_30_div_11_Template, 3, 3, "div", 20);
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(12, "div", 9)(13, "label");
    \u0275\u0275text(14);
    \u0275\u0275pipe(15, "translate");
    \u0275\u0275elementStart(16, "span", 11);
    \u0275\u0275text(17, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(18, "select", 21);
    \u0275\u0275listener("change", function WhatsappTemplateAssignmentComponent_For_30_Template_select_change_18_listener() {
      const assignment_r4 = \u0275\u0275restoreView(_r2).$implicit;
      const ctx_r4 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r4.clearUserTagValues(assignment_r4));
    });
    \u0275\u0275elementStart(19, "option", 22);
    \u0275\u0275text(20, "Tag");
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(21, "option", 23);
    \u0275\u0275text(22, "User");
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(23, "option", 24);
    \u0275\u0275text(24, "Custom Mail");
    \u0275\u0275elementEnd()()();
    \u0275\u0275template(25, WhatsappTemplateAssignmentComponent_For_30_div_25_Template, 11, 5, "div", 25)(26, WhatsappTemplateAssignmentComponent_For_30_div_26_Template, 10, 6, "div", 25)(27, WhatsappTemplateAssignmentComponent_For_30_div_27_Template, 10, 5, "div", 25)(28, WhatsappTemplateAssignmentComponent_For_30_Conditional_28_Template, 1, 0, "i", 26);
    \u0275\u0275elementEnd()();
  }
  if (rf & 2) {
    let tmp_13_0;
    let tmp_15_0;
    let tmp_16_0;
    let tmp_17_0;
    const assignment_r4 = ctx.$implicit;
    const i_r11 = ctx.$index;
    const ctx_r4 = \u0275\u0275nextContext();
    \u0275\u0275property("formGroupName", i_r11);
    \u0275\u0275advance(4);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(5, 8, "whatsapp_template"), " ");
    \u0275\u0275advance(5);
    \u0275\u0275repeater(ctx_r4.templateList);
    \u0275\u0275advance(2);
    \u0275\u0275property("ngIf", ((tmp_13_0 = assignment_r4.get("template_id")) == null ? null : tmp_13_0.invalid) && (((tmp_13_0 = assignment_r4.get("template_id")) == null ? null : tmp_13_0.touched) || ((tmp_13_0 = assignment_r4.get("template_id")) == null ? null : tmp_13_0.dirty)));
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(15, 10, "recipient_type"), " ");
    \u0275\u0275advance(11);
    \u0275\u0275property("ngIf", ((tmp_15_0 = assignment_r4.get("recipient_type")) == null ? null : tmp_15_0.value) === "tag");
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ((tmp_16_0 = assignment_r4.get("recipient_type")) == null ? null : tmp_16_0.value) === "user_id");
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ((tmp_17_0 = assignment_r4.get("recipient_type")) == null ? null : tmp_17_0.value) === "custom");
    \u0275\u0275advance();
    \u0275\u0275conditional(28, i_r11 > 0 ? 28 : -1);
  }
}
var _WhatsappTemplateAssignmentComponent = class _WhatsappTemplateAssignmentComponent {
  constructor(fb, translate, location, router, commonService, gridApiService, toastr, localStorageService) {
    this.fb = fb;
    this.translate = translate;
    this.location = location;
    this.router = router;
    this.commonService = commonService;
    this.gridApiService = gridApiService;
    this.toastr = toastr;
    this.localStorageService = localStorageService;
    this.whatsappTemplateProcessDetail = [];
    this.loading = false;
    this.recipientTags = [];
    this.templateList = [];
    this.userId = 0;
    this.options = [];
    this.form = this.fb.group({
      whatsapp_template_process: this.fb.group({
        whatsapp_template_process_id: [null, Validators.required]
      }),
      whatsapp_template_assignments: this.fb.array([])
    });
    const currentRoute = this.router.routerState.snapshot.url;
    this.whatsappTempAssignmentId = String(currentRoute.split("/")[currentRoute.split("/").length - 1]);
  }
  ngOnInit() {
    return __async(this, null, function* () {
      yield this.getWhatsappTemplateTag();
      yield this.getWhatsappTemplates();
      yield this.getWhatsappTemplateProcess();
      yield this.getTemplateAssignment();
      this.userId = this.localStorageService.getData("user_data") && JSON.parse(this.localStorageService.getData("user_data")).main.id;
    });
  }
  getWhatsappTemplateTag() {
    return __async(this, null, function* () {
      const payload = {
        company_id: 1,
        search_all: [
          {
            value: "3",
            operator: "!=",
            column_name: "whatsapp_template_recipient_tags.status_id"
          }
        ],
        limit_range: 1e3,
        print_query: true,
        start_index: 0,
        primary_table: "whatsapp_template_recipient_tags",
        select_columns: [["whatsapp_template_recipient_tags.id"], ["whatsapp_template_recipient_tags.slug"], ["whatsapp_template_recipient_tags.name"]]
      };
      this.commonService.getCommonList(payload).subscribe({
        next: (response) => {
          if (response.code === 200 && response.status) {
            this.loading = false;
            if (response.data.records) {
              response.data.records.forEach((each) => {
                this.recipientTags.push({
                  id: each.id,
                  name: each.name
                });
              });
            }
          }
        }
      });
    });
  }
  getWhatsappTemplates() {
    return __async(this, null, function* () {
      const payload = {
        includes: [
          {
            join_type: "INNER",
            table_name: "whatsapp_template_process",
            join_condition: "whatsapp_template_process.id = whatsapp_templates.whatsapp_template_process_id"
          }
        ],
        company_id: 1,
        search_all: [
          {
            value: "1",
            operator: "=",
            column_name: "whatsapp_templates.status_id"
          },
          {
            value: this.whatsappTempAssignmentId,
            operator: "=",
            column_name: "whatsapp_template_process.uuid"
          }
        ],
        limit_range: 1e3,
        print_query: false,
        start_index: 0,
        sort_columns: [["whatsapp_templates.name", "asc"]],
        primary_table: "whatsapp_templates",
        select_columns: [
          ["whatsapp_templates.id", "value"],
          ["whatsapp_templates.name", "label"]
        ]
      };
      this.commonService.getCommonList(payload).subscribe({
        next: (response) => {
          if (response.code === 200 && response.status) {
            if (response.data.records.length) {
              for (let each of response.data.records) {
                this.templateList.push({ label: each.label, value: each.value });
              }
            }
          }
        }
      });
    });
  }
  getWhatsappTemplateProcess() {
    return __async(this, null, function* () {
      const payload = {
        company_id: 1,
        search_all: [
          {
            value: "3",
            operator: "!=",
            column_name: "whatsapp_template_process.status_id"
          },
          {
            value: this.whatsappTempAssignmentId,
            operator: "=",
            column_name: "whatsapp_template_process.uuid"
          }
        ],
        limit_range: 1,
        print_query: true,
        start_index: 0,
        primary_table: "whatsapp_template_process",
        select_columns: [["whatsapp_template_process.id"], ["whatsapp_template_process.slug"]]
      };
      this.commonService.getCommonList(payload).subscribe({
        next: (response) => {
          if (response.code === 200 && response.status) {
            if (response.data.records.length) {
              this.whatsappTemplateProcessDetail.push({
                id: response.data.records[0].id,
                name: response.data.records[0].slug
              });
              this.form.controls["whatsapp_template_process"].setValue({ whatsapp_template_process_id: response.data.records[0].id });
            }
          }
        }
      });
    });
  }
  getTemplateAssignment() {
    return __async(this, null, function* () {
      const payload = {
        company_id: 1,
        includes: [
          {
            join_type: "INNER",
            table_name: "whatsapp_template_assignments",
            join_condition: "whatsapp_template_process.id = whatsapp_template_assignments.whatsapp_template_process_id"
          }
        ],
        search_all: [
          {
            value: this.whatsappTempAssignmentId,
            operator: "=",
            column_name: "whatsapp_template_process.uuid"
          },
          {
            value: "3",
            operator: "!=",
            column_name: "whatsapp_template_process.status_id"
          }
        ],
        limit_range: 1e3,
        print_query: true,
        start_index: 0,
        primary_table: "whatsapp_template_process",
        select_columns: [
          ["whatsapp_template_process.id"],
          ["whatsapp_template_process.slug"],
          ["whatsapp_template_assignments.id", "eta_id"],
          ["whatsapp_template_assignments.template_id"],
          ["whatsapp_template_assignments.recipient_type"],
          ["whatsapp_template_assignments.whatsapp_to"]
        ]
      };
      this.loading = true;
      this.commonService.getCommonList(payload).subscribe({
        next: (response) => {
          if (response.code === 200 && response.status) {
            this.loading = false;
            if (response.data.records) {
              if (response.data.records.length) {
                const lineItemsArray = this.form.get("whatsapp_template_assignments");
                let temp_assgn_ids = [];
                for (let each of response.data.records) {
                  lineItemsArray.push(this.fb.group({
                    id: each.eta_id,
                    recipient_type: [each.recipient_type, Validators.required],
                    whatsapp_to: [each.whatsapp_to, Validators.required],
                    template_id: [each.template_id, Validators.required],
                    whatsapp_template_assignment_id: [each.eta_id, Validators.required],
                    cc_bcc: this.fb.array([]),
                    whatsapp_tag_number: [null],
                    user_list: [null]
                  }));
                  if (each.recipient_type === "tag") {
                    this.getTemplateAssignmentTags(each.whatsapp_to, lineItemsArray.controls[lineItemsArray.length - 1]);
                  }
                  if (each.recipient_type === "user_id") {
                    this.getUsers(lineItemsArray.controls[lineItemsArray.length - 1], "");
                  }
                  temp_assgn_ids.push(each.eta_id);
                }
              } else {
                this.addWhatsappTemplateAssignment();
              }
            } else {
              const key = "failed_to_fetch_the_entity_details";
              const errorMessage = this.translate.instant(key);
              this.toastr.error(errorMessage, "Error");
            }
          } else {
            this.loading = false;
          }
        },
        error: (error) => {
          this.loading = false;
          console.error("Error fetching URL details:", error);
        }
      });
    });
  }
  getTemplateAssignmentTags(tagId, formGroup) {
    let payload = {
      company_id: 1,
      search_all: [
        {
          value: "3",
          operator: "!=",
          column_name: "whatsapp_template_recipient_tags.status_id"
        },
        {
          value: tagId,
          operator: "=",
          column_name: "whatsapp_template_recipient_tags.id"
        }
      ],
      search_any: [],
      limit_range: 1e3,
      print_query: true,
      start_index: 0,
      primary_table: "whatsapp_template_recipient_tags",
      select_columns: [
        ["whatsapp_template_recipient_tags.id"],
        ["whatsapp_template_recipient_tags.slug"],
        ["whatsapp_template_recipient_tags.query_information"]
      ]
    };
    this.commonService.getCommonList(payload).subscribe({
      next: (response) => {
        if (response.code === 200 && response.status) {
          if (response.data.records.length) {
            const query_information_string = response.data.records[0].query_information;
            const query_information = JSON.parse(query_information_string);
            if (query_information.search_all?.length) {
              query_information.search_all.forEach((each) => {
                if (each.value === "@process.user_id") {
                  each.value = this.userId;
                }
              });
            }
            console.log("query_information : ", query_information);
            this.commonService.getCommonList(query_information).subscribe({
              next: (response2) => {
                if (response2.data.records) {
                  let whatsappName = "";
                  if (response2.data.records.length) {
                    for (let each of response2.data.records) {
                      whatsappName = each.country_code + " " + each.phone_number;
                      formGroup.get("whatsapp_tag_number")?.setValue(whatsappName);
                    }
                  } else {
                    formGroup.get("whatsapp_tag_number")?.setValue("No phone number id is present");
                  }
                }
              }
            });
          }
        }
      }
    });
  }
  getTemplateAssignmentList() {
    const lineItemsArray = this.form.get("whatsapp_template_assignments");
    return lineItemsArray?.controls?.length ? lineItemsArray.controls : [];
  }
  addWhatsappTemplateAssignment() {
    const lineItemsArray = this.form.get("whatsapp_template_assignments");
    lineItemsArray.push(this.fb.group({
      id: [0],
      recipient_type: ["tag", Validators.required],
      whatsapp_to: [null, Validators.required],
      template_id: [null, Validators.required],
      whatsapp_template_assignment_id: [0],
      cc_bcc: this.fb.array([]),
      whatsapp_tag_number: [null],
      user_list: [null]
    }));
  }
  removeWhatsappTemplateAssignment(index) {
    const lineItemsArray = this.form.get("whatsapp_template_assignments");
    lineItemsArray.removeAt(index);
  }
  clearUserTagValues(formGroup) {
    formGroup.controls["whatsapp_to"].reset();
    formGroup.controls["whatsapp_tag_number"].reset();
    if (formGroup.controls["recipient_type"].value === "user_id") {
      this.getUsers(formGroup, "");
    }
  }
  getUsers(formGroup, pno) {
    let payload = {
      company_id: 1,
      includes: [
        {
          join_type: "INNER",
          table_name: "user_details",
          join_condition: "users.id = user_details.user_id"
        }
      ],
      limit_range: 25,
      print_query: false,
      start_index: 0,
      sort_columns: [["email", "asc"]],
      primary_table: "users",
      select_columns: [
        ["user_details.phone_number", "value"],
        ["concat(email, ' - ', user_details.phone_number)", "label"]
      ]
    };
    if (pno) {
      payload.search_all = [
        {
          value: "%" + pno + "%",
          operator: "ILIKE",
          column_name: "user_details.phone_number"
        }
      ];
    }
    this.commonService.getCommonList(payload).subscribe({
      next: (response) => {
        if (response.code === 200 && response.status) {
          if (response.data.records.length) {
            formGroup.get("user_list")?.setValue(response.data.records);
          }
        }
      }
    });
  }
  submit() {
    this.form.markAllAsTouched();
    if (this.form.valid) {
      let no_of_tables = 2;
      const payload = {
        data: {},
        table: ["whatsapp_template_process", "whatsapp_template_assignments"],
        action: ["select", "hard_delete"],
        columns: {
          table1: ["id"]
        },
        conditions: {
          table1: [
            {
              id: this.whatsappTemplateProcessDetail[0].id
            }
          ],
          table2: [
            {
              whatsapp_template_process_id: "@table1.id"
            }
          ]
        },
        table_mapping: ["table1", "table2"]
      };
      const lineItemsArray = this.form.get("whatsapp_template_assignments");
      for (let templates of lineItemsArray.controls) {
        no_of_tables++;
        payload.data["table" + no_of_tables] = [
          {
            whatsapp_to: templates.controls["whatsapp_to"].value,
            created_at: true,
            created_by: true,
            template_id: templates.controls["template_id"].value,
            recipient_type: templates.controls["recipient_type"].value,
            whatsapp_template_process_id: "@table1.id"
          }
        ];
        payload.action.push("insert");
        payload.table_mapping.push("table" + no_of_tables);
        payload.table.push("whatsapp_template_assignments");
      }
      this.gridApiService.executeRecords(payload).subscribe({
        next: (response) => {
          this.loading = false;
          if (response.code === 200 && response.status) {
            this.toastr.success("Record updated successfully", "Success");
          }
        }
      });
    } else {
      this.toastr.error("Enter all required fields", "Error");
    }
  }
};
_WhatsappTemplateAssignmentComponent.\u0275fac = function WhatsappTemplateAssignmentComponent_Factory(t) {
  return new (t || _WhatsappTemplateAssignmentComponent)(\u0275\u0275directiveInject(FormBuilder), \u0275\u0275directiveInject(TranslateService), \u0275\u0275directiveInject(Location), \u0275\u0275directiveInject(Router), \u0275\u0275directiveInject(MenuMapService), \u0275\u0275directiveInject(GridApiService), \u0275\u0275directiveInject(ToastrService), \u0275\u0275directiveInject(LocalStorageService));
};
_WhatsappTemplateAssignmentComponent.\u0275cmp = /* @__PURE__ */ \u0275\u0275defineComponent({ type: _WhatsappTemplateAssignmentComponent, selectors: [["app-whatsapp-template-assignment"]], standalone: true, features: [\u0275\u0275StandaloneFeature], decls: 31, vars: 10, consts: [[1, "panel"], [1, "mb-5", "flex", "flex-col", "items-start", "justify-between", "gap-3", "lg:flex-row", "lg:items-center"], [1, "text-lg", "font-semibold", "dark:text-white-light"], [1, "align-center", "flex", "gap-3"], ["appDynamicFontSize", "body", "type", "button", 1, "btn", "btn-danger", "mr-5", "ltr:rounded-r", "rtl:rounded-l", 3, "click"], ["type", "submit", 1, "btn", "btn-outline-secondary", "ng-tns-c3247919129-2", "text-xs", "ltr:rounded-r", "rtl:rounded-l", 3, "click"], [3, "formGroup"], ["formGroupName", "whatsapp_template_process", 1, "mb-5", "flex", "flex-col", "items-start", "justify-between", "gap-3", "lg:flex-row", "lg:items-center"], [1, "min-w-200-p"], [1, "form-group"], ["for", "whatsapp_template_process_id"], [1, "text-danger"], ["formControlName", "whatsapp_template_process_id", "required", "", 1, "form-select", "w-full", "py-1", "text-xs", "text-gray-700", "placeholder:text-white-dark", "dark:bg-gray-800", "dark:text-white-dark"], ["value", ""], [3, "value"], ["type", "button", 1, "hover:bg-primary-dark", "dark:bg-primary-dark", "dark:focus:ring-primary-dark", "flex", "w-40", "flex-row", "items-center", "justify-center", "gap-8", "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", 3, "click"], ["formArrayName", "whatsapp_template_assignments"], [1, "my-4", 3, "formGroupName"], [1, "grid", "grid-cols-4", "gap-3"], ["formControlName", "template_id", "required", "", 1, "form-select", "w-full", "py-1", "text-xs", "text-gray-700", "placeholder:text-white-dark", "dark:bg-gray-800", "dark:text-white-dark"], ["class", "invalid-feedback mt-1 text-danger", 4, "ngIf"], ["formControlName", "recipient_type", "required", "", 1, "form-select", "w-full", "py-1", "text-xs", "text-gray-700", "placeholder:text-white-dark", "dark:bg-gray-800", "dark:text-white-dark", 3, "change"], ["value", "tag"], ["value", "user_id"], ["value", "custom"], ["class", "form-group", 4, "ngIf"], [1, "fa-solid", "fa-xmark", "color-red", "mt-5", "cursor-pointer", "text-xl"], [1, "invalid-feedback", "mt-1", "text-danger"], ["formControlName", "whatsapp_to", "required", "", 1, "form-select", "w-full", "py-1", "text-xs", "text-gray-700", "placeholder:text-white-dark", "dark:bg-gray-800", "dark:text-white-dark", 3, "change"], ["class", "mt-5", 4, "ngIf"], [1, "mt-5"], ["bindLabel", "label", "bindValue", "value", "formControlName", "whatsapp_to", "placeholder", "Select User", 1, "custom-multiselect", "et-ng-select", 3, "search", "clear", "clearable", "searchable"], ["type", "tel", "formControlName", "whatsapp_to", "placeholder", "Enter whatsapp address", "required", "", 1, "form-control", "form-input", "w-full", "py-1", "text-xs", "text-gray-600", "placeholder:text-white-dark"], [1, "fa-solid", "fa-xmark", "color-red", "mt-5", "cursor-pointer", "text-xl", 3, "click"]], template: function WhatsappTemplateAssignmentComponent_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "div", 0)(1, "div", 1)(2, "h5", 2);
    \u0275\u0275text(3);
    \u0275\u0275pipe(4, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(5, "div", 3)(6, "button", 4);
    \u0275\u0275listener("click", function WhatsappTemplateAssignmentComponent_Template_button_click_6_listener() {
      return ctx.location.back();
    });
    \u0275\u0275text(7);
    \u0275\u0275pipe(8, "translate");
    \u0275\u0275elementEnd();
    \u0275\u0275elementStart(9, "button", 5);
    \u0275\u0275listener("click", function WhatsappTemplateAssignmentComponent_Template_button_click_9_listener() {
      return ctx.submit();
    });
    \u0275\u0275text(10, "Submit");
    \u0275\u0275elementEnd()()();
    \u0275\u0275elementStart(11, "div")(12, "form", 6)(13, "div", 7)(14, "div", 8)(15, "div", 9)(16, "label", 10);
    \u0275\u0275text(17);
    \u0275\u0275pipe(18, "translate");
    \u0275\u0275elementStart(19, "span", 11);
    \u0275\u0275text(20, "*");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(21, "select", 12)(22, "option", 13);
    \u0275\u0275text(23, "Please select");
    \u0275\u0275elementEnd();
    \u0275\u0275repeaterCreate(24, WhatsappTemplateAssignmentComponent_For_25_Template, 2, 2, "option", 14, \u0275\u0275repeaterTrackByIdentity);
    \u0275\u0275elementEnd()()();
    \u0275\u0275elementStart(26, "button", 15);
    \u0275\u0275listener("click", function WhatsappTemplateAssignmentComponent_Template_button_click_26_listener() {
      return ctx.addWhatsappTemplateAssignment();
    });
    \u0275\u0275text(27, " Add ");
    \u0275\u0275elementEnd()();
    \u0275\u0275elementStart(28, "div", 16);
    \u0275\u0275repeaterCreate(29, WhatsappTemplateAssignmentComponent_For_30_Template, 29, 12, "div", 17, \u0275\u0275repeaterTrackByIdentity);
    \u0275\u0275elementEnd()()()();
  }
  if (rf & 2) {
    \u0275\u0275advance(3);
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(4, 4, "whatsapp_template_assignment_form"), " ");
    \u0275\u0275advance(4);
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(8, 6, "back"), " ");
    \u0275\u0275advance(5);
    \u0275\u0275property("formGroup", ctx.form);
    \u0275\u0275advance(5);
    \u0275\u0275textInterpolate1("", \u0275\u0275pipeBind1(18, 8, "whatsapp_template_process"), " ");
    \u0275\u0275advance(7);
    \u0275\u0275repeater(ctx.whatsappTemplateProcessDetail);
    \u0275\u0275advance(5);
    \u0275\u0275repeater(ctx.getTemplateAssignmentList());
  }
}, dependencies: [FormlyModule, CommonSharedModule, NgIf, \u0275NgNoValidate, NgSelectOption, \u0275NgSelectMultipleOption, DefaultValueAccessor, SelectControlValueAccessor, NgControlStatus, NgControlStatusGroup, RequiredValidator, NgSelectComponent, NgOptionComponent, DynamicFontSizeDirective, TranslatePipe, FormlyBootstrapModule, ReactiveFormsModule, FormGroupDirective, FormControlName, FormGroupName, FormArrayName, FormlyConfigModule, FormsModule, CommonModule, NgSelectModule] });
var WhatsappTemplateAssignmentComponent = _WhatsappTemplateAssignmentComponent;
(() => {
  (typeof ngDevMode === "undefined" || ngDevMode) && \u0275setClassDebugInfo(WhatsappTemplateAssignmentComponent, { className: "WhatsappTemplateAssignmentComponent", filePath: "src\\app\\@lcp-framework\\pages\\whatsapp-template-assignment\\whatsapp-template-assignment.component.ts", lineNumber: 24 });
})();
export {
  WhatsappTemplateAssignmentComponent
};
//# sourceMappingURL=chunk-DBKBXQ5O.js.map
