<template>
  <div id="main">
    <!-- TODO: Kontakte erstellen und dem Kunden zuweisen    -->

    <!--<InputGroup>
      <UButton @click="router.push(`/banking/accounts/create/`)">+ Kontakt</UButton>

      <UInput
          v-model="searchString"
          placeholder="Suche..."
      />
    </InputGroup>-->



    <UTable
        :rows="filteredRows"
        :columns="itemColumns"
        @select="selectItem"
        :empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: 'Noch keine Einträge' }"
    >

    </UTable>

  </div>
</template>

<script setup>

definePageMeta({
  middleware: "auth"
})

const dataStore = useDataStore()
const router = useRouter()
const mode = ref("show")

const itemColumns = [
  {
    key: "iban",
    label: "IBAN",
    sortable: true
  },
  {
    key: "bankId",
    label: "Bank",
    sortable: true
  },
  {
    key: "ownerName",
    label: "Besitzer",
    sortable: true
  }
]


const selectItem = (item) => {
  router.push(`/banking/statements/${item.id} `)
}


const searchString = ref('')

const filteredRows = computed(() => {
  dataStore.bankAccounts = dataStore.bankAccounts.filter(account => account.used)

  if(!searchString.value) {
    return dataStore.bankAccounts
  }

  return dataStore.bankAccounts.filter(item => {
    return Object.values(item).some((value) => {
      return String(value).toLowerCase().includes(searchString.value.toLowerCase())
    })
  })
})
</script>

<style scoped>

</style>