import {
  DataTableComponent,
  ExportService
} from "./chunk-KV3IUGXW.js";
import "./chunk-TN2NHK56.js";
import "./chunk-TIV2UYBT.js";
import {
  jspdf_es_min_default,
  readSync,
  utils
} from "./chunk-YWQICJL7.js";
import "./chunk-LAL7OD5G.js";
import "./chunk-BP5JJWGC.js";
import "./chunk-IAAODDF7.js";
import "./chunk-2XS6LH2E.js";
import "./chunk-FXJXZPYD.js";
import "./chunk-NFRJCL7R.js";
import "./chunk-62OL73TD.js";
import "./chunk-IGGXREIH.js";
import {
  LoaderComponent
} from "./chunk-X5XWBDVM.js";
import {
  require_sweetalert2_all
} from "./chunk-KLTWPXW2.js";
import "./chunk-XKNDBYX7.js";
import {
  MenuMapService
} from "./chunk-3FLJCSSF.js";
import {
  ToastrService
} from "./chunk-2YLAF7RI.js";
import {
  CommonSharedModule,
  DynamicFontSizeDirective,
  NgxTippyDirective,
  Store,
  TimezoneService
} from "./chunk-7NQGM4EA.js";
import {
  FormBuilder,
  ReactiveFormsModule,
  TranslatePipe,
  TranslateService
} from "./chunk-NLYGDKUR.js";
import {
  animate,
  style,
  transition,
  trigger
} from "./chunk-ZEL7H2AL.js";
import {
  ActivatedRoute,
  GridApiService,
  LocalStorageService,
  Router,
  commonConfig
} from "./chunk-P7K2QEDI.js";
import {
  ChangeDetectorRef,
  DatePipe,
  HttpClientModule,
  NgClass,
  NgIf,
  Title,
  lastValueFrom,
  ɵsetClassDebugInfo,
  ɵɵProvidersFeature,
  ɵɵStandaloneFeature,
  ɵɵadvance,
  ɵɵclassMapInterpolate1,
  ɵɵdefineComponent,
  ɵɵdirectiveInject,
  ɵɵelement,
  ɵɵelementEnd,
  ɵɵelementStart,
  ɵɵgetCurrentView,
  ɵɵlistener,
  ɵɵloadQuery,
  ɵɵnextContext,
  ɵɵpipe,
  ɵɵpipeBind1,
  ɵɵproperty,
  ɵɵpureFunction2,
  ɵɵqueryRefresh,
  ɵɵresetView,
  ɵɵrestoreView,
  ɵɵtemplate,
  ɵɵtemplateRefExtractor,
  ɵɵtext,
  ɵɵtextInterpolate1,
  ɵɵviewQuery
} from "./chunk-GKZIWABI.js";
import {
  __async,
  __objRest,
  __spreadProps,
  __spreadValues,
  __toESM
} from "./chunk-CVWHNZRK.js";

