<template>
  <Filters
    :report-button="true"
    @reset-form="data = []"
    @run-search="() => filterData(filters)"
    @run-report="() => exportToPDF(reportMeta, data, true)"
    class="mb-4"
  >
    <Type1 @update:filters="(value) => (filters = value)" />
  </Filters>

  <div id="data">
    <DxDataGrid
      @cell-click="onCellClicked"
      ref="dataGridRef"
      :allow-column-reordering="true"
      class="max-h-[calc(100vh-140px)] mb-10"
      :data-source="data"
      v-if="loadingData == false"
      :show-column-lines="true"
      :show-row-lines="false"
      :show-borders="true"
      :row-alternation-enabled="true"
      :hover-state-enabled="true"
      @selection-changed="onDataSelectionChanged"
      @exporting="onExporting"
      :allow-column-resizing="true"
      column-resizing-mode="widget"
    >
      <DxGrouping :auto-expand-all="false" :context-menu-enabled="true" />
      <DxSelection mode="single" />
      <!--  -->
      <DxSearchPanel :visible="true" :highlight-case-sensitive="true" />
      <DxExport
        :enabled="true"
        :formats="['pdf', 'xlsx', 'document']"
        :allow-export-selected-data="false"
      />
      <!-- <DxColumn
        css-class="custom-table-column"
        :width="50"
        alignment="center"
        :calculate-display-value="(item: any) => data.findIndex((i) => i == item) + 1"
        data-type="number"
        caption="No"
        cell-template="formatNumber"
      /> -->
      <DxColumn
        :width="150"
        alignment="center"
        data-field="nama_posko"
        caption="Nama Unit"
        css-class="custom-table-column"
        cell-template="formatText"
      />

      <DxColumn
        v-if="grouping.length > 0"
        v-for="(group, index) in grouping"
        :width="150"
        alignment="center"
        :data-field="group.data"
        :caption="group.caption"
        css-class="custom-table-column"
        cell-template="formatText"
        :group-index="index"
      />

      <DxColumn
        :width="150"
        alignment="center"
        data-field="total"
        data-type="number"
        caption="Total"
        :allow-resizing="false"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="150"
        alignment="center"
        data-field="total_selesai"
        caption="Selesai"
        :allow-resizing="false"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="70"
        alignment="center"
        data-field="persen_selesai"
        data-type="number"
        caption="%"
        :allow-resizing="false"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="150"
        alignment="center"
        data-field="total_inproses"
        data-type="number"
        caption="In Progress"
        :allow-resizing="false"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="70"
        alignment="center"
        data-field="persen_inproses"
        data-type="number"
        caption="%"
        :allow-resizing="false"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn alignment="center" caption="Dispatching Time" css-class="custom-table-column">
        <DxColumn
          :width="150"
          alignment="center"
          data-field="avg_durasi_dispatch"
          data-type="number"
          caption="Rata-Rata"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatDPT"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-field="count_durasi_dispatch"
          data-type="number"
          caption="Jumlah Dispatch"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-type="number"
          caption="Total Durasi Dispatch"
          name="total_durasi_dispatch"
          :allow-resizing="false"
          css-class="custom-table-column"
          :calculate-display-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_dispatch) * parseFloat(rowData.avg_durasi_dispatch)
          "
          :calculate-cell-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_dispatch) * parseFloat(rowData.avg_durasi_dispatch)
          "
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="max_durasi_dispatch"
          data-type="number"
          caption="Max"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="min_durasi_dispatch"
          data-type="number"
          caption="Min"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_diatas_sla_dispatch"
          data-type="number"
          caption=">SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_dibawah_sla_dispatch"
          data-type="number"
          caption="≤SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
      </DxColumn>
      <DxColumn alignment="center" caption="Response Time" css-class="custom-table-column">
        <DxColumn
          :width="150"
          alignment="center"
          data-field="avg_durasi_response"
          data-type="number"
          caption="Rata-Rata"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatRPT"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-field="count_durasi_response"
          data-type="number"
          caption="Jumlah Response"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-type="number"
          caption="Total Durasi Response"
          name="total_durasi_response"
          :allow-resizing="false"
          css-class="custom-table-column"
          :calculate-display-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_response) * parseFloat(rowData.avg_durasi_response)
          "
          :calculate-cell-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_response) * parseFloat(rowData.avg_durasi_response)
          "
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="max_durasi_response"
          data-type="number"
          caption="Max"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="min_durasi_response"
          data-type="number"
          caption="Min"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_diatas_sla_response"
          data-type="number"
          caption=">SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_dibawah_sla_response"
          data-type="number"
          caption="≤SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
      </DxColumn>
      <DxColumn alignment="center" caption="Recovery Time" css-class="custom-table-column">
        <DxColumn
          :width="150"
          alignment="center"
          data-field="avg_durasi_recovery"
          data-type="number"
          caption="Rata-Rata"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatRCT"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-field="count_durasi_recovery"
          data-type="number"
          caption="Jumlah Recovery"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :visible="false"
          :width="150"
          alignment="center"
          data-type="number"
          caption="Total Durasi Recovery"
          name="total_durasi_recovery"
          :allow-resizing="false"
          css-class="custom-table-column"
          :calculate-display-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_recovery) * parseFloat(rowData.avg_durasi_recovery)
          "
          :calculate-cell-value="
            (rowData: any) =>
              parseFloat(rowData.count_durasi_recovery) * parseFloat(rowData.avg_durasi_recovery)
          "
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="max_durasi_recovery"
          data-type="number"
          caption="Max"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="min_durasi_recovery"
          data-type="number"
          caption="Min"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatTime"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_diatas_sla_recovery"
          data-type="number"
          caption=">SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :width="150"
          alignment="center"
          data-field="total_dibawah_sla_recovery"
          data-type="number"
          caption="≤SLA"
          :allow-resizing="false"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
      </DxColumn>

      <DxSummary :calculate-custom-summary="calculateCustomSummary">
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total"
          name="total"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_selesai"
          name="total_selesai"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="persen_selesai"
          name="persen_selesai"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_inproses"
          name="total_inproses"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="persen_inproses"
          name="persen_inproses"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="avg_durasi_dispatch"
          name="avg_durasi_dispatch"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_durasi_dispatch"
          name="total_durasi_dispatch"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="count_durasi_dispatch"
          name="count_durasi_dispatch"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />

        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="max_durasi_dispatch"
          summary-type="max"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="min_durasi_dispatch"
          summary-type="min"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_diatas_sla_dispatch"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_dibawah_sla_dispatch"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="avg_durasi_response"
          name="avg_durasi_response"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_durasi_response"
          name="total_durasi_response"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="count_durasi_response"
          name="count_durasi_response"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="max_durasi_response"
          summary-type="max"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="min_durasi_response"
          summary-type="min"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_diatas_sla_response"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_dibawah_sla_response"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="avg_durasi_recovery"
          name="avg_durasi_recovery"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_durasi_recovery"
          name="total_durasi_recovery"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="count_durasi_recovery"
          name="count_durasi_recovery"
          summary-type="custom"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="max_durasi_recovery"
          summary-type="max"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="min_durasi_recovery"
          summary-type="min"
          css-class="!text-center"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_diatas_sla_recovery"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          :show-in-group-footer="false"
          :align-by-column="true"
          column="total_dibawah_sla_recovery"
          summary-type="sum"
          css-class="!text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
      </DxSummary>

      <template #formatText="{ data }">
        <p class="text-left cursor-pointer" @click="setDialogStatus(data.column.caption)">
          {{ data.text }}
        </p>
      </template>

      <template #formatNumber="{ data }">
        <p class="text-right cursor-pointer" @click="setDialogStatus(data.column.caption)">
          {{
            isNumber(data.text)
              ? data.column.caption == '%'
                ? formatPercentage(data.text)
                : formatNumber(data.text)
              : data.text
          }}
        </p>
      </template>

      <template #formatTime="{ data }">
        <p class="cursor-pointer" @click="setDialogStatus(data.column.caption)">
          {{ parseInt(data.text) ? formatWaktu(data.text) : '-' }}
        </p>
      </template>

      <template #formatDPT="{ data }">
        <p
          class="text-right cursor-pointer"
          :class="[data.text < 5 ? 'text-green-500' : 'text-red-500']"
          @click="setDialogStatus(data.column.caption)"
        >
          {{
            isNumber(data.text)
              ? data.column.caption == '%'
                ? formatPercentage(data.text)
                : formatNumber(data.text)
              : data.text
          }}
        </p>
      </template>

      <template #formatRPT="{ data }">
        <p
          class="text-right cursor-pointer"
          :class="[data.text < 45 ? 'text-green-500' : 'text-red-500']"
          @click="setDialogStatus(data.column.caption)"
        >
          {{
            isNumber(data.text)
              ? data.column.caption == '%'
                ? formatPercentage(data.text)
                : formatNumber(data.text)
              : data.text
          }}
        </p>
      </template>

      <template #formatRCT="{ data }">
        <p
          class="text-right cursor-pointer"
          :class="[data.text < 180 ? 'text-green-500' : 'text-red-500']"
          @click="setDialogStatus(data.column.caption)"
        >
          {{
            isNumber(data.text)
              ? data.column.caption == '%'
                ? formatPercentage(data.text)
                : formatNumber(data.text)
              : data.text
          }}
        </p>
      </template>
    </DxDataGrid>
  </div>

  <DetailDialog
    :open="dialogDetail"
    title="Detail Gangguan All"
    @on-close="closedialogDetail"
    :full-width="true"
  >
    <div class="w-full mb-4 lg:w-[70%] lg:float-left">
      <div class="p-4 bg-white rounded-xl lg:mr-4">
        <DxDataGrid
          :allow-column-reordering="true"
          class="max-h-[calc(100vh-140px)]"
          :data-source="dataSub"
          :show-column-lines="true"
          :show-row-lines="false"
          :show-borders="true"
          :row-alternation-enabled="true"
          :hover-state-enabled="true"
          @selection-changed="onDataSubSelectionChanged"
          :column-width="100"
          @exporting="onExportingDetail"
          :allow-column-resizing="true"
          column-resizing-mode="widget"
        >
          <DxSelection mode="single" />
          <DxPaging :page-size="20" :enabled="true" />
          <DxPager
            :visible="true"
            :allowed-page-sizes="[20, 50, 100]"
            display-mode="full"
            :show-page-size-selector="true"
            :show-info="true"
            :show-navigation-buttons="true"
          />
          <!--  -->
          <DxSearchPanel :visible="true" :highlight-case-sensitive="true" />
          <DxExport
            :enabled="true"
            :formats="['pdf', 'xlsx', 'document']"
            :allow-export-selected-data="false"
          />

          <DxColumn
            css-class="custom-table-column"
            :width="50"
            alignment="center"
            :calculate-display-value="(item: any) => dataSub.findIndex((i: any) => i == item) + 1"
            data-type="number"
            caption="No"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="nama_posko"
            caption="Posko"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="no_laporan"
            caption="No Lapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_lapor"
            caption="Tgl/Jam Lapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_response"
            caption="Tgl/Jam Datang"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_recovery"
            caption="Tgl/Jam Nyala"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_response_time"
            caption="Durasi Response Time"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_recovery_time"
            caption="Durasi Recovery Time"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_dispatch_time"
            caption="Durasi Penugasan Regu"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_perjalanan_time"
            caption="Durasi Perjalanan Regu"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="jarak_closing"
            caption="Jarak Closing (m)"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="dispatch_oleh"
            caption="Dispatch Oleh"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="idpel_nometer"
            caption="IDPEL/NO METER"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="nama_pelapor"
            caption="Nama Pelapor"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="200"
            alignment="center"
            data-field="alamat_pelapor"
            caption="Alamat Pelapor"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="no_telp_pelapor"
            caption="No Telp Pelapor"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="200"
            alignment="center"
            data-field="keterangan_pelapor"
            caption="Keterangan Pelapor"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="media"
            caption="Sumber Lapor"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="diselesaikan_oleh"
            caption="Diselesaikan Oleh"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="status_akhir"
            caption="Status"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="referensi_marking"
            caption="Referensi Marking"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="kode_gangguan"
            caption="Kode Gangguan"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="jenis_gangguan"
            caption="Jenis Gangguan"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="penyebab"
            caption="Penyebab"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="tindakan"
            caption="Tindakan"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />

          <template #formatText="{ data }">
            <p class="text-left cursor-pointer">
              {{ data.text }}
            </p>
          </template>

          <template #formatNumber="{ data }">
            <p class="text-right cursor-pointer">
              {{ data.text }}
            </p>
          </template>

          <template #formatTime="{ data }">
            <p>
              {{ parseInt(data.text) ? formatWaktu(data.text) : '-' }}
            </p>
          </template>
        </DxDataGrid>
      </div>
    </div>
    <div class="w-full mb-4 lg:w-[30%] lg:float-right">
      <div class="p-4 space-y-2 bg-white rounded-xl">
        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Posko:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.nama_posko" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">No Laporan:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.no_laporan" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Tgl/Jam Lapor:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.waktu_lapor" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Tgl/Jam Datang:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.waktu_response"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Tgl/Jam Nyala:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.waktu_recovery"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Durasi Response Time:</h3>
          <InputText
            :readonly="true"
            :value="
              parseInt(dataSubSelected?.durasi_response_time)
                ? formatWaktu(dataSubSelected?.durasi_response_time)
                : '-'
            "
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Durasi Recovery Time:</h3>
          <InputText
            :readonly="true"
            :value="
              parseInt(dataSubSelected?.durasi_recovery_time)
                ? formatWaktu(dataSubSelected?.durasi_recovery_time)
                : '-'
            "
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Durasi Penugasan Regu:</h3>
          <InputText
            :readonly="true"
            class-name="flex-1"
            :value="
              parseInt(dataSubSelected?.durasi_dispatch_time)
                ? formatWaktu(dataSubSelected?.durasi_dispatch_time)
                : '-'
            "
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Durasi Perjalanan Regu:</h3>
          <InputText
            :readonly="true"
            :value="
              parseInt(dataSubSelected?.durasi_perjalanan_time)
                ? formatWaktu(dataSubSelected?.durasi_perjalanan_time)
                : '-'
            "
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Jarak Closing (m):</h3>
          <InputText :readonly="true" :value="dataSubSelected?.jarak_closing" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Dispatch Oleh:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.dispatch_oleh" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">IDPEL/NO METER:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.idpel_nometer" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Nama Pelapor:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.nama_pelapor" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Alamat Pelapor:</h3>
          <InputText
            :readonly="true"
            type="textarea"
            :value="dataSubSelected?.alamat_pelapor"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">NO Telp Pelapor:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.no_telp_pelapor"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Keterangan Pelapor:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.keterangan_pelapor"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Sumber Lapor:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.pembuat_laporan"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Diselesaikan Oleh:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.diselesaikan_oleh"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Status:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.status_akhir" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Referensi Marking:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.referensi_marking"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Kode Gangguan:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.kode_gangguan" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Jenis Gangguan:</h3>
          <InputText
            :readonly="true"
            :value="dataSubSelected?.jenis_gangguan"
            class-name="flex-1"
          />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Penyebab:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.penyebab" class-name="flex-1" />
        </div>

        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">Tindakan:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.tindakan" class-name="flex-1" />
        </div>
      </div>
    </div>
  </DetailDialog>

  <BufferDialog v-if="loadingData || loadingSubData" />
