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

  <div>
    <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"
      @exporting="onExporting"
      :allow-column-resizing="true"
      column-resizing-mode="widget"
      :word-wrap-enabled="true"
    >
      <DxGrouping expand-mode="rowClick" />
      <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="50"
        alignment="center"
        caption="NO"
        css-class="custom-table-column"
        data-type="number"
        data-field="number"
        cell-template="formatNumber"
      />

      <DxColumn
        :width="120"
        alignment="center"
        data-field="nama_up3"
        caption="UP3"
        css-class="custom-table-column"
        :group-index="0"
      />

      <DxColumn
        :width="170"
        alignment="center"
        data-field="nama_ulp"
        caption="Unit"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
        <DxColumn
          :width="150"
          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="150"
            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="150"
            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="Hari" css-class="custom-table-column">
          <DxColumn
            :width="150"
            alignment="center"
            data-field="total_durasi_response"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :visible="false"
            :width="150"
            alignment="center"
            data-field="count_durasi_response"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
            :calculate-cell-value="
              (rowData: any) => rowData.total_durasi_response * rowData.avg_durasi_response
            "
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="avg_durasi_response"
            data-type="number"
            caption="Rata-Rata"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="max_durasi_response"
            data-type="number"
            caption="Max"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            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="150"
            alignment="center"
            data-field="total_diatas_sla_response"
            data-type="number"
            caption=">SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            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="Penyelesaian" css-class="custom-table-column">
        <DxColumn alignment="center" caption="Hari" css-class="custom-table-column">
          <DxColumn
            :width="150"
            alignment="center"
            data-field="total_durasi_recovery"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :visible="false"
            :width="150"
            alignment="center"
            data-field="count_durasi_recovery"
            data-type="number"
            caption="Total"
            css-class="custom-table-column"
            cell-template="formatNumber"
            :calculate-cell-value="
              (rowData: any) => rowData.total_durasi_recovery * rowData.avg_durasi_recovery
            "
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="avg_durasi_recovery"
            data-type="number"
            caption="Rata-Rata"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="max_durasi_recovery"
            data-type="number"
            caption="Max"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            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="150"
            alignment="center"
            data-field="total_diatas_sla_recovery"
            data-type="number"
            caption=">SLA"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            :width="150"
            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
          display-format="Total"
          show-in-column="nama_ulp"
          css-class="!text-left"
          :show-in-group-footer="true"
        />
        <DxGroupItem
          summary-type="custom"
          name="total"
          column="total"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="total_selesai"
          column="total_selesai"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="persen_selesai"
          column="persen_selesai"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="total_inproses"
          column="total_inproses"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="persen_inproses"
          column="persen_inproses"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatPercentage(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="total_durasi_response"
          column="total_durasi_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="count_durasi_response"
          column="count_durasi_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="avg_durasi_response"
          column="avg_durasi_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="min"
          display-format="{0}"
          column="min_durasi_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          summary-type="max"
          display-format="{0}"
          column="max_durasi_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          summary-type="sum"
          display-format="{0}"
          column="total_diatas_sla_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="sum"
          display-format="{0}"
          column="total_dibawah_sla_response"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="total_durasi_recovery"
          column="total_durasi_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="count_durasi_recovery"
          column="count_durasi_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="custom"
          name="avg_durasi_recovery"
          column="avg_durasi_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="min"
          display-format="{0}"
          column="min_durasi_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          summary-type="max"
          display-format="{0}"
          column="max_durasi_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => (parseInt(e.value) ? formatWaktu(e.value) : '-')"
        />
        <DxGroupItem
          summary-type="sum"
          display-format="{0}"
          column="total_diatas_sla_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />
        <DxGroupItem
          summary-type="sum"
          display-format="{0}"
          column="total_dibawah_sla_recovery"
          css-class="!text-right"
          :show-in-group-footer="true"
          :customize-text="(e: any) => formatNumber(e.value)"
        />

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

      <template #formatTime="{ data }">
        <p class="cursor-pointer !text-right" @click="setAgreementDialog(false, 0)">
          {{ parseInt(data.text) ? formatWaktu(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 #formatText="{ data }" @click="setAgreementDialog(false, 0)">
        <p class="text-left cursor-pointer">
          {{ data.text }}
        </p>
      </template>
    </DxDataGrid>
  </div>

  <DetailDialog
    :open="dialogDetail"
    title="Rekapitulasi Keluhan Per Unit"
    @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) => 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="Dalam Proses Bidang"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="waktu_recovery"
            caption="Selesai Bidang Unit"
            :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="status_akhir"
            caption="Status"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="idpel_nometer"
            caption="IDPEL/NO METER"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <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 Tlp 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="nama_ulp"
            caption="Rayon"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="uraian"
            caption="Uraian"
            :allow-resizing="false"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field="respon_pelanggan"
            caption="Respon Pelanggan"
            :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">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">Dalam Proses Bidang:</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">Selesai Bidang Unit:</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">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">Rayon:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.nama_ulp" 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">Uraian:</h3>
          <InputText
            :readonly="true"
            type="textarea"
            :value="dataSubSelected?.uraian"
            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">Response Pelanggan:</h3>
          <InputText
            :readonly="true"
            type="textarea"
            :value="dataSubSelected?.respon_pelanggan"
            class-name="flex-1"
          />
        </div>
      </div>
    </div>
  </DetailDialog>
  <BufferDialog v-if="loadingData || loadingSubData" />
</template>

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

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 closedialogDetail = () => (dialogDetail.value = false)
const loadingData = ref(false)
const loadingSubData = ref(false)
const agreeToShowDialog = ref(false)
const progressSelected = ref(0)
const reportMeta = ref({
  uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
  up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
  periode: ''
})

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 = !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 === '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 = !isFinite(count_durasi_response / total_durasi_response)
        ? 0
        : count_durasi_response == 0
          ? 0
          : 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 = !isFinite(count_durasi_recovery / total_durasi_recovery)
        ? 0
        : count_durasi_recovery == 0
          ? 0
          : count_durasi_recovery / total_durasi_recovery
    }
  }
}

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

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

