<script setup>
  /*defineShortcuts({
    /!*'/': () => {
      //console.log(searchinput)
      //searchinput.value.focus()
      document.getElementById("searchinput").focus()
    },*!/
    'Enter': {
      usingInput: true,
      handler: () => {
        router.push(`/standardEntity/${props.type}/show/${props.rows.value[selectedItem.value].id}`)
      }
    },
    'arrowdown': () => {
      if(selectedItem.value < props.rows.length - 1) {
        selectedItem.value += 1
      } else {
        selectedItem.value = 0
      }
    },
    'arrowup': () => {
      if(selectedItem.value === 0) {
        selectedItem.value = props.rows.length - 1
      } else {
        selectedItem.value -= 1
      }
    }
  })*/

  const props = defineProps({
    rows: {
      type: Array,
      required: true,
      default: []
    },
    columns: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      required: true,
    }
  })

  const dataStore = useDataStore()

  const router = useRouter()
  const getShowRoute = (entityType, id) => entityType === "tasks" ? `/tasks/show/${id}` : `/standardEntity/${entityType}/show/${id}`

  const dataType = dataStore.dataTypes[props.type]

  const selectedItem = ref(0)


</script>

<template>
  <UDashboardPanelContent class="w-full">
    <a
        v-for="item in props.rows"
        class="my-1"
        @click="router.push(getShowRoute(type, item.id))"
    >
      <p class="truncate text-left text-primary text-xl">{{dataType.templateColumns.find(i => i.title).key ? item[dataType.templateColumns.find(i => i.title).key] : null}}</p>
      <p class="text-sm">
        {{ dataType.numberRangeHolder ? item[dataType.numberRangeHolder] : null}}

        <span v-for="secondInfo in dataType.templateColumns.filter(i => i.secondInfo)">{{(secondInfo.secondInfoKey && item[secondInfo.key]) ? item[secondInfo.key][secondInfo.secondInfoKey] : item[secondInfo.key]}}</span>

      </p>
    </a>
  </UDashboardPanelContent>




<!--  <UTable
      v-if="dataType && columns"
      :data="props.rows"
      :columns="props.columns"
      class="w-full"
      :ui="{ divide: 'divide-gray-200 dark:divide-gray-800' }"
      @select="(i) => router.push(`/standardEntity/${type}/show/${i.id}`) "
      :empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: `Keine ${dataType.label} anzuzeigen` }"
  >
    <template
        v-for="column in dataType.templateColumns.filter(i => !i.disabledInTable)"
        v-slot:[`${column.key}-header`]="{row}">
      <span class="text-nowrap">{{column.label}}</span>
    </template>
    <template #name-data="{row}">
      <span
          v-if="row.id === props.rows[selectedItem].id"
          class="text-primary-500 font-bold">{{row.name}}
      </span>
      <span v-else>
        {{row.name}}
      </span>
    </template>
    <template #fullName-data="{row}">
      <span
          v-if="row.id === props.rows[selectedItem].id"
          class="text-primary-500 font-bold">{{row.fullName}}
      </span>
      <span v-else>
        {{row.fullName}}
      </span>
    </template>
    <template #licensePlate-data="{row}">
      <span
          v-if="row.id === props.rows[selectedItem].id"
          class="text-primary-500 font-bold">{{row.licensePlate}}
      </span>
      <span v-else>
        {{row.licensePlate}}
      </span>
    </template>
    <template
        v-for="column in dataType.templateColumns.filter(i => i.key !== 'name' && i.key !== 'fullName' && i.key !== 'licensePlate' && !i.disabledInTable)"
        v-slot:[`${column.key}-data`]="{row}">
      <component v-if="column.component" :is="column.component" :row="row"></component>
      <span v-else>{{row[column.key] ? `${row[column.key]} ${column.unit ? column.unit : ''}`: ''}}</span>
    </template>
  </UTable>-->
</template>

<style scoped>

</style>