</template>

<script setup lang="ts">
import Filters from '@/components/Form/Filters.vue'
import Type1 from '@/components/Form/FiltersType/Type1.vue'
import { formatWaktu } from '@/components/Form/FiltersType/reference'
import { DxDataGrid } from 'devextreme-vue'
import {
  DxColumn,
  DxExport,
  DxPager,
  DxPaging,
  DxSearchPanel,
  DxSelection,
  DxSummary,
  DxGroupItem,
  DxGrouping
} from 'devextreme-vue/data-grid'
import { onMounted, ref } from 'vue'
import { requestGraphQl, queries } from '@/utils/api/api.graphql'
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
import InputText from '@/components/InputText.vue'
import { apolloClient } from '@/utils/api/api.graphql'
import { provideApolloClient } from '@vue/apollo-composable'
import {
  exportToPDF,
  exportToXLSX,
  exportDetailToPDF,
  exportDetailToXLSX,
  exportToDOCX,
  exportDetailToDOCX
} from '@/report/Gangguan/Rekap/RGangguan_ALL'
import { getDataRowGroup } from '@/utils/helper'
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'

const client = apolloClient()
provideApolloClient(client)
const position = { of: '#data' }
const showIndicator = ref(true)
const shading = ref(true)
const showPane = ref(true)
const data = ref<any[]>([])
const dataSub = ref<any[]>([])
const dataSelected = ref<any>(null)
const dataSubSelected = ref<any>(null)
const dialogDetail = ref(false)
const closedialogDetail = () => (dialogDetail.value = false)
const loadingData = ref(false)
const loadingSubData = ref(false)
const isDialogEnabled = ref(false)
const progressSelected = ref(0)
const groupIndex = ref(0)
const groupDialog = ref(false)
const groupData = ref<any>(null)
const reportMeta = ref({
  uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
  up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
  posko: { id: 0, name: 'Semua Posko' },
  periode: ''
})
const grouping = ref<any[]>([
  {
    data: '',
    caption: 'Semua Unit'
  },
  {
    data: 'nama_regional',
    caption: 'Regional'
  },
  {
    data: 'nama_uid',
    caption: 'UID'
  },
  {
    data: 'nama_up3',
    caption: 'UP3'
  }
])

