<script setup lang="ts">
import type { Table } from '@tanstack/vue-table'

import { X } from 'lucide-vue-next'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import type { Card } from '@/pages/agent/cards/data/schema'

const props = defineProps<{
  table: Table<Card>
  searchFilter?: string
}>()

const emit = defineEmits<{
  'update:searchFilter': [value: string]
}>()

const { t } = useI18n()

const isFiltered = computed(() => !!props.searchFilter)

function resetFilters() {
  emit('update:searchFilter', '')
}
</script>

<template>
  <div class="flex items-center flex-1 space-x-2">
    <Input
      :placeholder="t('agent.cards.searchPlaceholder')"
      :model-value="searchFilter"
      class="h-8 w-[200px] lg:w-[300px]"
      @update:model-value="emit('update:searchFilter', $event as string)"
    />

    <Button
      v-if="isFiltered"
      variant="ghost"
      class="h-8 px-2 lg:px-3"
      @click="resetFilters"
    >
      {{ t('agent.cards.reset') }}
      <X class="size-4 ml-2" />
    </Button>
  </div>
</template>
