<template>
  <Filters
    @run-report="() => exportToPDF(reportMeta, data, true)"
    @reset-form="data = []"
    @run-search="() => filterData(filters)"
    :report-button="true"
    class="mb-4"
  >
    <Type1 @update:filters="(value) => (filters = value)" :showPosko="false" />
  </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="onSelectionChanged"
      :column-width="100"
      @exporting="onExporting"
      :allow-column-resizing="true"
      column-resizing-mode="widget"
    >
      <DxGrouping expand-mode="rowClick" />
      <DxSelection mode="single" />
      <DxPaging :enabled="false" />
      <DxScrolling column-rendering-mode="virtual" mode="virtual" />
      <!-- <DxLoadPanel
        shading-color="rgba(0,0,0,0.4)"
        :position="position"
        :show-indicator="showIndicator"
        :show-pane="showPane"
        :shading="shading"
        v-model:visible="loadingData"
        :enabled="true"
      /> -->

      <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"
        data-field="number"
        data-type="number"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="150"
        alignment="center"
        data-field="nama_up3"
        caption="UP3"
        css-class="custom-table-column"
        cell-template="formatText"
        :group-index="0"
      />
      <DxColumn
        :width="150"
        alignment="center"
        data-field="id_posko"
        caption="Kode Unit"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn
        :width="200"
        alignment="center"
        data-field="nama_posko"
        caption="Nama Unit"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
        <DxColumn
          alignment="center"
          data-field="total"
          data-type="number"
          caption="Total"
          css-class="custom-table-column"
          cell-template="formatNumberLaporanTotal"
        />
        <DxColumn alignment="center" caption="Belum Selesai" css-class="custom-table-column">
          <DxColumn
            alignment="center"
            data-field="total_inproses"
            data-type="number"
            caption="Jml"
            css-class="custom-table-column"
            cell-template="formatNumberLaporanJmlBelumSelesai"
          />
          <DxColumn
            alignment="center"
            data-field="persen_inproses"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatPercentage"
          />
        </DxColumn>
        <DxColumn alignment="center" caption="Sudah Selesai" css-class="custom-table-column">
          <DxColumn
            alignment="center"
            data-field="total_selesai"
            data-type="number"
            caption="Jml"
            css-class="custom-table-column"
            cell-template="formatNumberLaporanJmlSelesai"
          />
          <DxColumn
            alignment="center"
            data-field="persen_selesai"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatPercentage"
          />
        </DxColumn>
      </DxColumn>
      <DxColumn alignment="center" caption="Rating" css-class="custom-table-column">
        <DxColumn alignment="center" caption="Bintang" css-class="custom-table-column">
          <DxColumn
            alignment="center"
            data-field="total_rating"
            data-type="number"
            caption="Jml"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="nilai_rating1"
            data-type="number"
            caption="1"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="nilai_rating2"
            data-type="number"
            caption="2"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="nilai_rating3"
            data-type="number"
            caption="3"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="nilai_rating4"
            data-type="number"
            caption="4"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="nilai_rating5"
            data-type="number"
            caption="5"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="indeks_rating"
            data-type="number"
            caption="Index"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </DxColumn>
      </DxColumn>

      <DxColumn alignment="center" caption="Non Rating" css-class="custom-table-column">
        <DxColumn
          alignment="center"
          data-field="total_nonrating"
          data-type="number"
          caption="Jml"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          alignment="center"
          data-field="persen_nonrating"
          data-type="number"
          caption="%"
          css-class="custom-table-column"
          cell-template="formatPercentage"
        />
      </DxColumn>

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

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

  <DetailDialog
    :open="dialogDetail"
    title="Detail Rating Per Posko"
    @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"
          />
          <!-- <DxLoadPanel
            shading-color="rgba(0,0,0,0.4)"
            :position="position"
            :show-indicator="showIndicator"
            :show-pane="showPane"
            :shading="shading"
            v-model:visible="loadingSubData"
            :enabled="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="nilai_rating"
            caption="Rating"
            css-class="custom-table-column"
            cell-template="formatRating"
          />
          <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>

          <template #formatRating="{ data }">
            <div class="flex justify-center cursor-pointer">
              <vue3starRatings
                v-model="data.text"
                :starSize="20"
                starColor="#CCCC00"
                inactiveColor="#D1D5DB"
                :numberOfStars="5"
                :disableClick="true"
              />
            </div>
          </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">Rating:</h3>
          <InputText
            :readonly="true"
            :value="
              parseInt(dataSubSelected?.nilai_rating)
                ? parseInt(dataSubSelected?.nilai_rating) > 0
                  ? `${parseInt(dataSubSelected?.nilai_rating)} Bintang`
                  : `Tidak Ada Bintang`
                : `Tidak Ada Bintang`
            "
            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 Type1 from '@/components/Form/FiltersType/Type1.vue'
