'use client'
import type {FunctionComponent} from 'react'
import type {Tag as TagType} from '@/generated/prisma/client'
import {Card, CardHeader, CardTitle} from '@/components/ui/card'
import {Button} from '@/components/ui/button'
import {ChevronRightIcon, TrashIcon} from 'lucide-react'
import Link from 'next/link'
import {deleteTagServerFunction} from '@/serverFunctions/tags'

const Tag: FunctionComponent<TagType> = ({id, name}) => {
  return (
    <Card>
      <CardHeader>
        <div className="flex justify-between items-center">
          <CardTitle>{name}</CardTitle>
          <div>
            <Button variant="ghost" onClick={() => deleteTagServerFunction({id})}>
              <TrashIcon className="text-destructive" />
            </Button>
            <Link href={`/tags/${id}`}>
              <Button variant="ghost">
                <ChevronRightIcon />
              </Button>
            </Link>
          </div>
        </div>
      </CardHeader>
    </Card>
  )
}

export default Tag
