"use client" import { useEffect, useRef, useState } from "react" import { useIntl } from "react-intl" import { debounce } from "@scandic-hotels/common/utils/debounce" import { Typography } from "@scandic-hotels/design-system/Typography" import { getEmployeeInfo } from "@/utils/user" import styles from "./digitalTeamMemberCard.module.css" import type { User } from "@scandic-hotels/trpc/types/user" interface DigitalTeamMemberCardCardProps { user: User } export default function DigitalTeamMemberCardContent({ user, }: DigitalTeamMemberCardCardProps) { const intl = useIntl() const cardRef = useRef(null) const employeeInfo = getEmployeeInfo(user) const notAvailableText = "N/A" const [isHovering, setIsHovering] = useState(false) const [coords, setCoords] = useState({ x: 0, y: 0 }) const shimmerRef = useRef(null) const [rect, setRect] = useState({ top: 0, left: 0, bottom: 0, right: 0, height: 0, width: 0, x: 0, y: 0, toJSON() {}, }) useEffect(() => { const observer = new ResizeObserver( debounce(() => { const el = cardRef.current if (!el) return const rect = el.getBoundingClientRect() setRect(rect) }) ) observer.observe(document.body) return () => { observer.unobserve(document.body) } }, []) function onInteractionMove(e: React.MouseEvent | React.TouchEvent) { let x, y if ("touches" in e) { x = e.touches[0].clientX - rect.left y = e.touches[0].clientY - rect.top } else { x = e.clientX - rect.left y = e.clientY - rect.top } const centerX = rect.width / 2 const centerY = rect.height / 2 const rotateY = ((x - centerX) / centerX) * 8 const rotateX = ((centerY - y) / centerY) * 8 // Update shimmer position to be in the opposite corner if (shimmerRef.current) { // Calculate opposite position (invert percentage within bounds) const oppositeX = 100 - (x / rect.width) * 100 const oppositeY = 100 - (y / rect.height) * 100 shimmerRef.current.style.background = `radial-gradient( circle at ${oppositeX}% ${oppositeY}%, rgba(233, 171, 163, 0.4) 0%, rgba(255, 255, 255, 0) 50% )` } setCoords({ x: rotateX, y: rotateY }) } function onInteractionStart() { setIsHovering(true) } function onInteractionEnd() { setIsHovering(false) setCoords({ x: 0, y: 0 }) } return (
{employeeInfo?.retired ? intl.formatMessage({ id: "myPages.seniorTeamMember", defaultMessage: "Senior Team Member", }) : intl.formatMessage({ id: "myPages.teamMember", defaultMessage: "Team Member", })} {employeeInfo?.country || notAvailableText}
{employeeInfo?.employeeId || notAvailableText}
{user.firstName} {user.lastName}
{employeeInfo?.location || notAvailableText} {employeeInfo?.retired ? intl.formatMessage({ id: "myPages.retired", defaultMessage: "Retired", }) : intl.formatMessage({ id: "myPages.employee", defaultMessage: "Employee", })}
) }