import styles from "./styles.module.scss"
import { Worship as WorshipType } from '@/payload-types'
import { useDate } from '@/hooks/useCompactDate'
import { Section } from '@/components/Section/Section'
import { Title } from '@/components/Title/Title'
import { liturgicalDayName } from '@/hooks/liturgicalDayName'
import { EventExcerpt, EventExcerptRow } from '@/components/EventExcerpt/EventExcerpt'
import { transformCategory } from '@/utils/dto/worship'
import { TextDiv } from '@/components/Text/TextDiv'
import { church } from '@/utils/church'
import { ChurchIcon } from '@/components/ChurchIcon/ChurchIcon'
import { Cross } from '@/components/Cross/Cross'
import { Testimony } from '@/components/Testimony/Testimony'
import { Pill } from '@/components/Pill/Pill'

type WorshipPageProps = {
  worship: WorshipType
}

export const Worship = ({ worship }: WorshipPageProps) => {
  const date = new Date(worship.date);
  const day = date.toLocaleDateString('de-DE', {weekday: 'long'} )
  const localeDate = useDate(worship.date)
  const liturgicalDay = worship.liturgicalDay ? worship.liturgicalDay : liturgicalDayName(worship.date);
  const what = worship.title ? worship.title : transformCategory(worship.type) + " ";
  const time = date.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" });

  return (
    <>
      <Section>
        <div className={styles.textCenter}>
          <Cross color={"contrast"} />
        </div>
        <Title
          title={`${day}, ${localeDate}`}
          size={'lg'}
          color={'contrast'}
          align={"center"}
          cancelled={worship.cancelled}
        />

        <p className={styles.liturgicalDay}>
          <strong>{liturgicalDay}</strong><br/><br/><br/>
        </p>

        <EventExcerpt>
          <EventExcerptRow label={"Was:"}>
            {what}
            { worship.cancelled &&
              <Pill schema={"contrast"}>Abgesagt</Pill>
            }
          </EventExcerptRow>
          <EventExcerptRow label={"Wo:"}>
            { typeof worship.location == "object" &&
              <TextDiv text={`${worship.location.name}\n${worship.location.address}`} />
            }
          </EventExcerptRow>
          <EventExcerptRow label={"Wann:"}>
            {time} Uhr
          </EventExcerptRow>
          { worship.celebrant &&
            <EventExcerptRow label={"Zelebrant:"}>
              {worship.celebrant}
            </EventExcerptRow>
          }

          { typeof worship.description === "string" && worship.description != "" &&
            <EventExcerptRow label={"Hinweise:"}>
              <TextDiv text={worship.description} />
            </EventExcerptRow>
          }

          <div>
            <div className={styles.church}>
              <ChurchIcon
                church={church(typeof worship.location == "object" ? worship.location.name : "clara")}
                color={"var(--base-color)"}
                style={"filled"}
                stroke={3}
              />
            </div>
          </div>
        </EventExcerpt>
      </Section>

      <Section>
        <Testimony testimony={"Du bringst nichts mit hinein, Du nimmst nichts mit hinaus Lass eine goldene Spur zurück, Im alten Erdenhaus"} />
      </Section>
    </>
  )
}