"use client";

import Image from "next/image";
import { MessageCircle } from "lucide-react";

import styles from "./splash-latest-message.module.css";

export interface SplashLatestMessageProps {
  message: string | null;
  isLoading?: boolean;
  onOpenChat: () => void;
}

export function SplashLatestMessage({
  message,
  isLoading = false,
  onOpenChat,
}: SplashLatestMessageProps) {
  if (!isLoading && !message) return null;

  return (
    <button
      type="button"
      className={styles.card}
      onClick={onOpenChat}
      aria-label="Open latest message from Elio"
    >
      <span className={styles.avatarWrap}>
        <Image
          src="/images/chat/pic-chat-elio.png"
          alt=""
          width={42}
          height={42}
          className={styles.avatar}
        />
      </span>
      <span className={styles.copy}>
        <span className={styles.eyebrow}>
          <MessageCircle size={13} aria-hidden="true" />
          Latest message
        </span>
        {isLoading ? (
          <span className={styles.messageLoading} aria-label="Loading latest message" />
        ) : (
          <span className={styles.message}>{message}</span>
        )}
      </span>
    </button>
  );
}
