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

  <div id="data">
    <DxDataGrid
      ref="dataGridRef"
      :allow-column-reordering="true"
      class="max-h-[calc(100vh-140px)] mb-10"
      :data-source="data"
      :show-column-lines="true"
      :show-row-lines="false"
      :show-borders="true"
      :row-alternation-enabled="true"
      :hover-state-enabled="true"
      @selection-changed="onDataSelectionChanged"
      :column-width="100"
      @exporting="onExporting"
      :allow-column-resizing="true"
      column-resizing-mode="widget"
      :word-wrap-enabled="true"
    >
      <DxSelection mode="single" />
      <DxPaging :enabled="false" />
      <DxScrolling column-rendering-mode="virtual" mode="virtual" />
      <!--  -->
      <DxSearchPanel :visible="true" :highlight-case-sensitive="true" />
      <DxExport
        :enabled="true"
        :formats="['pdf', 'xlsx', 'document']"
        :allow-export-selected-data="false"
      />
      <DxColumnFixing :enabled="true" />

      <DxColumn
        :width="60"
        alignment="center"
        data-field="no"
        caption="NO"
        css-class="custom-table-column"
        cell-template="formatNumber"
        :calculate-display-value="(item: any) => data.findIndex((i) => i == item) + 1"
      />
      <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="kode_regu"
        caption="Kode"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn
        :width="200"
        alignment="center"
        data-field="nama_regu"
        caption="Nama Regu"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
        <DxColumn
          :width="120"
          alignment="center"
          data-field="total"
          data-type="number"
          caption="Total"
          css-class="custom-table-column"
          cell-template="formatNumberLaporanTotal"
        />
        <DxColumn alignment="center" caption="Sudah Selesai" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_selesai"
            data-type="number"
            caption="Jml"
            css-class="custom-table-column"
            cell-template="formatNumberLaporanJmlSelesai"
          />
          <DxColumn
            :width="70"
            alignment="center"
            data-field="persen_selesai"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </DxColumn>
        <DxColumn alignment="center" caption="Belum Selesai" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_inproses"
            data-type="number"
            caption="Jml"
            css-class="custom-table-column"
            cell-template="formatNumberLaporanJmlBelumSelesai"
          />
          <DxColumn
            :width="70"
            alignment="center"
            data-field="persen_inproses"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </DxColumn>
      </DxColumn>
      <DxColumn alignment="center" caption="Response Time" css-class="custom-table-column">
        <DxColumn alignment="center" caption="Menit" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_durasi_response"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :visible="false"
            :width="120"
            alignment="center"
            data-field="count_durasi_response"
            data-type="number"
            caption="Jumlah Durasi"
            css-class="custom-table-column"
            cell-template="formatNumber"
            :calculate-cell-value="
              (rowData: any) => rowData.total_durasi_response * rowData.avg_durasi_response
            "
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="avg_durasi_response"
            data-type="number"
            caption="Rata-Rata"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="max_durasi_response"
            data-type="number"
            caption="Max"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="min_durasi_response"
            data-type="number"
            caption="Min"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
        </DxColumn>
        <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_diatas_sla_response"
            data-type="number"
            caption=">SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_dibawah_sla_response"
            data-type="number"
            caption="≤SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </DxColumn>
      </DxColumn>
      <DxColumn alignment="center" caption="Recovery Time" css-class="custom-table-column">
        <DxColumn alignment="center" caption="Menit" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_durasi_recovery"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :visible="false"
            :width="120"
            alignment="center"
            data-field="count_durasi_recovery"
            data-type="number"
            caption="Jumlah Durasi"
            css-class="custom-table-column"
            cell-template="formatNumber"
            :calculate-cell-value="
              (rowData: any) => rowData.total_durasi_recovery * rowData.avg_durasi_recovery
            "
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="avg_durasi_recovery"
            data-type="number"
            caption="Rata-Rata"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="max_durasi_recovery"
            data-type="number"
            caption="Max"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="min_durasi_recovery"
            data-type="number"
            caption="Min"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
        </DxColumn>
        <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_diatas_sla_recovery"
            data-type="number"
            caption=">SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="120"
            alignment="center"
            data-field="total_dibawah_sla_recovery"
            data-type="number"
            caption="≤SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </DxColumn>
      </DxColumn>

      <DxSummary :calculate-custom-summary="calculateCustomSummary">
        <DxGroupItem
          :show-in-group-footer="true"
          column="kode_regu"
          display-format="Total"
          css-class="!text-left"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total"
          name="total"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_selesai"
          name="total_selesai"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="persen_selesai"
          name="persen_selesai"
          summary-type="custom"
          :customize-text="(e: any) => formatPercentage(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_inproses"
          name="total_inproses"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="persen_inproses"
          name="persen_inproses"
          summary-type="custom"
          :customize-text="(e: any) => formatPercentage(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_durasi_response"
          name="total_durasi_response"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="count_durasi_response"
          name="count_durasi_response"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="avg_durasi_response"
          name="avg_durasi_response"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="max_durasi_response"
          summary-type="max"
          css-class="!text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="min_durasi_response"
          summary-type="min"
          css-class="!text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_diatas_sla_response"
          summary-type="sum"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_dibawah_sla_response"
          summary-type="sum"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_durasi_recovery"
          name="total_durasi_recovery"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="count_durasi_recovery"
          name="count_durasi_recovery"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="avg_durasi_recovery"
          name="avg_durasi_recovery"
          summary-type="custom"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="max_durasi_recovery"
          summary-type="max"
          css-class="!text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="min_durasi_recovery"
          summary-type="min"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_diatas_sla_recovery"
          summary-type="sum"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />
        <DxGroupItem
          :show-in-group-footer="true"
          column="total_dibawah_sla_recovery"
          summary-type="sum"
          :customize-text="(e: any) => formatNumber(e.value)"
          css-class="!text-right"
        />

        <DxTotalItem
          summary-type="sum"
          display-format="Total"
          show-in-column="kode_regu"
          css-class="text-white !text-left"
        />
        <DxTotalItem
          summary-type="custom"
          show-in-column="total"
          column="total"
          name="total"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="total_selesai"
          name="total_selesai"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="persen_selesai"
          name="persen_selesai"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxTotalItem
          column="total_inproses"
          name="total_inproses"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="persen_inproses"
          name="persen_inproses"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxTotalItem
          column="total_durasi_response"
          name="total_durasi_response"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="count_durasi_response"
          name="count_durasi_response"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="avg_durasi_response"
          name="avg_durasi_response"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="max_durasi_response"
          summary-type="max"
          css-class="text-white !text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxTotalItem
          column="min_durasi_response"
          summary-type="min"
          css-class="text-white !text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxTotalItem
          column="total_diatas_sla_response"
          summary-type="sum"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="total_dibawah_sla_response"
          summary-type="sum"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="total_durasi_recovery"
          name="total_durasi_recovery"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="count_durasi_recovery"
          name="count_durasi_recovery"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="avg_durasi_recovery"
          name="avg_durasi_recovery"
          summary-type="custom"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="max_durasi_recovery"
          summary-type="max"
          css-class="text-white !text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxTotalItem
          column="min_durasi_recovery"
          summary-type="min"
          css-class="text-white !text-right"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxTotalItem
          column="total_diatas_sla_recovery"
          summary-type="sum"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxTotalItem
          column="total_dibawah_sla_recovery"
          summary-type="sum"
          css-class="text-white !text-right"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
      </DxSummary>

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

      <template #formatText="{ data }">
        <p class="text-left cursor-pointer" @click="setAgreementDialog(false, 0)">
          {{ data.text }}
        </p>
      </template>

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

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

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

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

      <template #formatTime="{ data }" @click="setAgreementDialog(false, 0)">
        <p class="!text-right">
          {{ parseInt(data.text) ? formatWaktu(data.text) : '-' }}
        </p>
      </template>
    </DxDataGrid>
  </div>

  <DetailDialog
    :open="dialogDetail"
    title="Detail Rekapitulasi Gangguan Per Regu"
    @on-close="closeDialog"
    :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) => i == item) + 1"
            data-type="number"
            caption="No"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="no_laporan"
            caption="No Laporan"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_lapor"
            caption="Tgl Lapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_response"
            caption="Tgl Datang"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_recovery"
            caption="Tgl Nyala"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_response_time"
            caption="Durasi Response Time"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="durasi_recovery_time"
            caption="Durasi Recovery Time"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="status_akhir"
            caption="Status"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="referensi_marking"
            caption="Referensi Marking"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="idpel_nometer"
            caption="IDPEL/NO METER"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="nama_pelapor"
            caption="Nama Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="alamat_pelapor"
            caption="Alamat Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="no_telp_pelapor"
            caption="No Telp Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="200"
            alignment="center"
            data-field="keterangan_pelapor"
            caption="Keterangan Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <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="tindakan"
            caption="Tidakan"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="penyebab"
            caption="Penyebab"
            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">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 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 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 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">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">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"
            :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">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">Tindakan:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.tindakan" 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>
    </div>
  </DetailDialog>

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