const onCellClicked = (e: any) => {
  if (e.rowType == 'group') {
    groupDialog.value = true
    groupIndex.value = e.row.groupIndex

    setDialogStatus(e.column.caption)
    groupData.value = getDataRowGroup(e.data)
    showDetail()
  } else {
    groupDialog.value = false
  }
}

const setDialogStatus = (column: string) => {
  if (column == 'Total' || column == 'Selesai' || column == 'In Progress') {
    isDialogEnabled.value = true
    if (column == 'Total') {
      progressSelected.value = 0
    } else if (column == 'Selesai') {
      progressSelected.value = 1
    } else {
      progressSelected.value = 2
    }
  } else {
    isDialogEnabled.value = false
  }
}

let total = 0
let total_selesai = 0
let total_inproses = 0
let count_durasi_dispatch = 0
let total_durasi_dispatch = 0
let count_durasi_response = 0
let total_durasi_response = 0
let count_durasi_recovery = 0
let total_durasi_recovery = 0
const calculateCustomSummary = (options: any) => {
  if (options.name === 'total') {
    if (options.summaryProcess === 'calculate') {
      total += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total
    }
  }

  if (options.name === 'total_selesai') {
    if (options.summaryProcess === 'calculate') {
      total_selesai += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total_selesai
    }
  }

  if (options.name === 'total_inproses') {
    if (options.summaryProcess === 'calculate') {
      total_inproses += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total_inproses
    }
  }

  if (options.name === 'persen_selesai') {
    if (options.summaryProcess === 'start') {
      total = 0
      total_selesai = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = !isFinite(total_selesai / total)
        ? 0
        : total_selesai == 0
          ? 0
          : (total_selesai / total) * 100
    }
  }

  if (options.name === 'persen_inproses') {
    if (options.summaryProcess === 'start') {
      total = 0
      total_inproses = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = !isFinite(total_inproses / total)
        ? 0
        : total_inproses == 0
          ? 0
          : (total_inproses / total) * 100
    }
  }

  if (options.name === 'count_durasi_dispatch') {
    if (options.summaryProcess === 'calculate') {
      count_durasi_dispatch += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = count_durasi_dispatch
    }
  }

  if (options.name === 'total_durasi_dispatch') {
    if (options.summaryProcess === 'calculate') {
      total_durasi_dispatch += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total_durasi_dispatch
    }
  }

  if (options.name === 'avg_durasi_dispatch') {
    if (options.summaryProcess === 'start') {
      count_durasi_dispatch = 0
      total_durasi_dispatch = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = !isFinite(total_durasi_dispatch / count_durasi_dispatch)
        ? 0
        : total_durasi_dispatch == 0
          ? 0
          : total_durasi_dispatch / count_durasi_dispatch
    }
  }

  if (options.name === 'count_durasi_response') {
    if (options.summaryProcess === 'calculate') {
      count_durasi_response += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = count_durasi_response
    }
  }

  if (options.name === 'total_durasi_response') {
    if (options.summaryProcess === 'calculate') {
      total_durasi_response += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total_durasi_response
    }
  }

  if (options.name === 'avg_durasi_response') {
    if (options.summaryProcess === 'start') {
      count_durasi_response = 0
      total_durasi_response = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = !isFinite(total_durasi_response / count_durasi_response)
        ? 0
        : total_durasi_response == 0
          ? 0
          : total_durasi_response / count_durasi_response
    }
  }

  if (options.name === 'count_durasi_recovery') {
    if (options.summaryProcess === 'calculate') {
      count_durasi_recovery += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = count_durasi_recovery
    }
  }

  if (options.name === 'total_durasi_recovery') {
    if (options.summaryProcess === 'calculate') {
      total_durasi_recovery += options.value
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = total_durasi_recovery
    }
  }

  if (options.name === 'avg_durasi_recovery') {
    if (options.summaryProcess === 'start') {
      count_durasi_recovery = 0
      total_durasi_recovery = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = !isFinite(total_durasi_recovery / count_durasi_recovery)
        ? 0
        : total_durasi_recovery == 0
          ? 0
          : total_durasi_recovery / count_durasi_recovery
    }
  }
}