import { DxDataGrid } from 'devextreme-vue'
import {
  DxColumn,
  DxColumnFixing,
  DxExport,
  DxGrouping,
  DxLoadPanel,
  DxPager,
  DxPaging,
  DxScrolling,
  DxSearchPanel,
  DxSelection
} from 'devextreme-vue/data-grid'
import { onMounted, ref } from 'vue'
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
import { formatWaktu } from '@/components/Form/FiltersType/reference'
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
import InputText from '@/components/InputText.vue'
import vue3starRatings from 'vue3-star-ratings'
import { apolloClient } from '@/utils/api/api.graphql'
import { provideApolloClient } from '@vue/apollo-composable'
import {
  exportToPDF,
  exportToXLSX,
  exportDetailToPDF,
  exportDetailToXLSX
} from '@/report/Gangguan/Rekap/RGangguan_RatingPerPosko'
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' },
  periode: ''
})
const agreeToShowDialog = ref(false)
const progressSelected = ref(0)

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: '',
    namaIssuetype: '',
    namaSubissuetype: ''
  }

  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 {
  }
}

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

const onSelectionChanged = ({ 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

  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.gangguanRatingPerPosko, query)
    .then((result) => {
      if (result.data.data != undefined) {
        data.value = [...result.data.data.rekapitulasiGangguanRatingPerPosko]
          .sort((a: any, b: any) => a.nama_up3.localeCompare(b.nama_up3))
          .map((ref: any, index: number) => {
            return {
              ...ref,
              number: index + 1
            }
          })
      } else {
        data.value = []
      }

      reportMeta.value = filters.value
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {
      loadingData.value = false
    })
}
const filters = ref()
onMounted(() => {
  if (import.meta.env.DEV) {
    data.value = [
      {
        id: 0,
        nama_regional: null,
        id_uid: 0,
        nama_uid: '',
        id_up3: 0,
        nama_up3: '',
        id_ulp: 0,
        nama_ulp: '',
        id_posko: 0,
        nama_posko: '',
        total: 3169,
        total_selesai: 3169,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 194,
        persen_rating: 6.121804985799937,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 194,
        indeks_rating: 1,
        total_nonrating: 2975,
        persen_nonrating: 93.87819501420006
      },
      {
        id: 1,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 44,
        nama_uid: 'WILAYAH NUSA TENGGARA BARAT',
        id_up3: 443,
        nama_up3: 'UP3 BIMA',
        id_ulp: 44320,
        nama_ulp: 'ULP DOMPU',
        id_posko: 443201,
        nama_posko: 'POSKO ULP DOMPU',
        total: 34,
        total_selesai: 34,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 6,
        persen_rating: 17.647058823529413,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 6,
        indeks_rating: 1,
        total_nonrating: 28,
        persen_nonrating: 82.35294117647058
      },
      {
        id: 2,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 31,
        nama_uid: 'WILAYAH SULAWESI UTARA,TENGAH DAN GORONTALO',
        id_up3: 31600,
        nama_up3: 'UP3 GORONTALO',
        id_ulp: 31620,
        nama_ulp: 'ULP MARISA',
        id_posko: 316201,
        nama_posko: 'POSKO ULP MARISA',
        total: 19,
        total_selesai: 19,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 15,
        persen_rating: 78.94736842105263,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 15,
        indeks_rating: 1,
        total_nonrating: 4,
        persen_nonrating: 21.052631578947366
      },
      {
        id: 3,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 430,
        nama_uid: 'WILAYAH NUSA TENGGARA TIMUR',
        id_up3: 433,
        nama_up3: 'UP3 SUMBA',
        id_ulp: 43380,
        nama_ulp: 'ULP SUMBA BARAT DAYA',
        id_posko: 433801,
        nama_posko: 'POSKO ULP SUMBA BARAT DAYA',
        total: 62,
        total_selesai: 62,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 18,
        persen_rating: 29.03225806451613,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 18,
        indeks_rating: 1,
        total_nonrating: 44,
        persen_nonrating: 70.96774193548387
      },
      {
        id: 4,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 149,
        nama_up3: 'UP3 MOJOKERTO',
        id_ulp: 51460,
        nama_ulp: 'ULP NGANJUK',
        id_posko: 514603,
        nama_posko: 'POSKO ULP NGANJUK',
        total: 183,
        total_selesai: 183,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 47,
        persen_rating: 25.683060109289617,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 1,
        nilai_rating4: 0,
        nilai_rating5: 46,
        indeks_rating: 1.978723404255319,
        total_nonrating: 136,
        persen_nonrating: 74.31693989071039
      },
      {
        id: 5,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 540,
        nama_up3: 'UP3 GARUT',
        id_ulp: 53293,
        nama_ulp: 'ULP LELES',
        id_posko: 532931,
        nama_posko: 'POSKO ULP LELES',
        total: 36,
        total_selesai: 36,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 7,
        persen_rating: 19.444444444444446,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 7,
        indeks_rating: 1,
        total_nonrating: 29,
        persen_nonrating: 80.55555555555556
      },
      {
        id: 6,
        nama_regional: 'REGIONAL JMB',
        id_uid: 2,
        nama_uid: 'DISTRIBUSI JAKARTA RAYA',
        id_up3: 9,
        nama_up3: 'UP3 CIPUTAT',
        id_ulp: 54360,
        nama_ulp: 'UP3 CIPUTAT',
        id_posko: 543601,
        nama_posko: 'POSKO CIPUTAT',
        total: 207,
        total_selesai: 207,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 57,
        persen_rating: 27.536231884057973,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 57,
        indeks_rating: 1,
        total_nonrating: 150,
        persen_nonrating: 72.46376811594203
      },
      {
        id: 7,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 32,
        nama_uid: 'WILAYAH SULAWESI SELATAN, TENGGARA DAN BARAT',
        id_up3: 32700,
        nama_up3: 'UP3 BULUKUMBA',
        id_ulp: 32760,
        nama_ulp: 'ULP SINJAI',
        id_posko: 327601,
        nama_posko: 'POSKO ULP SINJAI',
        total: 26,
        total_selesai: 26,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 1,
        persen_rating: 3.8461538461538463,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 1,
        indeks_rating: 1,
        total_nonrating: 25,
        persen_nonrating: 96.15384615384616
      },
      {
        id: 8,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 140,
        nama_uid: 'WILAYAH SUMATERA SELATAN, JAMBI & BENGKULU (S2JB)',
        id_up3: 1403,
        nama_up3: 'UP3 BENGKULU',
        id_ulp: 14630,
        nama_ulp: 'ULP MUARA AMAN',
        id_posko: 146301,
        nama_posko: 'POSKO ULP MUARA AMAN',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 1,
        persen_rating: 33.33333333333333,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 1,
        indeks_rating: 1,
        total_nonrating: 2,
        persen_nonrating: 66.66666666666666
      },
      {
        id: 9,
        nama_regional: 'REGIONAL JMB',
        id_uid: 56,
        nama_uid: 'DISTRIBUSI BANTEN',
        id_up3: 534,
        nama_up3: 'UP3 BANTEN UTARA',
        id_ulp: 56120,
        nama_ulp: 'ULP CILEGON',
        id_posko: 561201,
        nama_posko: 'POSKO ULP CILEGON',
        total: 55,
        total_selesai: 55,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 14,
        persen_rating: 25.454545454545453,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 14,
        indeks_rating: 1,
        total_nonrating: 41,
        persen_nonrating: 74.54545454545455
      },
      {
        id: 10,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 110,
        nama_uid: 'WILAYAH ACEH',
        id_up3: 114,
        nama_up3: 'UP3 MEULABOH',
        id_ulp: 11443,
        nama_ulp: 'ULP SINABANG',
        id_posko: 114431,
        nama_posko: 'POSKO ULP SINABANG',
        total: 9,
        total_selesai: 9,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 4,
        persen_rating: 44.44444444444444,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 4,
        indeks_rating: 1,
        total_nonrating: 5,
        persen_nonrating: 55.55555555555556
      },
      {
        id: 11,
        nama_regional: 'REGIONAL JMB',
        id_uid: 287,
        nama_uid: 'DISTRIBUSI BALI',
        id_up3: 329,
        nama_up3: 'UP3 BALI UTARA',
        id_ulp: 55320,
        nama_ulp: 'ULP SERIRIT',
        id_posko: 553202,
        nama_posko: 'POSKO ULP SERIRIT',
        total: 19,
        total_selesai: 19,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 5,
        persen_rating: 26.31578947368421,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 5,
        indeks_rating: 1,
        total_nonrating: 14,
        persen_nonrating: 73.68421052631578
      },
      {
        id: 12,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 120,
        nama_uid: 'WILAYAH SUMATERA UTARA',
        id_up3: 12500,
        nama_up3: 'UP3 RANTAU PRAPAT',
        id_ulp: 12516,
        nama_ulp: 'ULP SIMPANG KAWAT',
        id_posko: 125161,
        nama_posko: 'POSKO ULP SIMPANG KAWAT',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: null,
        persen_rating: null,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 0,
        indeks_rating: null,
        total_nonrating: null,
        persen_nonrating: null
      },
      {
        id: 13,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 430,
        nama_uid: 'WILAYAH NUSA TENGGARA TIMUR',
        id_up3: 437,
        nama_up3: 'UP3 FLORES BAGIAN BARAT',
        id_ulp: 43760,
        nama_ulp: 'ULP LABUAN BAJO',
        id_posko: 437601,
        nama_posko: 'POSKO ULP LABUAN BAJO',
        total: 3,
        total_selesai: 3,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 2,
        persen_rating: 66.66666666666666,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 2,
        indeks_rating: 1,
        total_nonrating: 1,
        persen_nonrating: 33.33333333333333
      },
      {
        id: 14,
        nama_regional: 'REGIONAL JMB',
        id_uid: 101,
        nama_uid: 'DISTRIBUSI JAWA TENGAH & DIY',
        id_up3: 52300,
        nama_up3: 'UP3 SEMARANG',
        id_ulp: 52310,
        nama_ulp: 'ULP BOJA',
        id_posko: 523101,
        nama_posko: 'POSKO ULP BOJA',
        total: 17,
        total_selesai: 17,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 16,
        persen_rating: 94.11764705882352,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 16,
        indeks_rating: 1,
        total_nonrating: 1,
        persen_nonrating: 5.88235294117647
      }
    ]
      .sort((a: any, b: any) => a.nama_up3.localeCompare(b.nama_up3))
      .map((ref: any, index: number) => {
        return {
          ...ref,
          number: index + 1
        }
      })
  }
})
</script>