<script setup lang="ts">
import Filters from '@/components/Form/Filters.vue'
import Type9 from '@/components/Form/FiltersType/Type9.vue'
import { formatWaktu } from '@/components/Form/FiltersType/reference'
import { onMounted, ref } from 'vue'
import { DxDataGrid } from 'devextreme-vue'
import {
  DxColumn,
  DxColumnFixing,
  DxExport,
  DxPager,
  DxPaging,
  DxScrolling,
  DxSearchPanel,
  DxSelection,
  DxSummary,
  DxTotalItem
} from 'devextreme-vue/data-grid'
import { queries, requestGraphQl } 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,
  exportDetailToPDF,
  exportToXLSX,
  exportDetailToXLSX,
  exportToDOCX,
  exportDetailToDOCX
} from '@/report/Gangguan/Rekap/RGangguan_PerRegu'
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>()
const dataSubSelected = ref<any>()
const dialogDetail = ref(false)
const loadingData = ref(false)
const loadingSubData = ref(false)
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: '',
  groupBy: false
})
const grouping = ref<any[]>([
  {
    data: '',
    caption: 'Seluruh Unit'
  }
])
const agreeToShowDialog = ref(false)
const progressSelected = ref(0)
const isGroupBy = ref(false)

let total = 0
let total_selesai = 0
let total_inproses = 0
let count_durasi_response = 0
let total_durasi_response = 0
let total_durasi_recovery = 0
let count_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 = (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 = (total_inproses / total) * 100
    }
  }

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

  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 === '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 === 'avg_durasi_response') {
    if (options.summaryProcess === 'start') {
      total_durasi_response = 0
      count_durasi_response = 0
    } else if (options.summaryProcess === 'finalize') {
      options.totalValue = count_durasi_response / total_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 = count_durasi_recovery / total_durasi_recovery
    }
  }
}

