// components/PdfCoverPlaceholder.jsx
import React from 'react';

// Soft tints so a grid of cover-less PDFs doesn't look identical.
const TINTS = [
    { from: '#eef2ff', to: '#e0e7ff', accent: '#6366f1', fold: '#c7d2fe' }, // indigo
    { from: '#f0f9ff', to: '#e0f2fe', accent: '#0ea5e9', fold: '#bae6fd' }, // sky
    { from: '#ecfdf5', to: '#d1fae5', accent: '#10b981', fold: '#a7f3d0' }, // emerald
    { from: '#fffbeb', to: '#fef3c7', accent: '#f59e0b', fold: '#fde68a' }, // amber
    { from: '#fdf2f8', to: '#fce7f3', accent: '#ec4899', fold: '#fbcfe8' }, // pink
    { from: '#f5f3ff', to: '#ede9fe', accent: '#8b5cf6', fold: '#ddd6fe' }, // violet
];

const tintFor = (pdf) => TINTS[Math.abs(Number(pdf?.id) || 0) % TINTS.length];

/**
 * Illustrated stand-in for a PDF without a cover image: a sheet of paper
 * with a folded corner, text lines and a "PDF" tag. Fills its (relative)
 * parent; `compact` drops the background pattern for small thumbnails.
 */
const PdfCoverPlaceholder = ({ pdf, compact = false }) => {
    const tint = tintFor(pdf);

    return (
        <div
            className="absolute inset-0 flex items-center justify-center overflow-hidden"
            style={{ background: `linear-gradient(160deg, ${tint.from} 0%, ${tint.to} 100%)` }}
            aria-hidden="true"
        >
            {!compact && (
                <>
                    <div
                        className="absolute -top-10 -right-10 size-40 rounded-full opacity-40 blur-2xl"
                        style={{ background: tint.accent }}
                    />
                    <div
                        className="absolute -bottom-12 -left-8 size-32 rounded-full opacity-20 blur-2xl"
                        style={{ background: tint.accent }}
                    />
                </>
            )}

            <svg
                viewBox="0 0 120 150"
                className={`relative ${compact ? 'w-[70%]' : 'w-[46%] max-w-[120px]'}`}
                style={{ filter: compact ? 'drop-shadow(0 1px 1px rgb(15 23 42 / 0.12))' : 'drop-shadow(0 10px 14px rgb(15 23 42 / 0.14))' }}
            >
                {/* Sheet with folded top-right corner */}
                <path d="M14 4h66l26 26v108a8 8 0 0 1-8 8H14a8 8 0 0 1-8-8V12a8 8 0 0 1 8-8z" fill="#ffffff" />
                <path d="M80 4v18a8 8 0 0 0 8 8h18z" fill={tint.fold} />

                {/* Heading + text lines */}
                <rect x="20" y="24" width="44" height="7" rx="3.5" fill={tint.accent} opacity="0.85" />
                <rect x="20" y="42" width="72" height="4" rx="2" fill="#e2e8f0" />
                <rect x="20" y="52" width="64" height="4" rx="2" fill="#e2e8f0" />
                <rect x="20" y="62" width="70" height="4" rx="2" fill="#e2e8f0" />
                <rect x="20" y="72" width="48" height="4" rx="2" fill="#e2e8f0" />
                <rect x="20" y="88" width="72" height="4" rx="2" fill="#f1f5f9" />
                <rect x="20" y="98" width="58" height="4" rx="2" fill="#f1f5f9" />

                {/* PDF tag */}
                <rect x="0" y="112" width="54" height="24" rx="6" fill="#ef4444" />
                <text
                    x="27"
                    y="128.5"
                    textAnchor="middle"
                    fontFamily="ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif"
                    fontSize="13"
                    fontWeight="800"
                    letterSpacing="1"
                    fill="#ffffff"
                >
                    PDF
                </text>
            </svg>
        </div>
    );
};

export default PdfCoverPlaceholder;