const resetData = () => {
  data.value = []
  dataSub.value = []
  dataSelected.value = null
  dataSubSelected.value = null
}

const filterData = async (params: any) => {
  resetData()
  const { posko, uid, up3 } = params
  const dateValue = params.periode.split(' s/d ')

  var groupList: any[] = [
    {
      data: '',
      caption: 'Semua Unit'
    },
    {
      data: 'nama_regional',
      caption: 'Regional'
    },
    {
      data: 'nama_uid',
      caption: 'UID'
    },
    {
      data: 'nama_up3',
      caption: 'UP3'
    }
  ]

  if (uid?.id != 0) {
    groupList.forEach((item, index) => {
      if (item.caption == 'Semua Unit') {
        groupList.splice(index, 1)
      }
    })

    groupList.forEach((item, index) => {
      if (item.caption == 'Regional') {
        groupList.splice(index, 1)
      }
    })

    if (up3?.id != 0) {
      groupList.forEach((item, index) => {
        if (item.caption == 'UID') {
          groupList.splice(index, 1)
        }
      })

      if (posko?.id != 0) {
        groupList.forEach((item, index) => {
          if (item.caption == 'UP3') {
            groupList.splice(index, 1)
          }
        })
      }
    }
  }
  grouping.value = groupList

  const query = {
    dateFrom: dateValue[0]
      ? dateValue[0].split('-').reverse().join('-')
      : new Date().toISOString().slice(0, 10),
    dateTo: dateValue[1]
      ? dateValue[1].split('-').reverse().join('-')
      : new Date().toISOString().slice(0, 10),
    posko: posko ? posko.id : 0,
    idUid: uid ? uid.id : 0,
    idUp3: up3 ? up3.id : 0
  }

  loadingData.value = true
  await requestGraphQl(queries.gangguan.rekap.gangguanAll, query)
    .then((result) => {
      if (result.data.data != null) {
        data.value = result.data.data.rekapitulasiAllGangguan
      } else {
        data.value = []
      }

      reportMeta.value = filters.value
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {
      loadingData.value = false
    })
}

const getDetail = async () => {
  loadingSubData.value = true
  const dateValue = filters.value.periode.split(' s/d ')
  const selected = dataSelected.value

  var query = {
    dateFrom: dateValue[0]
      ? dateValue[0].split('-').reverse().join('-')
      : new Date().toISOString().slice(0, 10),
    dateTo: dateValue[1]
      ? dateValue[1].split('-').reverse().join('-')
      : new Date().toISOString().slice(0, 10),
    posko: 0,
    idUid: 0,
    idUp3: 0,
    idRegu: 0,
    idUlp: 0,
    namaRegional: '',
    media: '',
    isSelesai: progressSelected.value,
    tanggal: ''
  }
  if (groupDialog.value) {
    console.log('groupData', grouping.value[groupIndex.value].data)
    if (grouping.value[groupIndex.value].data == 'nama_regional') {
      query = {
        ...query,
        namaRegional: groupData.value?.nama_regional ? groupData.value?.nama_regional : ''
      }
    } else if (grouping.value[groupIndex.value].data == 'nama_uid') {
      query = {
        ...query,
        idUid: groupData.value?.id_uid ? groupData.value?.id_uid : 0,
        namaRegional: groupData.value?.nama_regional ? groupData.value?.nama_regional : ''
      }
    } else if (grouping.value[groupIndex.value].data == 'nama_up3') {
      query = {
        ...query,
        idUid: groupData.value?.id_uid ? groupData.value?.id_uid : 0,
        idUp3: groupData.value?.id_up3 ? groupData.value?.id_up3 : 0,
        namaRegional: groupData.value?.nama_regional ? groupData.value?.nama_regional : ''
      }
    }
  } else {
    query = {
      dateFrom: dateValue[0]
        ? dateValue[0].split('-').reverse().join('-')
        : new Date().toISOString().slice(0, 10),
      dateTo: dateValue[1]
        ? dateValue[1].split('-').reverse().join('-')
        : new Date().toISOString().slice(0, 10),
      posko: selected?.id_posko ? selected?.id_posko : 0,
      idUid: selected?.id_uid ? selected?.id_uid : 0,
      idUp3: selected?.id_up3 ? selected?.id_up3 : 0,
      idRegu: selected?.id_regu ? selected?.id_regu : 0,
      idUlp: selected?.id_ulp ? selected?.id_ulp : 0,
      namaRegional: selected?.nama_regional ? selected?.nama_regional : '',
      media: selected?.media ? selected?.media : '',
      isSelesai: progressSelected.value,
      tanggal: ''
    }
  }
  console.table(query)

  await requestGraphQl(queries.gangguan.rekap.gangguanAllDetail, query)
    .then((result) => {
      if (result.data.data != null) {
        dataSub.value = result.data.data.detailGangguan
      } else {
        dataSub.value = []
      }
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {
      loadingSubData.value = false
      dialogDetail.value = true
    })
}
const dataGridRef = ref<DxDataGrid | null>(null)
const clearSelection = () => {
  try {
    dataGridRef.value?.instance?.clearSelection()
  } catch (error) {
    console.log(error)
  }
}
const showDetail = () => {
  clearSelection()
  if (isDialogEnabled.value) {
    dataSub.value = []
    dataSubSelected.value = null
    getDetail()
  }
}

const onExporting = (e: any) => {
  if (e.format === 'pdf') {
    exportToPDF(reportMeta.value, data.value)
  } else if (e.format === 'xlsx') {
    exportToXLSX(reportMeta.value, e)
  } else {
    exportToDOCX(reportMeta.value, data.value)
  }
}

const onExportingDetail = (e: any) => {
  if (e.format === 'pdf') {
    exportDetailToPDF(reportMeta.value, dataSub.value)
  } else if (e.format === 'xlsx') {
    exportDetailToXLSX(reportMeta.value, e)
  } else {
    exportDetailToDOCX(reportMeta.value, dataSub.value)
  }
}

const onDataSelectionChanged = ({ selectedRowsData }: any) => {
  if (selectedRowsData[0] != undefined) {
    dataSelected.value = selectedRowsData[0]
    showDetail()
  }
}

const onDataSubSelectionChanged = ({ selectedRowsData }: any) => {
  const data = selectedRowsData[0]
  dataSubSelected.value = data
}

const filters = ref()

onMounted(() => {
  if (import.meta.env.DEV) {
    data.value = [
      {
        id: 443201,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44320,
        nama_ulp: 'ULP DOMPU',
        id_posko: 443201,
        nama_posko: 'POSKO ULP DOMPU',
        total: 426,
        total_selesai: 374,
        persen_selesai: 87.79342723004694,
        total_inproses: 52,
        persen_inproses: 12.206572769953052,
        avg_durasi_dispatch: 2.4715447154471546,
        min_durasi_dispatch: 0,
        max_durasi_dispatch: 723,
        total_dibawah_sla_dispatch: 331,
        total_diatas_sla_dispatch: 38,
        avg_durasi_response: 12.729411764705882,
        min_durasi_response: 160,
        max_durasi_response: 2004,
        total_dibawah_sla_response: 340,
        total_diatas_sla_response: 0,
        avg_durasi_recovery: 21.4070796460177,
        min_durasi_recovery: 160,
        max_durasi_recovery: 2619,
        total_dibawah_sla_recovery: 339,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 394,
        count_durasi_response: 365,
        count_durasi_recovery: 364
      },
      {
        id: 316201,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 31,
        nama_uid: 'WILAYAH SULAWESI UTARA,TENGAH DAN GORONTALO',
        id_up3: 31600,
        nama_up3: 'UP3 GORONTALO',
        id_ulp: 31620,
        nama_ulp: 'ULP MARISA',
        id_posko: 316201,
        nama_posko: 'POSKO ULP MARISA',
        total: 152,
        total_selesai: 121,
        persen_selesai: 79.60526315789474,
        total_inproses: 31,
        persen_inproses: 20.394736842105264,
        avg_durasi_dispatch: 1.5221238938053097,
        min_durasi_dispatch: 1,
        max_durasi_dispatch: 1748,
        total_dibawah_sla_dispatch: 101,
        total_diatas_sla_dispatch: 12,
        avg_durasi_response: 10.786516853932584,
        min_durasi_response: 54,
        max_durasi_response: 2349,
        total_dibawah_sla_response: 89,
        total_diatas_sla_response: 0,
        avg_durasi_recovery: 19.32183908045977,
        min_durasi_recovery: 54,
        max_durasi_recovery: 3723,
        total_dibawah_sla_recovery: 87,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 118,
        count_durasi_response: 94,
        count_durasi_recovery: 92
      },
      {
        id: 422401,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 42,
        nama_uid: 'WILAYAH PAPUA DAN PAPUA BARAT',
        id_up3: 422,
        nama_up3: 'UP3 BIAK',
        id_ulp: 42240,
        nama_ulp: 'ULP WAROPEN',
        id_posko: 422401,
        nama_posko: 'POSKO ULP WAROPEN',
        total: 15,
        total_selesai: 13,
        persen_selesai: 86.66666666666667,
        total_inproses: 2,
        persen_inproses: 13.333333333333334,
        avg_durasi_dispatch: 1.0769230769230769,
        min_durasi_dispatch: 0,
        max_durasi_dispatch: 218,
        total_dibawah_sla_dispatch: 13,
        total_diatas_sla_dispatch: 0,
        avg_durasi_response: 11.833333333333334,
        min_durasi_response: 119,
        max_durasi_response: 1756,
        total_dibawah_sla_response: 12,
        total_diatas_sla_response: 0,
        avg_durasi_recovery: 20.545454545454547,
        min_durasi_recovery: 119,
        max_durasi_recovery: 1908,
        total_dibawah_sla_recovery: 11,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 15,
        count_durasi_response: 14,
        count_durasi_recovery: 13
      },
      {
        id: 433801,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 430,
        nama_uid: 'WILAYAH NUSA TENGGARA TIMUR',
        id_up3: 433,
        nama_up3: 'UP3 SUMBA',
        id_ulp: 43380,
        nama_ulp: 'ULP SUMBA BARAT DAYA',
        id_posko: 433801,
        nama_posko: 'POSKO ULP SUMBA BARAT DAYA',
        total: 188,
        total_selesai: 162,
        persen_selesai: 86.17021276595744,
        total_inproses: 26,
        persen_inproses: 13.829787234042554,
        avg_durasi_dispatch: 1.4675324675324675,
        min_durasi_dispatch: 2,
        max_durasi_dispatch: 567,
        total_dibawah_sla_dispatch: 147,
        total_diatas_sla_dispatch: 7,
        avg_durasi_response: 12.777777777777779,
        min_durasi_response: 241,
        max_durasi_response: 2772,
        total_dibawah_sla_response: 134,
        total_diatas_sla_response: 1,
        avg_durasi_recovery: 26.119402985074625,
        min_durasi_recovery: 453,
        max_durasi_recovery: 3755,
        total_dibawah_sla_recovery: 134,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 158,
        count_durasi_response: 139,
        count_durasi_recovery: 138
      },
      {
        id: 514603,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 149,
        nama_up3: 'UP3 MOJOKERTO',
        id_ulp: 51460,
        nama_ulp: 'ULP NGANJUK',
        id_posko: 514603,
        nama_posko: 'POSKO ULP NGANJUK',
        total: 1436,
        total_selesai: 1238,
        persen_selesai: 86.2116991643454,
        total_inproses: 198,
        persen_inproses: 13.788300835654596,
        avg_durasi_dispatch: 7.207339449541284,
        min_durasi_dispatch: 4,
        max_durasi_dispatch: 2760,
        total_dibawah_sla_dispatch: 508,
        total_diatas_sla_dispatch: 582,
        avg_durasi_response: 21.72106824925816,
        min_durasi_response: 130,
        max_durasi_response: 5415,
        total_dibawah_sla_response: 945,
        total_diatas_sla_response: 66,
        avg_durasi_recovery: 27.93168316831683,
        min_durasi_recovery: 130,
        max_durasi_recovery: 5978,
        total_dibawah_sla_recovery: 1010,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 1180,
        count_durasi_response: 1101,
        count_durasi_recovery: 1100
      },
      {
        id: 532931,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 540,
        nama_up3: 'UP3 GARUT',
        id_ulp: 53293,
        nama_ulp: 'ULP LELES',
        id_posko: 532931,
        nama_posko: 'POSKO ULP LELES',
        total: 370,
        total_selesai: 324,
        persen_selesai: 87.56756756756758,
        total_inproses: 46,
        persen_inproses: 12.432432432432433,
        avg_durasi_dispatch: 0.9965635738831615,
        min_durasi_dispatch: 3,
        max_durasi_dispatch: 1495,
        total_dibawah_sla_dispatch: 285,
        total_diatas_sla_dispatch: 6,
        avg_durasi_response: 16.597173144876326,
        min_durasi_response: 247,
        max_durasi_response: 5372,
        total_dibawah_sla_response: 261,
        total_diatas_sla_response: 22,
        avg_durasi_recovery: 25.93594306049822,
        min_durasi_recovery: 475,
        max_durasi_recovery: 7354,
        total_dibawah_sla_recovery: 281,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 295,
        count_durasi_response: 287,
        count_durasi_recovery: 285
      },
      {
        id: 543601,
        nama_regional: 'REGIONAL JMB',
        id_uid: 2,
        nama_uid: 'DISTRIBUSI JAKARTA RAYA',
        id_up3: 9,
        nama_up3: 'UP3 CIPUTAT',
        id_ulp: 54360,
        nama_ulp: 'UP3 CIPUTAT',
        id_posko: 543601,
        nama_posko: 'POSKO CIPUTAT',
        total: 3446,
        total_selesai: 2826,
        persen_selesai: 82.0081253627394,
        total_inproses: 620,
        persen_inproses: 17.99187463726059,
        avg_durasi_dispatch: 3.46793930494371,
        min_durasi_dispatch: 1,
        max_durasi_dispatch: 2761,
        total_dibawah_sla_dispatch: 1740,
        total_diatas_sla_dispatch: 303,
        avg_durasi_response: 30.737704918032787,
        min_durasi_response: 29,
        max_durasi_response: 8303,
        total_dibawah_sla_response: 1465,
        total_diatas_sla_response: 243,
        avg_durasi_recovery: 49.72835112692764,
        min_durasi_recovery: 29,
        max_durasi_recovery: 10280,
        total_dibawah_sla_recovery: 1686,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 2123,
        count_durasi_response: 1789,
        count_durasi_recovery: 1768
      },
      {
        id: 327601,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 32,
        nama_uid: 'WILAYAH SULAWESI SELATAN, TENGGARA DAN BARAT',
        id_up3: 32700,
        nama_up3: 'UP3 BULUKUMBA',
        id_ulp: 32760,
        nama_ulp: 'ULP SINJAI',
        id_posko: 327601,
        nama_posko: 'POSKO ULP SINJAI',
        total: 401,
        total_selesai: 344,
        persen_selesai: 85.785536159601,
        total_inproses: 57,
        persen_inproses: 14.214463840399002,
        avg_durasi_dispatch: 1.3757396449704142,
        min_durasi_dispatch: 1,
        max_durasi_dispatch: 2875,
        total_dibawah_sla_dispatch: 319,
        total_diatas_sla_dispatch: 19,
        avg_durasi_response: 17.36760124610592,
        min_durasi_response: 615,
        max_durasi_response: 3359,
        total_dibawah_sla_response: 318,
        total_diatas_sla_response: 3,
        avg_durasi_recovery: 31.22429906542056,
        min_durasi_recovery: 994,
        max_durasi_recovery: 3849,
        total_dibawah_sla_recovery: 321,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 340,
        count_durasi_response: 323,
        count_durasi_recovery: 323
      },
      {
        id: 146301,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 140,
        nama_uid: 'WILAYAH SUMATERA SELATAN, JAMBI & BENGKULU (S2JB)',
        id_up3: 1403,
        nama_up3: 'UP3 BENGKULU',
        id_ulp: 14630,
        nama_ulp: 'ULP MUARA AMAN',
        id_posko: 146301,
        nama_posko: 'POSKO ULP MUARA AMAN',
        total: 16,
        total_selesai: 14,
        persen_selesai: 87.5,
        total_inproses: 2,
        persen_inproses: 12.5,
        avg_durasi_dispatch: 3.8,
        min_durasi_dispatch: 91,
        max_durasi_dispatch: 991,
        total_dibawah_sla_dispatch: 9,
        total_diatas_sla_dispatch: 1,
        avg_durasi_response: 13.555555555555555,
        min_durasi_response: 625,
        max_durasi_response: 1117,
        total_dibawah_sla_response: 9,
        total_diatas_sla_response: 0,
        avg_durasi_recovery: 24.444444444444443,
        min_durasi_recovery: 1305,
        max_durasi_recovery: 1825,
        total_dibawah_sla_recovery: 9,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 10,
        count_durasi_response: 9,
        count_durasi_recovery: 9
      },
      {
        id: 561201,
        nama_regional: 'REGIONAL JMB',
        id_uid: 56,
        nama_uid: 'DISTRIBUSI BANTEN',
        id_up3: 534,
        nama_up3: 'UP3 BANTEN UTARA',
        id_ulp: 56120,
        nama_ulp: 'ULP CILEGON',
        id_posko: 561201,
        nama_posko: 'POSKO ULP CILEGON',
        total: 1177,
        total_selesai: 1057,
        persen_selesai: 89.80458793542905,
        total_inproses: 120,
        persen_inproses: 10.195412064570943,
        avg_durasi_dispatch: 2.6475972540045767,
        min_durasi_dispatch: 2,
        max_durasi_dispatch: 2544,
        total_dibawah_sla_dispatch: 796,
        total_diatas_sla_dispatch: 78,
        avg_durasi_response: 19.35131396957123,
        min_durasi_response: 90,
        max_durasi_response: 4412,
        total_dibawah_sla_response: 713,
        total_diatas_sla_response: 10,
        avg_durasi_recovery: 32.180281690140845,
        min_durasi_recovery: 90,
        max_durasi_recovery: 4951,
        total_dibawah_sla_recovery: 710,
        total_diatas_sla_recovery: 0,
        count_durasi_dispatch: 894,
        count_durasi_response: 743,
        count_durasi_recovery: 730
      }
    ]
    dataSub.value = []
  }
})
</script>