const setAgreementDialog = (status: boolean, progress: number) => {
  agreeToShowDialog.value = status
  progressSelected.value = progress
}

const getDetail = async () => {
  const dateValue = filters.value?.periode.split(' s/d ')
  const ref = dataSelected.value

  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: ref?.id_posko ? ref?.id_posko : 0,
    idUid: ref?.id_uid ? ref?.id_uid : 0,
    idUp3: ref?.id_up3 ? ref?.id_up3 : 0,
    idRegu: ref?.id_regu ? ref?.id_regu : 0,
    idUlp: ref?.id_ulp ? ref?.id_ulp : 0,
    namaRegional: ref?.nama_regional ? ref?.nama_regional : '',
    media: ref?.media ? ref?.media : '',
    isSelesai: progressSelected.value,
    tanggal: ''
  }

  loadingSubData.value = true
  await requestGraphQl(queries.gangguan.rekap.gangguanAllDetail, query)
    .then((result) => {
      if (result.data.data != undefined) {
        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 = () => {
  const dataGrid = dataGridRef.value!.instance!
  dataGrid.clearSelection()
}
const showDetail = () => {
  clearSelection()
  dataSub.value = []
  dataSubSelected.value = null
  if (agreeToShowDialog.value) {
    getDetail()
  }
}

const closeDialog = () => {
  dialogDetail.value = false
}

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) => {
  if (selectedRowsData[0] != undefined) {
    dataSubSelected.value = selectedRowsData[0]
  }
}

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

const filterData = async (params: any) => {
  resetData()
  const dateValue = params.periode.split(' s/d ')
  const { posko, uid, up3 } = params
  isGroupBy.value = params.groupBy
  if (isGroupBy.value) {
    if (uid.id != 0) {
      grouping.value = [
        {
          data: 'nama_up3',
          caption: 'UP3'
        }
      ]

      if (up3.id != 0 || posko.id != 0) {
        grouping.value = [
          {
            data: 'nama_ulp',
            caption: 'ULP'
          }
        ]
      }
    } else {
      grouping.value = [
        {
          data: 'nama_uid',
          caption: 'UID'
        }
      ]
    }
  } else {
    if (uid.id != 0) {
      grouping.value = [
        {
          data: 'nama_uid',
          caption: 'UID'
        }
      ]

      if (up3.id != 0) {
        grouping.value = [
          {
            data: 'nama_up3',
            caption: 'UP3'
          }
        ]

        if (posko.id != 0) {
          grouping.value = [
            {
              data: 'nama_ulp',
              caption: 'ULP'
            }
          ]
        }
      }
    } else {
      grouping.value = [
        {
          data: '',
          caption: 'Seluruh Unit'
        }
      ]
    }
  }

  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.gangguanPerRegu, query)
    .then((result) => {
      
      if (result.data.data != undefined) {
        data.value = result.data.data.rekapitulasiGangguanPerRegu
      } else {
        data.value = []
      }
      reportMeta.value = {
        uid: { id: uid ? uid.id : 0, name: uid ? uid.name : 'Semua Unit Induk Distribusi/Wilayah' },
        up3: {
          id: up3 ? up3.id : 0,
          name: up3 ? up3.name : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'
        },
        posko: { id: posko ? posko.id : 0, name: posko ? posko.name : 'Semua Posko' },
        periode: params.periode,
        groupBy: params.groupBy
      }
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {
      loadingData.value = false
    })
}

const filters = ref({
  uid: 0,
  up3: 0,
  posko: 0,
  periode: '',
  groupBy: false
})

onMounted(() => {
  if (import.meta.env.DEV) {
    data.value = [
      {
        id: 0,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 29044,
        kode_regu: 'SAMPUNGU1',
        nama_regu: 'SAMPUNGU1',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 420,
        avg_durasi_response: 7,
        min_durasi_response: 420,
        max_durasi_response: 420,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 771,
        avg_durasi_recovery: 12,
        min_durasi_recovery: 771,
        max_durasi_recovery: 771,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 1,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44340,
        nama_ulp: 'ULP BIMA KOTA',
        id_posko: 443401,
        nama_posko: 'POSKO ULP BIMA KOTA',
        id_regu: 19544,
        kode_regu: 'GABI1',
        nama_regu: 'GABI1',
        total: 13,
        total_selesai: 13,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 18753,
        avg_durasi_response: 23.384615384615383,
        min_durasi_response: 887,
        max_durasi_response: 3598,
        total_dibawah_sla_response: 12,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 34004,
        avg_durasi_recovery: 43.07692307692308,
        min_durasi_recovery: 1725,
        max_durasi_recovery: 4581,
        total_dibawah_sla_recovery: 13,
        total_diatas_sla_recovery: 0,
        total_response: 13,
        total_recovery: 13
      },
      {
        id: 2,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 31701,
        kode_regu: 'ULCWOHA',
        nama_regu: 'ULCWOHA',
        total: 8,
        total_selesai: 8,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 10462,
        avg_durasi_response: 21.125,
        min_durasi_response: 312,
        max_durasi_response: 2393,
        total_dibawah_sla_response: 8,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 15311,
        avg_durasi_recovery: 31.375,
        min_durasi_recovery: 942,
        max_durasi_recovery: 3338,
        total_dibawah_sla_recovery: 8,
        total_diatas_sla_recovery: 0,
        total_response: 8,
        total_recovery: 8
      },
      {
        id: 3,
        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',
        id_regu: 37136,
        kode_regu: 'GADOM2',
        nama_regu: 'GADOM2',
        total: 9,
        total_selesai: 9,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 19629,
        avg_durasi_response: 54,
        min_durasi_response: 1136,
        max_durasi_response: 6826,
        total_dibawah_sla_response: 3,
        total_diatas_sla_response: 3,
        total_durasi_recovery: 20047,
        avg_durasi_recovery: 66.2,
        min_durasi_recovery: 2047,
        max_durasi_recovery: 7721,
        total_dibawah_sla_recovery: 5,
        total_diatas_sla_recovery: 0,
        total_response: 6,
        total_recovery: 5
      },
      {
        id: 4,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 24498,
        kode_regu: 'GAMON1',
        nama_regu: 'GAMON 1',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1309,
        avg_durasi_response: 21,
        min_durasi_response: 1309,
        max_durasi_response: 1309,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 2477,
        avg_durasi_recovery: 41,
        min_durasi_recovery: 2477,
        max_durasi_recovery: 2477,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 5,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44340,
        nama_ulp: 'ULP BIMA KOTA',
        id_posko: 443401,
        nama_posko: 'POSKO ULP BIMA KOTA',
        id_regu: 30156,
        kode_regu: 'ULC BIMA',
        nama_regu: 'ULC BIMA',
        total: 12,
        total_selesai: 12,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 11722,
        avg_durasi_response: 21.11111111111111,
        min_durasi_response: 720,
        max_durasi_response: 2545,
        total_dibawah_sla_response: 9,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 15330,
        avg_durasi_recovery: 27.88888888888889,
        min_durasi_recovery: 1121,
        max_durasi_recovery: 2901,
        total_dibawah_sla_recovery: 9,
        total_diatas_sla_recovery: 0,
        total_response: 9,
        total_recovery: 9
      },
      {
        id: 6,
        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',
        id_regu: null,
        kode_regu: null,
        nama_regu: null,
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: null,
        avg_durasi_response: null,
        min_durasi_response: null,
        max_durasi_response: null,
        total_dibawah_sla_response: 0,
        total_diatas_sla_response: 0,
        total_durasi_recovery: null,
        avg_durasi_recovery: null,
        min_durasi_recovery: null,
        max_durasi_recovery: null,
        total_dibawah_sla_recovery: 0,
        total_diatas_sla_recovery: 0,
        total_response: 0,
        total_recovery: 0
      },
      {
        id: 7,
        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',
        id_regu: 24499,
        kode_regu: 'GAHU',
        nama_regu: 'GAHU',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 4954,
        avg_durasi_response: 41,
        min_durasi_response: 1527,
        max_durasi_response: 3427,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 7212,
        avg_durasi_recovery: 60,
        min_durasi_recovery: 3303,
        max_durasi_recovery: 3909,
        total_dibawah_sla_recovery: 2,
        total_diatas_sla_recovery: 0,
        total_response: 2,
        total_recovery: 2
      },
      {
        id: 8,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: 34661,
        kode_regu: '44310GANIP',
        nama_regu: '44310.GANIP',
        total: 4,
        total_selesai: 4,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 3811,
        avg_durasi_response: 15.5,
        min_durasi_response: 736,
        max_durasi_response: 1216,
        total_dibawah_sla_response: 4,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 5949,
        avg_durasi_recovery: 24.25,
        min_durasi_recovery: 1137,
        max_durasi_recovery: 2171,
        total_dibawah_sla_recovery: 4,
        total_diatas_sla_recovery: 0,
        total_response: 4,
        total_recovery: 4
      },
      {
        id: 9,
        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',
        id_regu: 29096,
        kode_regu: 'GAKO',
        nama_regu: 'GAKO',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 6272,
        avg_durasi_response: 34.333333333333336,
        min_durasi_response: 1443,
        max_durasi_response: 3050,
        total_dibawah_sla_response: 2,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 9943,
        avg_durasi_recovery: 55,
        min_durasi_recovery: 2049,
        max_durasi_recovery: 4767,
        total_dibawah_sla_recovery: 3,
        total_diatas_sla_recovery: 0,
        total_response: 3,
        total_recovery: 3
      },
      {
        id: 10,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: null,
        kode_regu: null,
        nama_regu: null,
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: null,
        avg_durasi_response: null,
        min_durasi_response: null,
        max_durasi_response: null,
        total_dibawah_sla_response: 0,
        total_diatas_sla_response: 0,
        total_durasi_recovery: null,
        avg_durasi_recovery: null,
        min_durasi_recovery: null,
        max_durasi_recovery: null,
        total_dibawah_sla_recovery: 0,
        total_diatas_sla_recovery: 0,
        total_response: 0,
        total_recovery: 0
      },
      {
        id: 11,
        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',
        id_regu: 24502,
        kode_regu: 'GASANG',
        nama_regu: 'GASANG',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1070,
        avg_durasi_response: 17,
        min_durasi_response: 1070,
        max_durasi_response: 1070,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 1642,
        avg_durasi_recovery: 27,
        min_durasi_recovery: 1642,
        max_durasi_recovery: 1642,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 12,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: 34656,
        kode_regu: '44310.GALU',
        nama_regu: '44310.GALU',
        total: 5,
        total_selesai: 5,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 5445,
        avg_durasi_response: 17.6,
        min_durasi_response: 717,
        max_durasi_response: 1446,
        total_dibawah_sla_response: 5,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 9921,
        avg_durasi_recovery: 32.6,
        min_durasi_recovery: 1698,
        max_durasi_recovery: 2204,
        total_dibawah_sla_recovery: 5,
        total_diatas_sla_recovery: 0,
        total_response: 5,
        total_recovery: 5
      },
      {
        id: 13,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44340,
        nama_ulp: 'ULP BIMA KOTA',
        id_posko: 443401,
        nama_posko: 'POSKO ULP BIMA KOTA',
        id_regu: 29041,
        kode_regu: '44340.KOLO',
        nama_regu: 'KOLO',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 3244,
        avg_durasi_response: 17.333333333333332,
        min_durasi_response: 206,
        max_durasi_response: 1967,
        total_dibawah_sla_response: 3,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 6192,
        avg_durasi_recovery: 34,
        min_durasi_recovery: 522,
        max_durasi_recovery: 3616,
        total_dibawah_sla_recovery: 3,
        total_diatas_sla_recovery: 0,
        total_response: 3,
        total_recovery: 3
      },
      {
        id: 14,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 29046,
        kode_regu: 'PARADO1',
        nama_regu: 'PARADO1',
        total: 4,
        total_selesai: 4,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 2587,
        avg_durasi_response: 14,
        min_durasi_response: 676,
        max_durasi_response: 1083,
        total_dibawah_sla_response: 3,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 6437,
        avg_durasi_recovery: 35.333333333333336,
        min_durasi_recovery: 1980,
        max_durasi_recovery: 2249,
        total_dibawah_sla_recovery: 3,
        total_diatas_sla_recovery: 0,
        total_response: 3,
        total_recovery: 3
      },
      {
        id: 15,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44340,
        nama_ulp: 'ULP BIMA KOTA',
        id_posko: 443401,
        nama_posko: 'POSKO ULP BIMA KOTA',
        id_regu: null,
        kode_regu: null,
        nama_regu: null,
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: null,
        avg_durasi_response: null,
        min_durasi_response: null,
        max_durasi_response: null,
        total_dibawah_sla_response: 0,
        total_diatas_sla_response: 0,
        total_durasi_recovery: null,
        avg_durasi_recovery: null,
        min_durasi_recovery: null,
        max_durasi_recovery: null,
        total_dibawah_sla_recovery: 0,
        total_diatas_sla_recovery: 0,
        total_response: 0,
        total_recovery: 0
      },
      {
        id: 16,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 29042,
        kode_regu: 'DONGGO1',
        nama_regu: 'DONGGO1',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 997,
        avg_durasi_response: 16,
        min_durasi_response: 997,
        max_durasi_response: 997,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 1259,
        avg_durasi_recovery: 20,
        min_durasi_recovery: 1259,
        max_durasi_recovery: 1259,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 17,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 19542,
        kode_regu: 'GAWO1',
        nama_regu: 'GAWO1',
        total: 7,
        total_selesai: 7,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 7835,
        avg_durasi_response: 18,
        min_durasi_response: 773,
        max_durasi_response: 2371,
        total_dibawah_sla_response: 7,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 14448,
        avg_durasi_recovery: 39.666666666666664,
        min_durasi_recovery: 1766,
        max_durasi_recovery: 4421,
        total_dibawah_sla_recovery: 6,
        total_diatas_sla_recovery: 0,
        total_response: 7,
        total_recovery: 6
      },
      {
        id: 18,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 30856,
        kode_regu: 'ULCMONTA',
        nama_regu: 'ULCMONTA',
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1858,
        avg_durasi_response: 15,
        min_durasi_response: 812,
        max_durasi_response: 1046,
        total_dibawah_sla_response: 2,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 4328,
        avg_durasi_recovery: 35.5,
        min_durasi_recovery: 1633,
        max_durasi_recovery: 2695,
        total_dibawah_sla_recovery: 2,
        total_diatas_sla_recovery: 0,
        total_response: 2,
        total_recovery: 2
      },
      {
        id: 19,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: 34659,
        kode_regu: '44310.GATA',
        nama_regu: '44310.GATA',
        total: 5,
        total_selesai: 5,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 4116,
        avg_durasi_response: 13.2,
        min_durasi_response: 752,
        max_durasi_response: 894,
        total_dibawah_sla_response: 5,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 9957,
        avg_durasi_recovery: 32.6,
        min_durasi_recovery: 1499,
        max_durasi_recovery: 2444,
        total_dibawah_sla_recovery: 5,
        total_diatas_sla_recovery: 0,
        total_response: 5,
        total_recovery: 5
      },
      {
        id: 20,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 29045,
        kode_regu: 'KUTAWAWO1',
        nama_regu: 'KUTAWAWO1',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1050,
        avg_durasi_response: 17,
        min_durasi_response: 1050,
        max_durasi_response: 1050,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 1675,
        avg_durasi_recovery: 27,
        min_durasi_recovery: 1675,
        max_durasi_recovery: 1675,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 21,
        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',
        id_regu: 24503,
        kode_regu: 'GAKAT',
        nama_regu: 'GAKAT',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1938,
        avg_durasi_response: 32,
        min_durasi_response: 1938,
        max_durasi_response: 1938,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 2975,
        avg_durasi_recovery: 49,
        min_durasi_recovery: 2975,
        max_durasi_recovery: 2975,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 22,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: 24501,
        kode_regu: 'GASAP 3',
        nama_regu: 'GASAP 3',
        total: 8,
        total_selesai: 8,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 13364,
        avg_durasi_response: 27.375,
        min_durasi_response: 780,
        max_durasi_response: 3808,
        total_dibawah_sla_response: 7,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 23245,
        avg_durasi_recovery: 48,
        min_durasi_recovery: 1654,
        max_durasi_recovery: 5187,
        total_dibawah_sla_recovery: 8,
        total_diatas_sla_recovery: 0,
        total_response: 8,
        total_recovery: 8
      },
      {
        id: 23,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44330,
        nama_ulp: 'ULP WOHA',
        id_posko: 443301,
        nama_posko: 'POSKO ULP WOHA',
        id_regu: 24497,
        kode_regu: 'GABO 1',
        nama_regu: 'GABO 1',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 1106,
        avg_durasi_response: 18,
        min_durasi_response: 1106,
        max_durasi_response: 1106,
        total_dibawah_sla_response: 1,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 2223,
        avg_durasi_recovery: 37,
        min_durasi_recovery: 2223,
        max_durasi_recovery: 2223,
        total_dibawah_sla_recovery: 1,
        total_diatas_sla_recovery: 0,
        total_response: 1,
        total_recovery: 1
      },
      {
        id: 24,
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44310,
        nama_ulp: 'ULP SAPE',
        id_posko: 443101,
        nama_posko: 'POSKO ULP SAPE',
        id_regu: 34662,
        kode_regu: '44310.GAWA',
        nama_regu: '44310.GAWA',
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 2809,
        avg_durasi_response: 22.5,
        min_durasi_response: 1255,
        max_durasi_response: 1554,
        total_dibawah_sla_response: 2,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 5058,
        avg_durasi_recovery: 41.5,
        min_durasi_recovery: 2313,
        max_durasi_recovery: 2745,
        total_dibawah_sla_recovery: 2,
        total_diatas_sla_recovery: 0,
        total_response: 2,
        total_recovery: 2
      },
      {
        id: 25,
        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',
        id_regu: 24496,
        kode_regu: 'GASOR',
        nama_regu: 'GASOR',
        total: 19,
        total_selesai: 19,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 56100,
        avg_durasi_response: 54.588235294117645,
        min_durasi_response: 1715,
        max_durasi_response: 6854,
        total_dibawah_sla_response: 6,
        total_diatas_sla_response: 11,
        total_durasi_recovery: 82343,
        avg_durasi_recovery: 80.23529411764706,
        min_durasi_recovery: 2855,
        max_durasi_recovery: 8171,
        total_dibawah_sla_recovery: 17,
        total_diatas_sla_recovery: 0,
        total_response: 17,
        total_recovery: 17
      },
      {
        id: 26,
        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',
        id_regu: 19541,
        kode_regu: 'GADOM1',
        nama_regu: 'GADOM1',
        total: 35,
        total_selesai: 35,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 118249,
        avg_durasi_response: 67.44827586206897,
        min_durasi_response: 1713,
        max_durasi_response: 8073,
        total_dibawah_sla_response: 8,
        total_diatas_sla_response: 21,
        total_durasi_recovery: 145117,
        avg_durasi_recovery: 85.85714285714286,
        min_durasi_recovery: 2443,
        max_durasi_recovery: 8387,
        total_dibawah_sla_recovery: 28,
        total_diatas_sla_recovery: 0,
        total_response: 29,
        total_recovery: 28
      },
      {
        id: 27,
        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',
        id_regu: 29097,
        kode_regu: 'GALO',
        nama_regu: 'GALO',
        total: 4,
        total_selesai: 4,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_durasi_response: 4929,
        avg_durasi_response: 27,
        min_durasi_response: 1595,
        max_durasi_response: 1682,
        total_dibawah_sla_response: 3,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 7014,
        avg_durasi_recovery: 38.666666666666664,
        min_durasi_recovery: 1880,
        max_durasi_recovery: 3013,
        total_dibawah_sla_recovery: 3,
        total_diatas_sla_recovery: 0,
        total_response: 3,
        total_recovery: 3
      }
    ]
  }
})
</script>
