import { buildImageSrcSet, Image } from '@components/common/Image.js'; import { Editable, EditableImageOverlay, isPageBuilderActive } from '@components/common/page-builder/index.js'; import { buttonVariants } from '@components/common/ui/Button.js'; import { scrimButtonClassName } from '@components/common/ui/scrimButton.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { ImagePlus } from 'lucide-react'; import React, { useEffect, useRef, useState } from 'react'; import Slider from 'react-slick'; import 'slick-carousel/slick/slick.css'; import { resolveArrowsStyle, resolveDotsStyle, type ArrowsStyle, type DotsStyle } from './slideshowControls.js'; type ContentAnchor = | 'tl' | 'tc' | 'tr' | 'ml' | 'mc' | 'mr' | 'bl' | 'bc' | 'br'; type OverlayTint = 'none' | 'dark' | 'light' | 'gradient'; type AspectRatio = 'auto' | '16:9' | '21:9' | '4:3' | '1:1'; // Slide CTA appearance — maps 1:1 to the shadcn `Button` variants. Legacy // data may still carry the prior values `filled` / `outline` / `link` from // before the variant migration; `resolveButtonVariant` translates them. type ButtonStyle = | 'default' | 'secondary' | 'outline' | 'ghost' | 'link' // Legacy values kept in the union so old saved settings type-check. | 'filled'; function resolveButtonVariant( raw: string | undefined ): 'default' | 'secondary' | 'outline' | 'ghost' | 'link' { switch (raw) { case 'secondary': return 'secondary'; case 'outline': return 'outline'; case 'ghost': return 'ghost'; case 'link': return 'link'; case 'default': case 'filled': case undefined: default: return 'default'; } } interface SlideData { id: string; image: string; mobileImage?: string; mobileWidth?: number; mobileHeight?: number; width?: number; height?: number; eyebrow?: string; headline?: string; subText?: string; buttonText?: string; buttonLink?: string; buttonStyle?: ButtonStyle; button2Text?: string; button2Link?: string; button2Style?: ButtonStyle; contentPosition?: ContentAnchor; overlayTint?: OverlayTint; overlayOpacity?: number; wholeSlideLink?: boolean; hidden?: boolean; } interface SlideshowProps { slideshowWidget: { slides: SlideData[]; autoplay?: boolean; autoplaySpeed?: number; arrows?: boolean; dots?: boolean; transition?: 'slide' | 'fade'; transitionSpeed?: number; pauseOnHover?: boolean; pauseOnInteraction?: boolean; arrowsStyle?: ArrowsStyle; dotsStyle?: DotsStyle; aspectRatio?: AspectRatio; defaultContentPosition?: ContentAnchor; defaultOverlayTint?: OverlayTint; defaultOverlayOpacity?: number; }; } // For a `flex flex-col` container: `justify-*` controls the MAIN axis // (vertical), `items-*` controls the CROSS axis (horizontal). Earlier // version had these swapped, so e.g. `tc` (top-center) rendered as // middle-left. Text alignment ships separately so the inner block uses the // same horizontal alignment as the column itself. const POSITION_CLASS: Record = { tl: { box: 'justify-start items-start', text: 'text-left' }, tc: { box: 'justify-start items-center', text: 'text-center' }, tr: { box: 'justify-start items-end', text: 'text-right' }, ml: { box: 'justify-center items-start', text: 'text-left' }, mc: { box: 'justify-center items-center', text: 'text-center' }, mr: { box: 'justify-center items-end', text: 'text-right' }, bl: { box: 'justify-end items-start', text: 'text-left' }, bc: { box: 'justify-end items-center', text: 'text-center' }, br: { box: 'justify-end items-end', text: 'text-right' } }; const ASPECT_CLASS: Record = { auto: '', '16:9': 'aspect-[16/9]', '21:9': 'aspect-[21/9]', '4:3': 'aspect-[4/3]', '1:1': 'aspect-square' }; const TINT_BG: Record, string> = { dark: 'bg-black', light: 'bg-white', // Bottom-heavy gradient gives legible captions without obscuring the // upper half of the image. Opacity multiplier still applies via CSS var. gradient: 'bg-gradient-to-t from-black via-black/40 to-transparent' }; function SlideOverlay({ tint, opacity }: { tint: OverlayTint; opacity: number; }) { if (tint === 'none' || opacity <= 0) return null; const clamped = Math.max(0, Math.min(1, opacity)); if (tint === 'gradient') { // Gradient tone is fixed top→bottom; opacity scales the whole layer // so a 0.5 opacity gradient still fades into transparent at the top. return (