'use client'

import styles from './styles.module.scss'
import Image from 'next/image'
import family from './family.svg'
import bible from './bible.svg'
import { useState } from 'react'
import Link from 'next/link'
import classNames from 'classnames'
import { useTime } from '@/hooks/useTime'
import { useCompactDate, useShortDayName } from '@/hooks/useCompactDate'

export type MassTableRowProps = {
  id: string
  date: string
  type: 'MASS' | 'FAMILY' | 'WORD'
  cancelled: boolean
}

export const MassTableRow = ({
  id,
  date,
  type,
  cancelled,
}: MassTableRowProps) => {
  const [symbol, setSymbol] = useState('-')
  const time = useTime(date)
  const compactDate = useCompactDate(date)
  const day = useShortDayName(date)

  return (
    <Link
      href={`/gottesdienst/${id}`}
      className={classNames({ [styles.cancelled]: cancelled }, styles.link)}
    >
      <div
        className={styles.row}
        onMouseEnter={() => setSymbol('†')}
        onMouseLeave={() => setSymbol('-')}
      >
        <div className={styles.time}>{day} {compactDate}</div>
        <div className={styles.symbol}>{symbol}</div>
        <div>{time}</div>

          {type === 'FAMILY' && (
            <Image src={family} width={18} height={18} alt={'Familien Messe'} />
          )}

          {type === 'WORD' && (
            <Image src={bible} width={18} height={18} alt={'Wortgottesfeier'} />
          )}
      </div>
    </Link>
  )
}