// src/app/@lcp-framework/pages/child-process-setting/child-process-setting.component.ts
var import_sweetalert2 = __toESM(require_sweetalert2_all());
var _c0 = ["actionTemplate"];
var _c1 = ["statusTemplate"];
var _c2 = (a0, a1) => [a0, a1];
function ChildProcessSettingComponent_ng_template_2_a_3_Template(rf, ctx) {
  if (rf & 1) {
    const _r5 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "a", 11);
    \u0275\u0275listener("click", function ChildProcessSettingComponent_ng_template_2_a_3_Template_a_click_0_listener() {
      \u0275\u0275restoreView(_r5);
      const item_r3 = \u0275\u0275nextContext().$implicit;
      const ctx_r3 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r3.viewItem(item_r3));
    });
    \u0275\u0275element(1, "i");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const ctx_r3 = \u0275\u0275nextContext(2);
    \u0275\u0275advance();
    \u0275\u0275classMapInterpolate1("fa-regular fa-eye ", ctx_r3.store.fontsize === "large" ? "h-5.5 w-5.5" : ctx_r3.store.fontsize === "medium" ? "h-4.5 w-4.5" : "h-3.5 w-3.5", "");
  }
}
function ChildProcessSettingComponent_ng_template_2_a_4_Template(rf, ctx) {
  if (rf & 1) {
    const _r6 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "a", 12);
    \u0275\u0275listener("click", function ChildProcessSettingComponent_ng_template_2_a_4_Template_a_click_0_listener() {
      \u0275\u0275restoreView(_r6);
      const item_r3 = \u0275\u0275nextContext().$implicit;
      const ctx_r3 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r3.editItem(item_r3));
    });
    \u0275\u0275element(1, "i");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const ctx_r3 = \u0275\u0275nextContext(2);
    \u0275\u0275advance();
    \u0275\u0275classMapInterpolate1("fa-regular fa-pen-to-square ", ctx_r3.store.fontsize === "large" ? "h-5.5 w-5.5" : ctx_r3.store.fontsize === "medium" ? "h-4.5 w-4.5" : "h-3.5 w-3.5", "");
  }
}
function ChildProcessSettingComponent_ng_template_2_a_5_Template(rf, ctx) {
  if (rf & 1) {
    const _r7 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "a", 13);
    \u0275\u0275listener("click", function ChildProcessSettingComponent_ng_template_2_a_5_Template_a_click_0_listener() {
      \u0275\u0275restoreView(_r7);
      const item_r3 = \u0275\u0275nextContext().$implicit;
      const ctx_r3 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r3.deleteItem(item_r3));
    });
    \u0275\u0275element(1, "i");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const ctx_r3 = \u0275\u0275nextContext(2);
    \u0275\u0275advance();
    \u0275\u0275classMapInterpolate1("fa-regular fa-trash-can ", ctx_r3.store.fontsize === "large" ? "h-5.5 w-5.5" : ctx_r3.store.fontsize === "medium" ? "h-4.5 w-4.5" : "h-3.5 w-3.5", "");
  }
}
function ChildProcessSettingComponent_ng_template_2_Template(rf, ctx) {
  if (rf & 1) {
    const _r2 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 5)(1, "button", 6);
    \u0275\u0275listener("click", function ChildProcessSettingComponent_ng_template_2_Template_button_click_1_listener() {
      const item_r3 = \u0275\u0275restoreView(_r2).$implicit;
      const ctx_r3 = \u0275\u0275nextContext();
      return \u0275\u0275resetView(ctx_r3.executeChildProcess(item_r3));
    });
    \u0275\u0275element(2, "i", 7);
    \u0275\u0275elementEnd();
    \u0275\u0275template(3, ChildProcessSettingComponent_ng_template_2_a_3_Template, 2, 3, "a", 8)(4, ChildProcessSettingComponent_ng_template_2_a_4_Template, 2, 3, "a", 9)(5, ChildProcessSettingComponent_ng_template_2_a_5_Template, 2, 3, "a", 10);
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const item_r3 = ctx.$implicit;
    const ctx_r3 = \u0275\u0275nextContext();
    \u0275\u0275advance(3);
    \u0275\u0275property("ngIf", ctx_r3.masterInfo.permissions.details);
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ctx_r3.masterInfo.permissions.edit && ((ctx_r3.masterInfo == null ? null : ctx_r3.masterInfo.Listname) == "mrn_grid" ? (item_r3 == null ? null : item_r3.mrn_status) != "completed" : (ctx_r3.masterInfo == null ? null : ctx_r3.masterInfo.Listname) == "min_grid" ? (item_r3 == null ? null : item_r3.min_status) != "completed" : true));
    \u0275\u0275advance();
    \u0275\u0275property("ngIf", ctx_r3.masterInfo.permissions.delete);
  }
}
function ChildProcessSettingComponent_ng_template_4_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275elementStart(0, "span", 14);
    \u0275\u0275text(1);
    \u0275\u0275pipe(2, "translate");
    \u0275\u0275elementEnd();
  }
  if (rf & 2) {
    const item_r8 = ctx.$implicit;
    const ctx_r3 = \u0275\u0275nextContext();
    \u0275\u0275property("ngClass", \u0275\u0275pureFunction2(4, _c2, ctx_r3.store.fontsize === "large" ? "text-base" : ctx_r3.store.fontsize === "medium" ? "text-sm" : "text-xs", ctx_r3.statuses[item_r8.status] == null ? null : ctx_r3.statuses[item_r8.status].border_color));
    \u0275\u0275advance();
    \u0275\u0275textInterpolate1(" ", \u0275\u0275pipeBind1(2, 2, ctx_r3.statuses[item_r8.status].value), " ");
  }
}
function ChildProcessSettingComponent_app_loader_6_Template(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275element(0, "app-loader");
  }
}
var _ChildProcessSettingComponent = class _ChildProcessSettingComponent {
  constructor(toastr, gridApiService, route, cdr, datepipe, router, storeData, exportService, datePipe, translate, localStorageService, commonService, titleService, fb, timezoneService) {
    this.toastr = toastr;
    this.gridApiService = gridApiService;
    this.route = route;
    this.cdr = cdr;
    this.datepipe = datepipe;
    this.router = router;
    this.storeData = storeData;
    this.exportService = exportService;
    this.datePipe = datePipe;
    this.translate = translate;
    this.localStorageService = localStorageService;
    this.commonService = commonService;
    this.titleService = titleService;
    this.fb = fb;
    this.timezoneService = timezoneService;
    this.customTemplates = {};
    this.column = "";
    this.query = "";
    this.selectcolumns = [];
    this.headercolumns = [];
    this.headerColumnData = [];
    this.items = [];
    this.totalItems = 0;
    this.currentPage = 1;
    this.resultsPerPage = 10;
    this.enableCheckBox = false;
    this.policyData = null;
    this.loading = false;
    this.gridloading = true;
    this.title = "";
    this.listQuery = "";
    this.defaultQuery = "";
    this.attachedPolicies = [];
    this.submitted = false;
    this.selectedProcess = null;
    this.statuses = {
      1: {
        value: "table_status_val_0",
        border_color: "badge-outline-success"
      },
      2: {
        value: "table_status_val_1",
        border_color: "badge-outline-danger"
      },
      3: {
        value: "table_status_val_2",
        border_color: "badge-outline-secondary"
      }
    };
    this.initStore();
  }
  ngAfterViewInit() {
    this.config = JSON.parse(this.localStorageService.getData("config"));
    const pageInfo = this.route.snapshot.data["pageInfo"] || "";
    console.log(pageInfo);
    this.user_info = JSON.parse(this.localStorageService.getData("user_data"));
    this.resultsPerPage = parseInt(this.config.grid_pagination_default);
    this.grid_records_delete = this.config.grid_enable_associated_records_deletion;
    this.user_id = this.user_info.main?.id;
    if (pageInfo && this.resultsPerPage) {
      if (this.user_info.main?.policies) {
        this.policyData = this.user_info.main?.policies || null;
      }
      this.masterInfo = pageInfo;
      const masterListConfig = pageInfo;
      const translateTitle = this.translate.instant(masterListConfig.fullEntity);
      this.titleService.setTitle(translateTitle);
      this.enableCheckBox = masterListConfig.enable_row_checkbox;
      this.title = masterListConfig.fullEntity;
      this.setHeader();
      this.setDefaultQuery();
      this.listQuery.start_index = 0;
      this.fetchAttachedPolicies(this.listQuery);
    } else {
      this.title = "Default Title";
      this.headercolumns = [];
      this.items = [];
    }
    this.cdr.detectChanges();
  }
  ngOnDestroy() {
  }
  setHeader() {
    this.headerColumnData = [
      {
        header: "id",
        clause_type: "where",
        field_value: "child_processes.id",
        is_sortable: "false",
        column_order: "0.00",
        column_width: "1.00",
        is_searchable: "false",
        is_grid_column: "false"
      },
      {
        header: "uuid",
        clause_type: "where",
        field_value: "child_processes.uuid",
        is_sortable: "false",
        column_order: "0.00",
        column_width: "1.00",
        is_searchable: "false",
        is_grid_column: "false"
      },
      {
        header: "name",
        clause_type: "where",
        field_value: "child_processes.name",
        is_sortable: "true",
        column_order: "1.00",
        column_width: "1.00",
        is_searchable: "true",
        is_grid_column: "true"
      },
      {
        header: "slug",
        clause_type: "where",
        field_value: "child_processes.slug",
        is_sortable: "true",
        column_order: "2.00",
        column_width: "2.00",
        is_searchable: "true",
        is_grid_column: "true"
      },
      {
        header: "description",
        clause_type: "where",
        field_value: "child_processes.description",
        is_sortable: "true",
        column_order: "3.00",
        column_width: "1.00",
        is_searchable: "true",
        is_grid_column: "true"
      },
      {
        header: "command",
        clause_type: "where",
        field_value: "child_processes.command",
        is_sortable: "true",
        column_order: "4.00",
        column_width: "1.00",
        is_searchable: "true",
        is_grid_column: "true"
      },
      {
        header: "status",
        clause_type: "where",
        field_value: "child_processes.status_id",
        is_sortable: "true",
        column_order: "5.00",
        column_width: "1.00",
        is_searchable: "false",
        is_grid_column: "true"
      },
      {
        header: "created_at",
        clause_type: "where",
        field_value: "child_processes.created_at",
        is_sortable: "true",
        column_order: "6.00",
        column_width: "1.00",
        is_searchable: "false",
        is_grid_column: "true"
      }
    ];
  }
  setDefaultQuery() {
    this.defaultQuery = {
      print_query: true,
      company_id: 1,
      primary_table: "child_processes",
      start_index: 0,
      limit_range: 10,
      sort_columns: [["child_processes.id", "desc"]],
      group_by: [
        "child_processes.name",
        "child_processes.slug",
        "child_processes.description",
        "child_processes.command",
        "child_processes.id",
        "child_processes.created_at"
      ],
      includes: [],
      // having_conditions: null,
      // having_any_conditions: null,
      search_all: [
        {
          column_name: "child_processes.status_id",
          value: 3,
          operator: "!="
        }
      ],
      search_any: [],
      select_columns: [...this.headerColumnData.map((column) => [column.field_value, column.header])]
    };
    this.listQuery = JSON.parse(JSON.stringify(this.defaultQuery));
  }
  setActiveTab() {
    return __async(this, null, function* () {
      this.query = "";
      this.setHeader();
      this.setDefaultQuery();
      this.fetchData(this.listQuery);
      this.cdr.detectChanges();
    });
  }
  initStore() {
    return __async(this, null, function* () {
      this.storeData.select((d) => d.index).subscribe((d) => {
        this.store = d;
      });
    });
  }
  sortColumn(column) {
    this.column = column;
    this.listQuery.limit_range = this.resultsPerPage;
    this.listQuery.sort_columns = [[this.column.field_value, this.column.sortDirection]];
    this.fetchData(this.listQuery);
  }
  advancedSearchData(data) {
    const query = data.data;
    const uncleanedwhereConditions = query.filter((d) => !d.isAggregate);
    const whereConditions = uncleanedwhereConditions.map((_a) => {
      var _b = _a, { isAggregate } = _b, rest = __objRest(_b, ["isAggregate"]);
      return rest;
    });
    const uncleanedhavingConditions = query.filter((d) => d.isAggregate);
    const havingConditions = uncleanedhavingConditions.map((_c) => {
      var _d = _c, { isAggregate } = _d, rest = __objRest(_d, ["isAggregate"]);
      return rest;
    });
    const condition = data.condition;
    const clonedListQuery = this.listQuery;
    const orgListQuery = this.defaultQuery;
    if (whereConditions.length == 0 && havingConditions.length == 0) {
      if (condition == "AND") {
        clonedListQuery.search_all = [...orgListQuery.search_all];
      } else {
        clonedListQuery.search_any = [...orgListQuery.search_any];
      }
      this.fetchData(clonedListQuery);
      return;
    }
    if (havingConditions.length > 0) {
      if (condition == "AND") {
        clonedListQuery.having_conditions = [...havingConditions];
      } else {
        clonedListQuery.having_any_conditions = [...havingConditions];
      }
    }
    if (condition == "AND") {
      if (whereConditions.length === 1 && whereConditions[0].column_name === "") {
        clonedListQuery.search_all = [];
        clonedListQuery.search_all = [...orgListQuery.search_all];
      } else {
        clonedListQuery.search_all = [];
        clonedListQuery.search_all = [...orgListQuery.search_all, ...whereConditions];
      }
      clonedListQuery.start_index = 0;
      this.currentPage = 1;
      this.fetchData(clonedListQuery);
    } else {
      if (whereConditions.length === 1 && whereConditions[0].column_name === "") {
        clonedListQuery.search_any = [...clonedListQuery.search_any];
      } else {
        clonedListQuery.search_any = [...clonedListQuery.search_any, ...whereConditions];
      }
      clonedListQuery.start_index = 0;
      this.currentPage = 1;
      this.fetchData(clonedListQuery);
    }
  }
  searchData(input) {
    const clonedListQuery = this.listQuery;
    if (input.where.data.length) {
      const query = input.where.data;
      const search = input.where.search;
      if (search == "") {
        const orgListQuery = this.defaultQuery;
        clonedListQuery.search_any = [];
        clonedListQuery.search_any = [...orgListQuery.search_any];
        this.fetchData(clonedListQuery);
        return;
      }
      if (query.length === 1 && query[0].column_name === "") {
        clonedListQuery.search_any = [...clonedListQuery.search_any];
      } else {
        clonedListQuery.search_any = [...query];
      }
    }
    if (input.having.data.length) {
      const query = input.having.data;
      const search = input.having.search;
      if (search.length)
        clonedListQuery.having_any_conditions = [...query];
    }
    clonedListQuery.start_index = 0;
    this.currentPage = 1;
    this.fetchData(clonedListQuery);
  }
  exportTable(item) {
    if (this.masterInfo.permissions.export_excel) {
      this.loading = true;
      if (this.masterInfo.children.export_excel && this.masterInfo.children.export_excel.component_class_name == "export_module") {
        this.exportItem(item);
      } else {
        const query = __spreadValues({}, this.listQuery);
        query.limit_range = 1e6;
        const export_download = this.masterInfo?.Listname.replace("_grid", "") + "_table_data";
        this.gridApiService.getAllRecords(this.localStorageService.replaceUniqueId(this.localStorageService.formatPayloadWithPolicyConditions(query, this.policyData, this.attachedPolicies), "$session_user_id", this.user_info.main.id)).subscribe((response) => {
          if (response.status && response.code === 200) {
            if (response.data.records && response.data.headers) {
              const filteredData = this.filterAndTransformData(response.data.headers, response.data.records);
              if (item.type == "pdf") {
                this.exportService.exportToPDF(filteredData, export_download);
              } else {
                this.exportService.exportToExcel(filteredData, export_download);
              }
              this.loading = false;
            }
          } else {
            this.loading = false;
            this.items = [];
            this.totalItems = 0;
            const key = response.message;
            const errorMessage = this.translate.instant(key);
            this.toastr.error(errorMessage, "Error");
          }
        }, (error) => {
          this.loading = false;
          const key = "error";
          const errorMessage = this.translate.instant(key);
          this.toastr.error(errorMessage, "Error");
        });
      }
    }
  }
  filterAndTransformData(headers, records) {
    const filteredHeaders = headers.filter((header) => header.header !== "id" && header.header !== "uuid");
    const transformedRecords = records.map((record) => {
      const transformedRecord = {};
      filteredHeaders.forEach((header) => {
        const translationKey = `${header.header}`;
        const translatedHeader = this.translate.instant(translationKey);
        if (header.field_type_id == "5") {
          transformedRecord[translatedHeader] = this.timezoneService.transformDateOnly(record[header.header]);
        } else if (header.field_type_id == "7") {
          transformedRecord[translatedHeader] = this.timezoneService.transformDateTime(record[header.header]);
        } else if (header.header == "status") {
          transformedRecord[translatedHeader] = this.getStatusTranslation(record[header.header]);
        } else {
          transformedRecord[translatedHeader] = record[header.header];
        }
      });
      return transformedRecord;
    });
    return transformedRecords;
  }
  getStatusTranslation(status) {
    return this.translate.instant(this.statuses[status].value);
  }
  fetchAttachedPolicies(params) {
    this.gridApiService.getAttachedPolicies({ entity_name: params.primary_table }).subscribe((response) => {
      if (response.status && response.code === 200) {
        this.attachedPolicies = response.data.attached_policies || [];
      }
    }, (error) => {
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    }, () => {
      this.fetchColumns();
      this.fetchData(this.listQuery);
    });
  }
  fetchColumns() {
    const data = [
      {
        order_no: 1,
        status_id: 1,
        company_id: 1,
        field: "child_processes.name",
        clause_type: "where",
        sorting: true,
        title: this.translate.instant("name"),
        field_type_id: 3,
        searchable: true,
        is_grid_column: true,
        enable: true
      },
      {
        order_no: 2,
        status_id: 1,
        company_id: 1,
        field: "child_processes.description",
        clause_type: "where",
        sorting: true,
        title: this.translate.instant("description"),
        field_type_id: 3,
        searchable: true,
        is_grid_column: true,
        enable: true
      },
      {
        order_no: 3,
        status_id: 1,
        company_id: 1,
        field: "child_processes.command",
        clause_type: "where",
        sorting: true,
        title: this.translate.instant("command"),
        field_type_id: 3,
        searchable: true,
        is_grid_column: true,
        enable: true
      }
    ];
    this.selectcolumns = [
      {
        field: "S.No",
        title: "S.No",
        sorting: false,
        searchable: false,
        enable: false,
        field_type_id: 1
      },
      ...data,
      {
        field: "Status",
        title: "Status",
        sorting: false,
        searchable: false,
        enable: false,
        field_type_id: 1
      },
      {
        field: "Action",
        title: "Action",
        sorting: false,
        searchable: false,
        enable: false,
        field_type_id: 0
      }
    ];
  }
  fetchData(params) {
    params.limit_range = this.resultsPerPage;
    const payload = this.localStorageService.replaceUniqueId(this.localStorageService.formatPayloadWithPolicyConditions(params, this.policyData, this.attachedPolicies), "$session_user_id", this.user_info.main.id);
    this.commonService.getCommonList(payload).subscribe((response) => {
      if (response.status && response.code === 200) {
        const data = this.headerColumnData.filter((key) => key.is_grid_column == "true").map((key) => __spreadProps(__spreadValues({}, key), {
          column_width: "40px"
        }));
        const isOnlyViewOrViewExport = (!this.masterInfo.permissions.export_excel || this.masterInfo.permissions.export_excel === true) && (!this.masterInfo.permissions.create || this.masterInfo.permissions.create === true) && Object.keys(this.masterInfo.permissions).every((key) => key === "export_excel" || key === "create" || this.masterInfo.permissions[key] === false);
        if (this.config.grid_show_serial_number == "true") {
          this.headercolumns = [
            {
              header: "table_column_sno",
              field_value: "S.No",
              is_sortable: "false",
              column_order: "0.00",
              column_width: "40px",
              is_searchable: "false",
              is_grid_column: "true"
            },
            ...data
          ];
          if (!isOnlyViewOrViewExport) {
            this.headercolumns.push({
              header: "table_column_action",
              field_value: "Action",
              is_sortable: "false",
              column_order: "0.00",
              column_width: "50px",
              is_searchable: "false",
              is_grid_column: "true"
            });
          }
        } else {
          this.headercolumns = [...data];
          this.headercolumns.push({
            header: "table_column_action",
            field_value: "Action",
            is_sortable: "false",
            column_order: "0.00",
            column_width: "50px",
            is_searchable: "false",
            is_grid_column: "true"
          });
        }
        this.headercolumns = this.headercolumns.map((item) => {
          if (item.header === "status") {
            return __spreadProps(__spreadValues({}, item), {
              customTemplate: this.statusTemplate
            });
          } else if (item.header === "table_column_action") {
            return __spreadProps(__spreadValues({}, item), {
              customTemplate: this.actionTemplate
            });
          } else {
            return __spreadValues({}, item);
          }
        });
        if (response.data.records) {
          this.items = response.data.records.map((item, index) => {
            const formattedItem = __spreadValues({}, item);
            for (const key in formattedItem) {
              if (formattedItem.hasOwnProperty(key) && (key.toLowerCase().includes("date") || key.toLowerCase().includes("deleted_at") || key.toLowerCase().includes("created_at") || key.toLowerCase().includes("updated_at")) && this.isDate(formattedItem[key])) {
                const transformedDate = this.timezoneService.transformDateTime(formattedItem[key]);
                if (transformedDate) {
                  formattedItem[key] = transformedDate;
                }
              }
            }
            if (this.config.grid_show_serial_number == "true") {
              return __spreadProps(__spreadValues({
                table_column_sno: this.listQuery.start_index + index + 1
              }, formattedItem), {
                Action: index + 1
              });
            }
            return __spreadProps(__spreadValues({}, formattedItem), {
              Action: index + 1
            });
          });
          this.totalItems = response.data.total_records;
          this.gridloading = false;
        } else {
          this.items = [];
          this.totalItems = 0;
          this.gridloading = false;
        }
      } else {
        this.items = [];
        this.totalItems = 0;
        this.gridloading = false;
        const key = response.message;
        const errorMessage = this.translate.instant(key);
        this.toastr.error(errorMessage, "Error");
      }
    }, (error) => {
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
      this.gridloading = false;
    });
  }
  isDate(value) {
    return !isNaN(Date.parse(value));
  }
  formatDate(value) {
    return this.timezoneService.transformDateOnly(value);
  }
  capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
  }
  handleCustomAction(action) {
    if (action === "addNew" && this.masterInfo.children.add) {
      this.router.navigate([`${this.masterInfo.children.add.target}`]);
    }
  }
  exportItem(item) {
    if (this.masterInfo.children.export_excel) {
      this.gridApiService.exportAllRecords(this.masterInfo.children.export_excel.id).subscribe({
        next: (response) => {
          try {
            const blob = new Blob([response.blob], {
              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            });
            if (item.type === "excel") {
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement("a");
              link.href = url;
              link.download = response.fileName;
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
              window.URL.revokeObjectURL(url);
              this.loading = false;
            } else if (item.type === "pdf") {
              this.convertExcelToPDF(blob, response.fileName.replace(".xlsx", ".pdf"));
              this.loading = false;
            }
          } catch (err) {
            this.loading = false;
            console.error("Download error:", err);
            this.toastr.error("Error downloading file");
          }
        },
        error: (error) => {
          this.loading = false;
          console.error("Export error:", error);
          this.toastr.error("Error exporting data");
        }
      });
    }
  }
  convertExcelToPDF(blob, pdfFileName) {
    const reader = new FileReader();
    reader.onload = (event) => {
      const data = new Uint8Array(event.target.result);
      const workbook = readSync(data, { type: "array" });
      const firstSheetName = workbook.SheetNames[0];
      const worksheet = workbook.Sheets[firstSheetName];
      const sheetData = utils.sheet_to_json(worksheet, { header: 1 });
      const doc = new jspdf_es_min_default();
      let y = 10;
      sheetData.forEach((row) => {
        const rowText = row.join("  ");
        doc.text(rowText, 10, y);
        y += 10;
      });
      doc.save(pdfFileName);
    };
    reader.readAsArrayBuffer(blob);
  }
  commonTranslate(msg) {
    return this.translate.instant(msg);
  }
  directDeleteItem(item) {
    import_sweetalert2.default.fire({
      icon: "warning",
      title: "Are you sure?",
      text: "You won't be able to revert this!",
      showCancelButton: true,
      confirmButtonText: "Delete",
      padding: "2em"
    }).then((result) => __async(this, null, function* () {
      if (result.value) {
        try {
          const jobResponse = yield this.localStorageService.getMasterEntity({
            record_info: item,
            entity_name: this.masterInfo.children.delete.entity_name,
            entity_type: this.masterInfo.children.delete.component_class_name
          });
          if (jobResponse) {
            yield this.executeJob(__spreadProps(__spreadValues({}, jobResponse), { record_info: item }));
            import_sweetalert2.default.fire({ title: "Deleted!", text: "Your file has been deleted.", icon: "success" });
            this.fetchData(this.listQuery);
          }
        } catch (error) {
          const key = "error";
          const errorMessage = this.translate.instant(key);
          this.toastr.error(errorMessage, error.message);
        }
      }
    }));
  }
  deleteItem(item) {
    if (this.masterInfo.children.delete && this.masterInfo.children.delete.component_class_name === commonConfig.ENTITY_TYPES.JOB_BUILDER_MODULE) {
      if (this.grid_records_delete == "true") {
        const procedureParams = { proc_name: "check_for_related_records", params: { entity_name: this.listQuery.entity_name, record_id: item.id } };
        this.commonService.procedureCall(procedureParams).subscribe({
          next: (response) => {
            if (response.code === 200 && response.status && response.data) {
              const res = response.data?.[0]?.result || [];
              if (Object.keys(res).length > 0) {
                let htmlInput = `
                    <span>` + this.commonTranslate("config_delete_msg_0") + `</span><br><br>
                    <table style="width: 100%; text-align: center; border-collapse: collapse;">
                    <thead>
                      <tr>
                        <th style="border: 1px solid #ddd; padding: 8px;">` + this.commonTranslate("config_delete_msg_1") + `</th>
                        <th style="border: 1px solid #ddd; padding: 8px;">` + this.commonTranslate("config_delete_msg_2") + `</th>
                      </tr> </thead><tbody>
                  `;
                Object.entries(res).forEach(([key, value]) => {
                  htmlInput += `
                      <tr>
                        <td style="border: 1px solid #ddd; padding: 8px;">${key}</td>
                        <td style="border: 1px solid #ddd; padding: 8px;">${value}</td>
                      </tr>
                    `;
                });
                htmlInput += `</tbody></table>`;
                import_sweetalert2.default.fire({
                  title: `<span style="color: orange;">` + this.commonTranslate("config_delete_msg_3") + `!</span>`,
                  html: htmlInput,
                  customClass: {
                    title: "swal-title"
                  }
                });
              } else {
                this.directDeleteItem(item);
              }
            } else {
              const key = "error";
              const errorMessage = this.translate.instant(key);
              this.toastr.error(errorMessage, "Error");
            }
          },
          error: (error) => {
            console.error("Error fetching data:", error);
          },
          complete: () => {
          }
        });
      } else {
        this.directDeleteItem(item);
      }
    }
  }
  executeJob(inputObject) {
    return __async(this, null, function* () {
      if (inputObject.record_info.id) {
        const job_query_information = this.localStorageService.replaceUniqueId(inputObject.query_information, "$unique_id", inputObject.record_info.id);
        try {
          const response = yield lastValueFrom(this.gridApiService.executeTransaction(job_query_information));
          if (!response.status) {
            throw new Error(response.message);
          }
        } catch (error) {
          throw error;
        }
      }
    });
  }
  viewItem(item) {
    if (this.masterInfo.children.details) {
      const targetRoute = this.masterInfo.children.details.target.replace(":uuid", item.uuid);
      this.router.navigate([targetRoute]);
    }
  }
  editItem(item) {
    if (this.masterInfo.children.edit) {
      const targetRoute = this.masterInfo.children.edit.target.replace(":id", item.uuid);
      this.router.navigate([targetRoute]);
    }
  }
  navigateToDetailPage(item) {
    const fullUrl = `${item.url}${item.screen_id}`;
    window.open(fullUrl, "_blank");
  }
  onPageChange(event) {
    this.currentPage = event.page;
    this.listQuery.start_index = event.start_index;
    this.listQuery.limit_range = this.resultsPerPage;
    this.fetchData(this.listQuery);
  }
  onResultsPerPageChange(event) {
    this.currentPage = 1;
    this.resultsPerPage = event.resultsPerPage;
    this.listQuery.start_index = event.start_index;
    this.listQuery.limit_range = event.resultsPerPage;
    this.fetchData(this.listQuery);
  }
  executeChildProcess(item) {
    this.loading = true;
    this.gridApiService.executeChildProcess(item.id).subscribe((response) => {
      this.loading = false;
      if (response.status) {
        this.toastr.success(response.message, "Success");
      } else {
        console.error("Error: Operation failed with response:", response);
        this.toastr.error(response.message, "Error");
      }
    }, (error) => {
      this.loading = false;
      console.error("Error executing child process:", error);
      const key = "error";
      const errorMessage = this.translate.instant(key);
      this.toastr.error(errorMessage, "Error");
    });
  }
};
_ChildProcessSettingComponent.\u0275fac = function ChildProcessSettingComponent_Factory(t) {
  return new (t || _ChildProcessSettingComponent)(\u0275\u0275directiveInject(ToastrService), \u0275\u0275directiveInject(GridApiService), \u0275\u0275directiveInject(ActivatedRoute), \u0275\u0275directiveInject(ChangeDetectorRef), \u0275\u0275directiveInject(DatePipe), \u0275\u0275directiveInject(Router), \u0275\u0275directiveInject(Store), \u0275\u0275directiveInject(ExportService), \u0275\u0275directiveInject(DatePipe), \u0275\u0275directiveInject(TranslateService), \u0275\u0275directiveInject(LocalStorageService), \u0275\u0275directiveInject(MenuMapService), \u0275\u0275directiveInject(Title), \u0275\u0275directiveInject(FormBuilder), \u0275\u0275directiveInject(TimezoneService));
};
_ChildProcessSettingComponent.\u0275cmp = /* @__PURE__ */ \u0275\u0275defineComponent({ type: _ChildProcessSettingComponent, selectors: [["app-child-process-setting"]], viewQuery: function ChildProcessSettingComponent_Query(rf, ctx) {
  if (rf & 1) {
    \u0275\u0275viewQuery(_c0, 5);
    \u0275\u0275viewQuery(_c1, 5);
  }
  if (rf & 2) {
    let _t;
    \u0275\u0275queryRefresh(_t = \u0275\u0275loadQuery()) && (ctx.actionTemplate = _t.first);
    \u0275\u0275queryRefresh(_t = \u0275\u0275loadQuery()) && (ctx.statusTemplate = _t.first);
  }
}, standalone: true, features: [\u0275\u0275ProvidersFeature([DatePipe]), \u0275\u0275StandaloneFeature], decls: 7, vars: 14, consts: [["actionTemplate", ""], ["statusTemplate", ""], [1, "flex-1", "p-3", "pt-6"], [3, "delete", "edit", "view", "customAction", "pageChange", "resultsPerPageChange", "columnSort", "searchQuery", "exportType", "advancedSearchQuery", "loading", "masterInfo", "enableCheckBox", "customTemplates", "headercolumns", "selectcolumns", "items", "totalItems", "currentPage", "resultsPerPage", "column", "title", "query"], [4, "ngIf"], [1, "flex", "items-center", "gap-4"], ["ngxTippy", "", "data-tippy-content", "Execute", "appDynamicFontSize", "body", "type", "button", 3, "click"], [1, "fa-solid", "fa-play", "text-success"], ["href", "javascript:void(0);", "class", "hover:text-primary", "ngxTippy", "", "data-tippy-content", "Details", "appDynamicFontSize", "body", 3, "click", 4, "ngIf"], ["href", "javascript:void(0);", "class", "hover:text-info", "appDynamicFontSize", "body", "ngxTippy", "", "data-tippy-content", "Edit", 3, "click", 4, "ngIf"], ["href", "javascript:void(0);", "class", "hover:text-primary", "appDynamicFontSize", "body", "ngxTippy", "", "data-tippy-content", "Delete", 3, "click", 4, "ngIf"], ["href", "javascript:void(0);", "ngxTippy", "", "data-tippy-content", "Details", "appDynamicFontSize", "body", 1, "hover:text-primary", 3, "click"], ["href", "javascript:void(0);", "appDynamicFontSize", "body", "ngxTippy", "", "data-tippy-content", "Edit", 1, "hover:text-info", 3, "click"], ["href", "javascript:void(0);", "appDynamicFontSize", "body", "ngxTippy", "", "data-tippy-content", "Delete", 1, "hover:text-primary", 3, "click"], [1, "badge", 3, "ngClass"]], template: function ChildProcessSettingComponent_Template(rf, ctx) {
  if (rf & 1) {
    const _r1 = \u0275\u0275getCurrentView();
    \u0275\u0275elementStart(0, "div", 2)(1, "app-datatable", 3);
    \u0275\u0275listener("delete", function ChildProcessSettingComponent_Template_app_datatable_delete_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.deleteItem($event));
    })("edit", function ChildProcessSettingComponent_Template_app_datatable_edit_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.editItem($event));
    })("view", function ChildProcessSettingComponent_Template_app_datatable_view_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.viewItem($event));
    })("customAction", function ChildProcessSettingComponent_Template_app_datatable_customAction_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.handleCustomAction($event));
    })("pageChange", function ChildProcessSettingComponent_Template_app_datatable_pageChange_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.onPageChange($event));
    })("resultsPerPageChange", function ChildProcessSettingComponent_Template_app_datatable_resultsPerPageChange_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.onResultsPerPageChange($event));
    })("columnSort", function ChildProcessSettingComponent_Template_app_datatable_columnSort_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.sortColumn($event));
    })("searchQuery", function ChildProcessSettingComponent_Template_app_datatable_searchQuery_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.searchData($event));
    })("exportType", function ChildProcessSettingComponent_Template_app_datatable_exportType_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.exportTable($event));
    })("advancedSearchQuery", function ChildProcessSettingComponent_Template_app_datatable_advancedSearchQuery_1_listener($event) {
      \u0275\u0275restoreView(_r1);
      return \u0275\u0275resetView(ctx.advancedSearchData($event));
    });
    \u0275\u0275elementEnd();
    \u0275\u0275template(2, ChildProcessSettingComponent_ng_template_2_Template, 6, 3, "ng-template", null, 0, \u0275\u0275templateRefExtractor)(4, ChildProcessSettingComponent_ng_template_4_Template, 3, 7, "ng-template", null, 1, \u0275\u0275templateRefExtractor);
    \u0275\u0275elementEnd();
    \u0275\u0275template(6, ChildProcessSettingComponent_app_loader_6_Template, 1, 0, "app-loader", 4);
  }
  if (rf & 2) {
    \u0275\u0275advance();
    \u0275\u0275property("loading", ctx.gridloading)("masterInfo", ctx.masterInfo)("enableCheckBox", ctx.enableCheckBox)("customTemplates", ctx.customTemplates)("headercolumns", ctx.headercolumns)("selectcolumns", ctx.selectcolumns)("items", ctx.items)("totalItems", ctx.totalItems)("currentPage", ctx.currentPage)("resultsPerPage", ctx.resultsPerPage)("column", ctx.column)("title", ctx.title)("query", ctx.query);
    \u0275\u0275advance(5);
    \u0275\u0275property("ngIf", ctx.loading);
  }
}, dependencies: [CommonSharedModule, NgClass, NgIf, NgxTippyDirective, DynamicFontSizeDirective, TranslatePipe, HttpClientModule, DataTableComponent, LoaderComponent, ReactiveFormsModule], data: { animation: [
  trigger("toggleAnimation", [
    transition(":enter", [style({ opacity: 0, transform: "scale(0.95)" }), animate("100ms ease-out", style({ opacity: 1, transform: "scale(1)" }))]),
    transition(":leave", [animate("75ms", style({ opacity: 0, transform: "scale(0.95)" }))])
  ])
] } });
var ChildProcessSettingComponent = _ChildProcessSettingComponent;
(() => {
  (typeof ngDevMode === "undefined" || ngDevMode) && \u0275setClassDebugInfo(ChildProcessSettingComponent, { className: "ChildProcessSettingComponent", filePath: "src\\app\\@lcp-framework\\pages\\child-process-setting\\child-process-setting.component.ts", lineNumber: 59 });
})();
export {
  ChildProcessSettingComponent
};
//# sourceMappingURL=chunk-XR4MGT7Z.js.map
