<template>
  <Filters @run-search="() => filterData(filters)" :report-button="true" class="mb-4">
    <Type1 @update:filters="(value) => (filters = value)" />
  </Filters>
  <div id="data">
    <DxDataGrid
      :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"
    >
      <DxSelection mode="single" />
      <DxPaging :enabled="false" />
      <DxScrolling column-rendering-mode="virtual" mode="virtual" />
      <DxLoadPanel
        :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"
        :calculateCellValue="(item: any) => data.findIndex((i) => i == item) + 1"
        caption="NO"
        data-type="number"
        css-class="custom-table-column"
        cell-template="formatNumber"
      />
      <DxColumn
        :width="150"
        alignment="center"
        data-field="kode_regu"
        caption="Kode"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn
        :width="200"
        alignment="center"
        data-field="nama_regu"
        caption="Nama Regu"
        css-class="custom-table-column"
        cell-template="formatText"
      />
      <DxColumn alignment="center" caption="Laporan" css-class="custom-table-column">
        <DxColumn
          alignment="center"
          data-field="total"
          data-type="number"
          caption="Total"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <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="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="persen_inproses"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </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="formatNumber"
          />
          <DxColumn
            alignment="center"
            data-field="persen_selesai"
            data-type="number"
            caption="%"
            css-class="custom-table-column"
            cell-template="formatNumber"
          />
        </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
          :width="150"
          alignment="center"
          data-field="total_nonrating"
          data-type="number"
          caption="Jml"
          css-class="custom-table-column"
          cell-template="formatNumber"
        />
        <DxColumn
          :width="70"
          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="showDetail()">
          {{ data.text }}
        </p>
      </template>

      <template #formatPercentage="{ data }">
        <p class="text-right cursor-pointer" @click="showDetail()">
          {{ parseFloat(data.text) ? formatPercentage(data.text) : '0%' }}
        </p>
      </template>

      <template #formatNumber="{ data }">
        <p class="text-right cursor-pointer" @click="showDetail()">
          {{
            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="showDetail()">
          {{ parseInt(data.text) ? formatWaktu(data.text) : '-' }}
        </p>
      </template>
    </DxDataGrid>
  </div>

  <DetailDialog
    :open="dialogDetail"
    title="Detail Rating Per Regu"
    @on-close="closeDetail"
    :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="onExporting"
          :allow-column-resizing="true"
          column-resizing-mode="widget"
        >
          <DxSelection mode="single" />
          <DxPaging :page-size="5" :enabled="true" />
          <DxPager
            :visible="true"
            :allowed-page-sizes="[5, 10, 20]"
            display-mode="full"
            :show-page-size-selector="true"
            :show-info="true"
            :show-navigation-buttons="true"
          />
          <DxLoadPanel
            :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"
            :calculateCellValue="(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 }">
            <p class="cursor-pointer">
              <vue3starRatings
                v-model="data.text"
                :starSize="20"
                starColor="#CCCC00"
                inactiveColor="#D1D5DB"
                :numberOfStars="5"
                :disableClick="true"
              />
            </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">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">Penyeban:</h3>
          <InputText :readonly="true" :value="dataSubSelected?.penyebab" class-name="flex-1" />
        </div>
      </div>
    </div>
  </DetailDialog>
</template>

<script setup lang="ts">
import Filters from '@/components/Form/Filters.vue'
import Type1 from '@/components/Form/FiltersType/Type1.vue'
import { onMounted, ref, watch } from 'vue'
import { DxDataGrid } from 'devextreme-vue'
import {
  DxColumn,
  DxColumnFixing,
  DxExport,
  DxLoadPanel,
  DxPager,
  DxPaging,
  DxScrolling,
  DxSearchPanel,
  DxSelection
} from 'devextreme-vue/data-grid'
import { jsPDF } from 'jspdf'
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
import { saveAs } from 'file-saver'
import { Workbook } from 'exceljs'
import { useQuery } from '@vue/apollo-composable'
import { queries } from '@/utils/api/api.graphql'
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
import { formatWaktu } from '@/components/Form/FiltersType/reference'
import vue3starRatings from 'vue3-star-ratings'
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
import InputText from '@/components/InputText.vue'
import { apolloClient } from '@/utils/api/api.graphql'
import { provideApolloClient } from '@vue/apollo-composable'

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()
const dataSubSelected = ref()
const dialogDetail = ref(false)
const loadingData = ref(false)
const loadingSubData = ref(false)

const getDetail = () => {
  loadingSubData.value = true
  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 : ''
  }

  const { onResult, onError, loading, refetch } = useQuery(
    queries.gangguan.rekap.gangguanAllDetail,
    query
  )

  onResult((queryResult) => {
    if (queryResult.data != undefined) {
      dataSub.value = queryResult.data.detailGangguan
    }
  })

  onError((error) => {
    console.log(error)
  })

  watch(loading, (value) => {
    loadingSubData.value = value
  })
}

const showDetail = () => {
  if (dataSelected.value != null) {
    dataSub.value = []
    dataSubSelected.value = null
    dialogDetail.value = true
    getDetail()
  }
}

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

const onExporting = (e: any) => {
  if (e.format === 'pdf') {
    const doc = new jsPDF()

    exportToPdf({
      jsPDFDocument: doc,
      component: e.component,
      indent: 5
    }).then(() => {
      doc.save(`.pdf`)
    })
  } else {
    const workbook = new Workbook()
    const worksheet = workbook.addWorksheet('Employees')

    exportToExcel({
      component: e.component,
      worksheet,
      autoFilterEnabled: true
    }).then(() => {
      workbook.xlsx.writeBuffer().then((buffer: any) => {
        saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
      })
    })

    e.cancel = true
  }
}

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

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

const { onResult, onError, loading, refetch } = useQuery(
  queries.gangguan.rekap.gangguanRatingPerRegu,
  {
    dateFrom: new Date('2023-10-01').toISOString().slice(0, 10),
    dateTo: new Date('2023-10-01').toISOString().slice(0, 10),
    posko: '',
    idUid: 0,
    idUp3: 0
  }
)
const filterData = (params: any) => {
  const dateValue = params.periode.split(' s/d ')
  const { posko, uid, up3 } = params
  refetch({
    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
  })
  onResult((queryResult) => {
    if (queryResult.data != undefined) {
      data.value = queryResult.data.rekapitulasiGangguanRatingPerRegu
    }
    console.log(queryResult.data)
    console.log(queryResult.loading)
    console.log(queryResult.networkStatus)
  })
  onError((error) => {
    console.log(error)
  })
}
const filters = ref()
onMounted(() => {
  if (import.meta.env.DEV) {
    data.value = [
      {
        id: 0,
        nama_regional: 'REGIONAL JMB',
        id_uid: 101,
        nama_uid: 'DISTRIBUSI JAWA TENGAH & DIY',
        id_up3: 52050,
        nama_up3: 'UP3 SURAKARTA',
        id_ulp: 52058,
        nama_ulp: 'ULP SRAGEN',
        id_posko: 520581,
        nama_posko: 'POSKO ULP SRAGEN',
        total: 5,
        total_selesai: 5,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 2,
        persen_rating: 40,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 2,
        indeks_rating: 1,
        total_nonrating: 3,
        persen_nonrating: 60
      },
      {
        id: 1,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 150,
        nama_up3: 'UP3 PAMEKASAN',
        id_ulp: 51750,
        nama_ulp: 'ULP KETAPANG',
        id_posko: 517506,
        nama_posko: 'POSKO ULP KETAPANG',
        total: 5,
        total_selesai: 5,
        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: 2,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 140,
        nama_uid: 'WILAYAH SUMATERA SELATAN, JAMBI & BENGKULU (S2JB)',
        id_up3: 1404,
        nama_up3: 'UP3 JAMBI',
        id_ulp: 14390,
        nama_ulp: 'ULP SABAK',
        id_posko: 143901,
        nama_posko: 'POSKO ULP SABAK',
        total: 2,
        total_selesai: 2,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 2,
        persen_rating: 100,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 2,
        indeks_rating: 1,
        total_nonrating: 0,
        persen_nonrating: 0
      },
      {
        id: 3,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 539,
        nama_up3: 'UP3 GUNUNG PUTRI',
        id_ulp: 53867,
        nama_ulp: 'ULP JONGGOL',
        id_posko: 538671,
        nama_posko: 'POSKO ULP JONGGOL',
        total: 7,
        total_selesai: 7,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 4,
        persen_rating: 57.14285714285714,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 4,
        indeks_rating: 1,
        total_nonrating: 3,
        persen_nonrating: 42.857142857142854
      },
      {
        id: 4,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 542,
        nama_up3: 'UP3 MAJALAYA',
        id_ulp: 53531,
        nama_ulp: 'ULP MAJALAYA',
        id_posko: 535311,
        nama_posko: 'POSKO ULP MAJALAYA',
        total: 4,
        total_selesai: 4,
        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: 5,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 120,
        nama_uid: 'WILAYAH SUMATERA UTARA',
        id_up3: 12100,
        nama_up3: 'UP3 PEMATANG SIANTAR',
        id_ulp: 12115,
        nama_ulp: 'ULP PEMATANG RAYA',
        id_posko: 121155,
        nama_posko: 'POSKO ULP PEMATANG RAYA',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 1,
        persen_rating: 100,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 1,
        indeks_rating: 1,
        total_nonrating: 0,
        persen_nonrating: 0
      },
      {
        id: 6,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 171,
        nama_uid: 'DISTRIBUSI LAMPUNG',
        id_up3: 17172,
        nama_up3: 'UP3 METRO',
        id_ulp: 17210,
        nama_ulp: 'ULP SRIBAWONO',
        id_posko: 172101,
        nama_posko: 'POSKO ULP SRIBAWONO',
        total: 18,
        total_selesai: 18,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 12,
        persen_rating: 66.66666666666666,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 12,
        indeks_rating: 1,
        total_nonrating: 6,
        persen_nonrating: 33.33333333333333
      },
      {
        id: 7,
        nama_regional: 'REGIONAL JMB',
        id_uid: 101,
        nama_uid: 'DISTRIBUSI JAWA TENGAH & DIY',
        id_up3: 52200,
        nama_up3: 'UP3 PURWOKERTO',
        id_ulp: 52205,
        nama_ulp: 'ULP WONOSOBO',
        id_posko: 522051,
        nama_posko: 'POSKO ULP WONOSOBO',
        total: 23,
        total_selesai: 23,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 22,
        persen_rating: 95.65217391304348,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 22,
        indeks_rating: 1,
        total_nonrating: 1,
        persen_nonrating: 4.3478260869565215
      },
      {
        id: 8,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 120,
        nama_uid: 'WILAYAH SUMATERA UTARA',
        id_up3: 12500,
        nama_up3: 'UP3 RANTAU PRAPAT',
        id_ulp: 12513,
        nama_ulp: 'ULP LABUHAN BILIK',
        id_posko: 125133,
        nama_posko: 'POSKO ULP LABUHAN BILIK',
        total: 1,
        total_selesai: 1,
        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: 9,
        nama_regional: 'REGIONAL JMB',
        id_uid: 103,
        nama_uid: 'DISTRIBUSI JAWA TIMUR',
        id_up3: 150,
        nama_up3: 'UP3 PAMEKASAN',
        id_ulp: 51730,
        nama_ulp: 'ULP BANGKALAN',
        id_posko: 517304,
        nama_posko: 'POSKO ULP BANGKALAN',
        total: 32,
        total_selesai: 32,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 3,
        persen_rating: 9.375,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 3,
        indeks_rating: 1,
        total_nonrating: 29,
        persen_nonrating: 90.625
      },
      {
        id: 10,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 180,
        nama_uid: 'WILAYAH RIAU DAN KEPULAUAN RIAU',
        id_up3: 181,
        nama_up3: 'UP3 PEKANBARU',
        id_ulp: 18111,
        nama_ulp: 'ULP PEKANBARU KOTA BARAT',
        id_posko: 181111,
        nama_posko: 'POSKO ULP PEKANBARU KOTA BARAT',
        total: 109,
        total_selesai: 109,
        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: 11,
        nama_regional: 'REGIONAL JMB',
        id_uid: 427,
        nama_uid: 'DISTRIBUSI JAWA BARAT',
        id_up3: 536,
        nama_up3: 'UP3 CIMAHI',
        id_ulp: 53589,
        nama_ulp: 'ULP LEMBANG',
        id_posko: 535891,
        nama_posko: 'POSKO ULP LEMBANG',
        total: 17,
        total_selesai: 17,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 17,
        persen_rating: 100,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 17,
        indeks_rating: 1,
        total_nonrating: 0,
        persen_nonrating: 0
      },
      {
        id: 12,
        nama_regional: 'REGIONAL SULMAPANA',
        id_uid: 32,
        nama_uid: 'WILAYAH SULAWESI SELATAN, TENGGARA DAN BARAT',
        id_up3: 32800,
        nama_up3: 'UP3 BAUBAU',
        id_ulp: 32820,
        nama_ulp: 'ULP RAHA',
        id_posko: 328201,
        nama_posko: 'POSKO ULP RAHA',
        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: 32,
        nama_uid: 'WILAYAH SULAWESI SELATAN, TENGGARA DAN BARAT',
        id_up3: 32200,
        nama_up3: 'UP3 WATAMPONE',
        id_ulp: 32270,
        nama_ulp: 'ULP PATANGKAI',
        id_posko: 322701,
        nama_posko: 'POSKO ULP PATANGKAI',
        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: 14,
        nama_regional: 'REGIONAL SUMKAL',
        id_uid: 221,
        nama_uid: 'WILAYAH KALIMANTAN SELATAN DAN TENGAH',
        id_up3: 2220,
        nama_up3: 'UP3 BARABAI',
        id_ulp: 22250,
        nama_ulp: 'ULP PARINGIN',
        id_posko: 222501,
        nama_posko: 'POSKO ULP PARINGIN',
        total: 1,
        total_selesai: 1,
        persen_selesai: 100,
        total_inproses: 0,
        persen_inproses: 0,
        total_rating: 1,
        persen_rating: 100,
        nilai_rating1: 0,
        nilai_rating2: 0,
        nilai_rating3: 0,
        nilai_rating4: 0,
        nilai_rating5: 1,
        indeks_rating: 1,
        total_nonrating: 0,
        persen_nonrating: 0
      }
    ]
  }
})
</script>