const filterData = async (params: any) => {
  resetData()
  const dateValue = params.periode.split(' s/d ')
  const { ulp, uid, up3 } = params
  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),
    idUlp: ulp ? ulp.id : 0,
    idUid: uid ? uid.id : 0,
    idUp3: up3 ? up3.id : 0
  }

  loadingData.value = true
  await requestGraphQl(queries.keluhan.rekap.keluhanPerUnit, query)
    .then((result) => {
      if (result.data.data != undefined) {
        data.value = [...result.data.data.rekapitulasiKeluhanPerUnit]
          .sort((a, b) => a.nama_up3.localeCompare(b.nama_up3))
          .map((item, index) => {
            return {
              ...item,
              number: index + 1
            }
          })
      } else {
        data.value = []
      }

      reportMeta.value = {
        uid: uid ? uid : { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
        up3: up3 ? up3 : { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
        periode: params.periode
      }
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {
      loadingData.value = false
    })
}

const getDetail = async () => {
  const dateValue = filters.value.periode.split(' s/d ')
  const selected = 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),
    idUlp: selected?.id_ulp ? selected?.id_ulp : 0,
    idUid: selected?.id_uid ? selected?.id_uid : 0,
    idUp3: selected?.id_up3 ? selected?.id_up3 : 0,
    namaRegional: selected?.nama_regional ? selected?.nama_regional : '',
    isSelesai: progressSelected.value,
    media: '',
    tanggal: '',
    namaIssuetype: '',
    namaSubissuetype: ''
  }

  loadingSubData.value = true
  await requestGraphQl(queries.keluhan.rekap.rekapKeluhanAllDetail, query)
    .then((result) => {
      if (result.data.data != undefined) {
        dataSub.value = result.data.data.detailKeluhanAll
      } 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()
  dataSubSelected.value = null
  if (agreeToShowDialog.value) {
    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: 0,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 120,
        nama_uid: 'WILAYAH SUMATERA UTARA',
        id_up3: 12100,
        nama_up3: 'UP3 PEMATANG SIANTAR',
        id_ulp: 12102,
        nama_ulp: 'ULP LIMA PULUH',
        total: 11,
        total_selesai: 1,
        persen_selesai: 9.090909090909092,
        total_inproses: 10,
        persen_inproses: 90.9090909090909,
        total_durasi_response: 10193,
        avg_durasi_response: 1019.3,
        min_durasi_response: 379,
        max_durasi_response: 1782,
        total_dibawah_sla_response: 7,
        total_diatas_sla_response: 3,
        total_durasi_recovery: 13701,
        avg_durasi_recovery: 1245.5454545454545,
        min_durasi_recovery: 388,
        max_durasi_recovery: 2501,
        total_dibawah_sla_recovery: 11,
        total_diatas_sla_recovery: 0
      },
      {
        id: 1,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 41,
        nama_uid: 'WILAYAH MALUKU DAN MALUKU UTARA',
        id_up3: 412,
        nama_up3: 'UP3 TERNATE',
        id_ulp: 41230,
        nama_ulp: 'ULP BACAN',
        total: 6,
        total_selesai: 4,
        persen_selesai: 66.66666666666666,
        total_inproses: 2,
        persen_inproses: 33.33333333333333,
        total_durasi_response: 7291,
        avg_durasi_response: 1458.2,
        min_durasi_response: 308,
        max_durasi_response: 2736,
        total_dibawah_sla_response: 2,
        total_diatas_sla_response: 3,
        total_durasi_recovery: 19860,
        avg_durasi_recovery: 3310,
        min_durasi_recovery: 2152,
        max_durasi_recovery: 6176,
        total_dibawah_sla_recovery: 5,
        total_diatas_sla_recovery: 1
      },
      {
        id: 2,
        nama_regional: 'REGIONAL JMB',
        id_uid: 101,
        nama_uid: 'DISTRIBUSI JAWA TENGAH & DIY',
        id_up3: 52150,
        nama_up3: 'UP3 MAGELANG',
        id_ulp: 52156,
        nama_ulp: 'ULP PARAKAN',
        total: 56,
        total_selesai: 15,
        persen_selesai: 26.785714285714285,
        total_inproses: 41,
        persen_inproses: 73.21428571428571,
        total_durasi_response: 145058,
        avg_durasi_response: 3086.340425531915,
        min_durasi_response: 459,
        max_durasi_response: 8933,
        total_dibawah_sla_response: 11,
        total_diatas_sla_response: 36,
        total_durasi_recovery: 204948,
        avg_durasi_recovery: 3659.785714285714,
        min_durasi_recovery: 1,
        max_durasi_recovery: 15497,
        total_dibawah_sla_recovery: 43,
        total_diatas_sla_recovery: 13
      },
      {
        id: 3,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 31,
        nama_uid: 'WILAYAH SULAWESI UTARA,TENGAH DAN GORONTALO',
        id_up3: 31500,
        nama_up3: 'UP3 TOLITOLI',
        id_ulp: 31530,
        nama_ulp: 'ULP BANGKIR',
        total: 56,
        total_selesai: 23,
        persen_selesai: 41.07142857142857,
        total_inproses: 33,
        persen_inproses: 58.92857142857143,
        total_durasi_response: 14809,
        avg_durasi_response: 643.8695652173913,
        min_durasi_response: 63,
        max_durasi_response: 6694,
        total_dibawah_sla_response: 22,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 63412,
        avg_durasi_recovery: 1132.357142857143,
        min_durasi_recovery: 76,
        max_durasi_recovery: 6815,
        total_dibawah_sla_recovery: 52,
        total_diatas_sla_recovery: 4
      },
      {
        id: 4,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 154,
        nama_up3: 'UP3 SITUBONDO',
        id_ulp: 51654,
        nama_ulp: 'ULP WONOSARI',
        total: 92,
        total_selesai: 0,
        persen_selesai: 0,
        total_inproses: 92,
        persen_inproses: 100,
        total_durasi_response: 201431,
        avg_durasi_response: 2426.879518072289,
        min_durasi_response: 14,
        max_durasi_response: 22160,
        total_dibawah_sla_response: 54,
        total_diatas_sla_response: 29,
        total_durasi_recovery: 856596,
        avg_durasi_recovery: 9310.826086956522,
        min_durasi_recovery: 0,
        max_durasi_recovery: 74239,
        total_dibawah_sla_recovery: 49,
        total_diatas_sla_recovery: 43
      },
      {
        id: 5,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 110,
        nama_uid: 'WILAYAH ACEH',
        id_up3: 116,
        nama_up3: 'UP3 SIGLI',
        id_ulp: 11662,
        nama_ulp: 'ULP MEUREUDU',
        total: 8,
        total_selesai: 0,
        persen_selesai: 0,
        total_inproses: 8,
        persen_inproses: 100,
        total_durasi_response: 3766,
        avg_durasi_response: 470.75,
        min_durasi_response: 99,
        max_durasi_response: 1322,
        total_dibawah_sla_response: 8,
        total_diatas_sla_response: 0,
        total_durasi_recovery: 4463,
        avg_durasi_recovery: 557.875,
        min_durasi_recovery: 132,
        max_durasi_recovery: 1390,
        total_dibawah_sla_recovery: 8,
        total_diatas_sla_recovery: 0
      },
      {
        id: 6,
        nama_regional: 'REGIONAL JMB',
        id_uid: 287,
        nama_uid: 'DISTRIBUSI BALI',
        id_up3: 329,
        nama_up3: 'UP3 BALI UTARA',
        id_ulp: 55340,
        nama_ulp: 'ULP GILIMANUK',
        total: 47,
        total_selesai: 19,
        persen_selesai: 40.42553191489361,
        total_inproses: 28,
        persen_inproses: 59.57446808510638,
        total_durasi_response: 47015,
        avg_durasi_response: 1000.3191489361702,
        min_durasi_response: 22,
        max_durasi_response: 14684,
        total_dibawah_sla_response: 42,
        total_diatas_sla_response: 5,
        total_durasi_recovery: 74421,
        avg_durasi_recovery: 1583.4255319148936,
        min_durasi_recovery: 257,
        max_durasi_recovery: 14769,
        total_dibawah_sla_recovery: 44,
        total_diatas_sla_recovery: 3
      },
      {
        id: 7,
        nama_regional: null,
        id_uid: 0,
        nama_uid: '',
        id_up3: 0,
        nama_up3: '',
        id_ulp: 22450,
        nama_ulp: 'ULP PANGKALAN BUN',
        total: 167,
        total_selesai: 0,
        persen_selesai: 0,
        total_inproses: 167,
        persen_inproses: 100,
        total_durasi_response: 118469,
        avg_durasi_response: 789.7933333333333,
        min_durasi_response: 52,
        max_durasi_response: 3752,
        total_dibawah_sla_response: 135,
        total_diatas_sla_response: 15,
        total_durasi_recovery: 173448,
        avg_durasi_recovery: 1038.6107784431138,
        min_durasi_recovery: 0,
        max_durasi_recovery: 3793,
        total_dibawah_sla_recovery: 167,
        total_diatas_sla_recovery: 0
      },
      {
        id: 8,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 131,
        nama_uid: 'WILAYAH SUMATERA BARAT',
        id_up3: 13300,
        nama_up3: 'UP3 SOLOK',
        id_ulp: 13334,
        nama_ulp: 'ULP SILUNGKANG',
        total: 1,
        total_selesai: 0,
        persen_selesai: 0,
        total_inproses: 1,
        persen_inproses: 100,
        total_durasi_response: 5118,
        avg_durasi_response: 5118,
        min_durasi_response: 5118,
        max_durasi_response: 5118,
        total_dibawah_sla_response: 0,
        total_diatas_sla_response: 1,
        total_durasi_recovery: 5696,
        avg_durasi_recovery: 5696,
        min_durasi_recovery: 5696,
        max_durasi_recovery: 5696,
        total_dibawah_sla_recovery: 0,
        total_diatas_sla_recovery: 1
      },
      {
        id: 9,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 221,
        nama_uid: 'WILAYAH KALIMANTAN SELATAN DAN TENGAH',
        id_up3: 2220,
        nama_up3: 'UP3 BARABAI',
        id_ulp: 22230,
        nama_ulp: 'ULP AMUNTAI',
        total: 48,
        total_selesai: 4,
        persen_selesai: 8.333333333333332,
        total_inproses: 44,
        persen_inproses: 91.66666666666666,
        total_durasi_response: 25050,
        avg_durasi_response: 532.9787234042553,
        min_durasi_response: 58,
        max_durasi_response: 2352,
        total_dibawah_sla_response: 44,
        total_diatas_sla_response: 3,
        total_durasi_recovery: 49151,
        avg_durasi_recovery: 1023.9791666666666,
        min_durasi_recovery: 129,
        max_durasi_recovery: 2853,
        total_dibawah_sla_recovery: 48,
        total_diatas_sla_recovery: 0
      },
      {
        id: 10,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 31,
        nama_uid: 'WILAYAH SULAWESI UTARA,TENGAH DAN GORONTALO',
        id_up3: 31700,
        nama_up3: 'UP3 KOTAMOBAGU',
        id_ulp: 31730,
        nama_ulp: 'ULP MODAYAG',
        total: 21,
        total_selesai: 11,
        persen_selesai: 52.38095238095239,
        total_inproses: 10,
        persen_inproses: 47.61904761904761,
        total_durasi_response: 11456,
        avg_durasi_response: 716,
        min_durasi_response: 126,
        max_durasi_response: 2376,
        total_dibawah_sla_response: 13,
        total_diatas_sla_response: 3,
        total_durasi_recovery: 30489,
        avg_durasi_recovery: 1451.857142857143,
        min_durasi_recovery: 0,
        max_durasi_recovery: 3482,
        total_dibawah_sla_recovery: 21,
        total_diatas_sla_recovery: 0
      },
      {
        id: 11,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 546,
        nama_up3: 'UP3 TASIKMALAYA',
        id_ulp: 53231,
        nama_ulp: 'ULP CIAMIS',
        total: 123,
        total_selesai: 16,
        persen_selesai: 13.008130081300814,
        total_inproses: 107,
        persen_inproses: 86.99186991869918,
        total_durasi_response: 476405,
        avg_durasi_response: 5881.543209876543,
        min_durasi_response: 46,
        max_durasi_response: 41257,
        total_dibawah_sla_response: 21,
        total_diatas_sla_response: 60,
        total_durasi_recovery: 1177396,
        avg_durasi_recovery: 9572.325203252032,
        min_durasi_recovery: 0,
        max_durasi_recovery: 45912,
        total_dibawah_sla_recovery: 57,
        total_diatas_sla_recovery: 66
      },
      {
        id: 12,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 157,
        nama_up3: 'UP3 SURABAYA UTARA',
        id_ulp: 51101,
        nama_ulp: 'ULP INDRAPURA',
        total: 139,
        total_selesai: 131,
        persen_selesai: 94.24460431654677,
        total_inproses: 8,
        persen_inproses: 5.755395683453238,
        total_durasi_response: 491177,
        avg_durasi_response: 3749.442748091603,
        min_durasi_response: 18,
        max_durasi_response: 20546,
        total_dibawah_sla_response: 51,
        total_diatas_sla_response: 80,
        total_durasi_recovery: 775066,
        avg_durasi_recovery: 5576.014388489209,
        min_durasi_recovery: 1,
        max_durasi_recovery: 49206,
        total_dibawah_sla_recovery: 78,
        total_diatas_sla_recovery: 61
      },
      {
        id: 13,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 41,
        nama_uid: 'WILAYAH MALUKU DAN MALUKU UTARA',
        id_up3: 414,
        nama_up3: 'UP3 MASOHI',
        id_ulp: 41430,
        nama_ulp: 'ULP MASOHI',
        total: 19,
        total_selesai: 17,
        persen_selesai: 89.47368421052632,
        total_inproses: 2,
        persen_inproses: 10.526315789473683,
        total_durasi_response: 18570,
        avg_durasi_response: 1092.3529411764705,
        min_durasi_response: 480,
        max_durasi_response: 2337,
        total_dibawah_sla_response: 13,
        total_diatas_sla_response: 4,
        total_durasi_recovery: 41850,
        avg_durasi_recovery: 2202.6315789473683,
        min_durasi_recovery: 22,
        max_durasi_recovery: 4386,
        total_dibawah_sla_recovery: 18,
        total_diatas_sla_recovery: 1
      },
      {
        id: 14,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 131,
        nama_uid: 'WILAYAH SUMATERA BARAT',
        id_up3: 13100,
        nama_up3: 'UP3 PADANG',
        id_ulp: 13105,
        nama_ulp: 'ULP LUBUK ALUNG',
        total: 67,
        total_selesai: 56,
        persen_selesai: 83.5820895522388,
        total_inproses: 11,
        persen_inproses: 16.417910447761194,
        total_durasi_response: 67996,
        avg_durasi_response: 1214.2142857142858,
        min_durasi_response: 45,
        max_durasi_response: 17051,
        total_dibawah_sla_response: 48,
        total_diatas_sla_response: 8,
        total_durasi_recovery: 546970,
        avg_durasi_recovery: 8163.731343283582,
        min_durasi_recovery: 0,
        max_durasi_recovery: 221267,
        total_dibawah_sla_recovery: 40,
        total_diatas_sla_recovery: 27
      }
    ]
      .sort((a, b) => a.nama_up3.localeCompare(b.nama_up3))
      .map((item, index) => {
        return {
          ...item,
          number: index + 1
        }
      })
  }
})
</script>
