<script setup lang="ts">
import Select from '@/components/Select.vue';
import SelectMulti from '@/components/SelectMulti.vue';

import DatePicker from '@/components/DatePicker.vue';
import { selectedUid, selectedUp3Posko, selectedPosko, fetchUid, itemsUid, itemsUp3, itemsPosko } from './reference';
import { onMounted, ref } from 'vue';

const uidPlaceholder = 'Semua Unit Induk Distribusi/Wilayah';
const up3Placeholder = 'Semua Unit Pelaksanaan Pelayanan Pelanggan';
const poskoPlaceholder = 'Semua Posko';
const up3 = ref({ id: 0, name: up3Placeholder });
const uid = ref({ id: 0, name: uidPlaceholder });
const posko = ref({ id: 0, name: poskoPlaceholder });
const emit = defineEmits(['update:filters'])
const jenisTransakasi = [
  { id: 1, value: 'Koreksi Transaksi Individual', label: 'Koreksi Transaksi Individual' },
  { id: 2, value: 'Cleansing Traksaksi TM', label: 'Cleansing Traksaksi TM', },
  { id: 3, value: 'Koreksi Transaksi TM', label: 'Koreksi Transaksi TM', },
  { id: 4, value: 'Koreksi Kode Gangguan dan Anev', label: 'Koreksi Kode Gangguan dan Anev' },
]
const data = ref({
  uid: uid.value,
  up3: up3.value,
  posko: posko.value,
  periode: '',
  jenisTransaksi: [],
  group: 1
})
onMounted(() => {
  emit('update:filters', data.value)
  fetchUid()
})
</script>

<template>
  <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
    <div class="flex flex-col flex-1 space-y-2">
      <label class="filter-input-label">Unit Induk Distribusi/Wilayah:</label>

      <Select @update:selected="selectedUid($event)" :data="itemsUid"
        placeholder="Semua Unit Induk Distribusi/Wilayah" />
    </div>

    <div class="flex flex-col flex-1 space-y-2">
      <label class="filter-input-label">Unit Pelaksanaan Pelayanan Pelanggan:</label>

      <Select @update:selected="selectedUp3Posko($event)" :data="itemsUp3" :selected="up3"
        placeholder="Semua Unit Pelaksanaan Pelayanan Pelanggan" />
    </div>

    <div class="flex flex-col flex-1 space-y-2">
      <label class="filter-input-label">Posko:</label>

      <Select @update:selected="selectedPosko($event)" :data="itemsPosko" :selected="posko" placeholder="Semua Posko" />
    </div>
    <div class="flex flex-col flex-1 space-y-2">
      <label class="filter-input-label">Jenis Transaksi:</label>

      <SelectMulti :tags="jenisTransakasi" placeholder="Semua Jenis Transaksi" useLabel label="Jenis Transaksi" />
    </div>
    <div class="flex flex-col flex-1 space-y-2">
      <label class="filter-input-label">Periode Tanggal:</label>
      <DatePicker @update:date-value="(value) => data.periode = value" />
    </div>
  </div>

</template>
