Banner.tsx 3.15 KB
import { useState } from 'react';
import type { BannerCapsuleTag } from '../types/home';

const LOCAL_BANNER_IMAGE = '/banner.png';
const LOCAL_BANNER_BLUR_IMAGE = '/banner-blur.png';
const DEFAULT_CAPSULE_TEXT = '新一代智能协作平台';

export interface BannerProps {
  title: string;
  subtitle: string;
  backgroundImage: string | null;
  backgroundBlurImage: string | null;
  capsuleTag: BannerCapsuleTag | null;
}

export function Banner({
  title,
  subtitle,
  backgroundImage,
  backgroundBlurImage,
  capsuleTag,
}: BannerProps) {
  const [isHovering, setIsHovering] = useState(false);
  const [imageError, setImageError] = useState(false);
  void backgroundImage;
  void backgroundBlurImage;

  const shouldShowBlur = isHovering;
  const effectiveBackground = imageError
    ? null
    : shouldShowBlur
      ? LOCAL_BANNER_BLUR_IMAGE
      : LOCAL_BANNER_IMAGE;
  const capsuleText = capsuleTag?.text?.trim() || DEFAULT_CAPSULE_TEXT;

  const handleMouseEnter = () => {
    setIsHovering(true);
  };

  const handleMouseLeave = () => {
    setIsHovering(false);
  };

  const handleImageError = () => {
    setImageError(true);
  };

  return (
    <section
      data-testid="banner-section"
      className="relative min-h-[500px] tablet:min-h-[582px] flex items-center justify-center overflow-hidden py-16 tablet:py-24 px-margin-mobile tablet:px-margin-desktop"
      onMouseEnter={handleMouseEnter}
      onMouseLeave={handleMouseLeave}
    >
      <div className="absolute inset-0 z-0">
        {effectiveBackground ? (
          <>
            <img
              src={effectiveBackground}
              alt="Banner 背景"
              className="w-full h-full object-cover"
              onError={handleImageError}
            />
            <div className="absolute inset-0 bg-white/40 backdrop-blur-[2px]" />
          </>
        ) : (
          <div className="absolute inset-0 bg-gradient-to-br from-primary/5 to-surface" />
        )}
      </div>

      <div className="relative z-10 text-center max-w-container-max mx-auto">
        <div className="inline-flex items-center gap-3 px-8 py-3 rounded-full bg-[#E8EFFD] border border-[#AFC4EF] mb-6 tablet:mb-8 shadow-[0_0_0_1px_rgba(255,255,255,0.35)_inset]">
          <svg className="w-7 h-7 text-[#2A5AA6] shrink-0" viewBox="0 0 32 32" fill="currentColor" aria-hidden="true">
            <path d="M14 2.5L16.1 8.4L22 10.5L16.1 12.6L14 18.5L11.9 12.6L6 10.5L11.9 8.4L14 2.5Z" />
            <path d="M24.5 10L25.8 13.5L29.3 14.8L25.8 16.1L24.5 19.6L23.2 16.1L19.7 14.8L23.2 13.5L24.5 10Z" />
          </svg>
          <span className="text-[18px] leading-none text-[#1E4F8B] font-bold tracking-[0.02em]">{capsuleText}</span>
        </div>

        <h1 className="text-display-lg-mobile tablet:text-display-lg font-bold mb-4 tablet:mb-6 leading-tight text-on-surface">
          {title.split(' ').map((word, index) => (
            index === 1 ? <span key={index} className="text-primary">{word} </span> : word + ' '
          ))}
        </h1>

        <p className="text-body-md tablet:text-body-lg text-on-surface-variant mb-8 tablet:mb-10 max-w-2xl mx-auto font-medium">
          {subtitle}
        </p>
      </div>
    </section>
  );
}