<template>
  <Filters @run-search="() => filterData(filters)" :report-button="true" class="mb-4">
    <Type1 @update:filters="(value) => (filters = value)" />
  </Filters>
  <div id="data">
    <DxDataGrid
      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"
    >
      <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-if="loading"
        v-model:visible="loading"
        :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="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="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="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="formatNumber"
          />
          <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="showData()">
          {{ data.text }}
        </p>
      </template>

      <template #formatPercentage="{ data }">
        <p class="text-right cursor-pointer" @click="showData()">
          {{ isNumber(data.text) ? formatPercentage(data.text) : data.text }}
        </p>
      </template>

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

  <DetailDialog
    :open="showDetail"
    title="Detail Rating Per Posko"
    @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
          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=""
            caption="No Laporan"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Rating"
            css-class="custom-table-column"
            cell-template="formatRating"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Tgl Lapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Tgl Datang"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Tgl Nyala"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Durasi Response Time"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Durasi Recovery Time"
            css-class="custom-table-column"
            cell-template="formatTime"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Referensi Marking"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="IDPEL/NO METER"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Nama Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Alamat Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="No Tlp Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Keterangan Pelapor"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Posko"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Tindakan"
            css-class="custom-table-column"
            cell-template="formatText"
          />
          <DxColumn
            :width="150"
            alignment="center"
            data-field=""
            caption="Penyebab"
            css-class="custom-table-column"
            cell-template="formatText"
          />

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

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

          <template #formatTime="{ data }">
            <p>
              {{ parseInt(data.text) ? formatWaktu(data.text) : '-' }}
            </p>
          </template>
        </DxDataGrid>
      </div>
    </div>
    <div class="w-full mb-4 lg:w-[30%] lg:float-right">
      <div class="p-4 space-y-2 bg-white rounded-xl">
        <div class="flex flex-row items-center justify-between w-full">
          <h3 class="text-sm font-medium w-[135px] text-gray-800">No Laporan:</h3>
          <InputText :readonly="true" value="" 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="" 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="" 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="" 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="" 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="" 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="" 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" class-name="flex-1" value="" />
        </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="" 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="" 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="" 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="" 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="" 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" type="textarea" value="" 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="" 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="" 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 { DxDataGrid } from 'devextreme-vue'
import {
  DxColumn,
  DxColumnFixing,
  DxExport,
  DxLoadPanel,
  DxPager,
  DxPaging,
  DxScrolling,
  DxSearchPanel,
  DxSelection
} from 'devextreme-vue/data-grid'
import { onMounted, ref, watch } from 'vue'
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 DetailDialog from '@/components/Dialogs/DetailDialog.vue'
import InputText from '@/components/InputText.vue'

const position = { of: '#data' }
const showIndicator = ref(true)
const shading = ref(true)
const showPane = ref(true)
const loading = ref(false)
const loadingSubData = ref(false)
const data = ref<any[]>([])
const dataSub = ref<any[]>([])
const dataSelected = ref()
const dataSubSelected = ref()
const showDetail = ref(false)
const showData = () => {
  showDetail.value = true
}
const closeDetail = () => {
  showDetail.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 onSelectionChanged = ({ selectedRowsData }: any) => {
  dataSelected.value = selectedRowsData[0]
  console.log(data)
}

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

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

  const { onResult, onError, loading, refetch } = useQuery(
    queries.gangguan.rekap.gangguanRatingPerPosko,
    {
      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.id,
      idUid: uid.id,
      idUp3: up3.id
    }
  )

  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.rekapitulasiGangguanRatingPerPosko
    }
    console.log(queryResult.data)
    console.log(queryResult.loading)
    console.log(queryResult.networkStatus)
  })
  onError((error) => {
    console.log(error)
  })
  watch(loading, (value) => {
    loading.value = value
  })
}
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
      }
    ]
  }
})
</script>
