// florals.jsx — fine line floral decorations inspired by Natacha's book
// All florals use currentColor so they can be tinted via parent color.

const FloralBranch1 = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 400 90" fill="none" stroke="currentColor" strokeWidth="1.1"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <path d="M5 55 Q 80 30 160 45 T 320 38 Q 360 35 395 50" />
    {/* small berries */}
    <circle cx="30" cy="48" r="2" /><circle cx="36" cy="44" r="1.6" />
    <circle cx="24" cy="44" r="1.6" /><circle cx="30" cy="40" r="1.6" />
    {/* leaf cluster 1 */}
    <path d="M70 42 q -6 -10 -14 -6 q 4 10 14 6 Z" />
    <path d="M78 38 q -4 -12 -14 -10 q 2 12 14 10 Z" />
    {/* small flower */}
    <g transform="translate(120 38)">
      <circle r="1.6" />
      {[0,1,2,3,4,5].map(i => (
        <ellipse key={i} cx="0" cy="-5" rx="1.4" ry="3"
                 transform={`rotate(${i*60})`} />
      ))}
    </g>
    {/* berries cluster */}
    <g transform="translate(180 42)">
      <circle cx="0" cy="0" r="1.6" /><circle cx="4" cy="-2" r="1.4" />
      <circle cx="-3" cy="-3" r="1.4" /><circle cx="1" cy="-5" r="1.2" />
      <circle cx="-4" cy="2" r="1.2" />
    </g>
    {/* leaves */}
    <path d="M220 40 q -8 -8 -16 -2 q 6 10 16 2 Z" />
    <path d="M232 35 q -4 -10 -14 -8 q 2 10 14 8 Z" />
    {/* tiny 4-petal flower */}
    <g transform="translate(275 36)">
      <circle r="1.4" />
      {[0,1,2,3].map(i => (
        <ellipse key={i} cx="0" cy="-4" rx="1.6" ry="2.8"
                 transform={`rotate(${i*90})`} />
      ))}
    </g>
    {/* end leaves */}
    <path d="M345 42 q -6 -8 -14 -4 q 4 10 14 4 Z" />
    <path d="M360 45 q 4 -10 14 -8 q -2 10 -14 8 Z" />
  </svg>
);

const FloralCornerTL = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 240 240" fill="none" stroke="currentColor" strokeWidth="1.2"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <path d="M-10 -10 Q 60 40 80 110 T 110 220" />
    {/* big flower */}
    <g transform="translate(48 48)">
      <circle r="3.2" fill="currentColor" opacity="0.6"/>
      {[0,1,2,3,4,5,6,7].map(i => (
        <ellipse key={i} cx="0" cy="-10" rx="3" ry="7"
                 transform={`rotate(${i*45})`} />
      ))}
    </g>
    {/* leaves along stem */}
    <path d="M72 90 q -14 -12 -28 -4 q 8 18 28 4 Z" />
    <path d="M86 130 q 16 -10 28 0 q -10 16 -28 0 Z" />
    <path d="M96 170 q -16 -10 -28 -2 q 8 18 28 2 Z" />
    {/* small flower */}
    <g transform="translate(108 195)">
      <circle r="1.8" />
      {[0,1,2,3,4].map(i => (
        <ellipse key={i} cx="0" cy="-5" rx="1.6" ry="3.5"
                 transform={`rotate(${i*72})`} />
      ))}
    </g>
    {/* berries */}
    <g transform="translate(20 70)">
      <circle cx="0" cy="0" r="2" /><circle cx="5" cy="-3" r="1.8" />
      <circle cx="-4" cy="-4" r="1.6" /><circle cx="2" cy="-7" r="1.4" />
    </g>
  </svg>
);

const FloralCornerBR = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 240 240" fill="none" stroke="currentColor" strokeWidth="1.2"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <g transform="translate(240 240) rotate(180)">
      <path d="M-10 -10 Q 60 40 80 110 T 110 220" />
      <g transform="translate(48 48)">
        <circle r="3.2" fill="currentColor" opacity="0.6"/>
        {[0,1,2,3,4,5,6,7].map(i => (
          <ellipse key={i} cx="0" cy="-10" rx="3" ry="7"
                   transform={`rotate(${i*45})`} />
        ))}
      </g>
      <path d="M72 90 q -14 -12 -28 -4 q 8 18 28 4 Z" />
      <path d="M86 130 q 16 -10 28 0 q -10 16 -28 0 Z" />
      <path d="M96 170 q -16 -10 -28 -2 q 8 18 28 2 Z" />
      <g transform="translate(108 195)">
        <circle r="1.8" />
        {[0,1,2,3,4].map(i => (
          <ellipse key={i} cx="0" cy="-5" rx="1.6" ry="3.5"
                   transform={`rotate(${i*72})`} />
        ))}
      </g>
    </g>
  </svg>
);

const FloralSprig = ({ className = "", style = {}, seed = 0 }) => {
  const rot = seed * 37 % 360;
  return (
    <svg viewBox="0 0 120 120" fill="none" stroke="currentColor" strokeWidth="1.1"
         strokeLinecap="round" strokeLinejoin="round" className={className}
         style={{...style, transform: `rotate(${rot}deg)`}}>
      <path d="M60 110 Q 55 70 65 30 T 60 5" />
      <path d="M62 85 q -10 -6 -18 -2 q 6 12 18 2 Z" />
      <path d="M58 65 q 12 -6 20 2 q -8 12 -20 -2 Z" />
      <path d="M65 45 q -10 -4 -16 2 q 6 10 16 -2 Z" />
      <g transform="translate(60 18)">
        <circle r="1.4" />
        {[0,1,2,3,4,5].map(i => (
          <ellipse key={i} cx="0" cy="-4" rx="1.4" ry="3"
                   transform={`rotate(${i*60})`} />
        ))}
      </g>
    </svg>
  );
};

const FloralWreath = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 200 200" fill="none" stroke="currentColor" strokeWidth="1.2"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <circle cx="100" cy="100" r="70" strokeDasharray="2 4" opacity="0.4" />
    {[0,1,2,3,4,5,6,7].map(i => {
      const a = (i / 8) * Math.PI * 2;
      const x = 100 + Math.cos(a) * 70;
      const y = 100 + Math.sin(a) * 70;
      const rot = (a * 180 / Math.PI) + 90;
      return (
        <g key={i} transform={`translate(${x} ${y}) rotate(${rot})`}>
          <path d="M0 -10 q -6 4 -8 12 q 8 -2 12 -10 q -2 8 2 14 q 6 -8 4 -16 Z" />
          <circle cx="0" cy="-2" r="1.4" />
        </g>
      );
    })}
  </svg>
);

const FloralDivider = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 600 60" fill="none" stroke="currentColor" strokeWidth="1.1"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <path d="M0 30 Q 100 10 200 30 T 400 30 T 600 30" />
    <g transform="translate(300 30)">
      <circle r="3" fill="currentColor" opacity="0.5"/>
      {[0,1,2,3,4,5,6,7].map(i => (
        <ellipse key={i} cx="0" cy="-7" rx="2" ry="5"
                 transform={`rotate(${i*45})`} />
      ))}
    </g>
    <g transform="translate(150 28)">
      <path d="M-8 0 q 0 -8 8 -8 q 8 0 8 8 q 0 8 -8 8 q -8 0 -8 -8 Z" opacity="0.6" />
    </g>
    <g transform="translate(450 32)">
      <path d="M-6 0 q 0 -6 6 -6 q 6 0 6 6 q 0 6 -6 6 q -6 0 -6 -6 Z" opacity="0.6" />
    </g>
    {/* end leaves */}
    <path d="M40 32 q -8 -6 -16 -2 q 4 12 16 2 Z" />
    <path d="M560 32 q 8 -6 16 -2 q -4 12 -16 2 Z" />
  </svg>
);

// flower pattern background tile (very subtle)
const FloralPattern = ({ opacity = 0.06 }) => (
  <svg width="100%" height="100%" style={{position:'absolute',inset:0,pointerEvents:'none',opacity}}
       preserveAspectRatio="xMidYMid slice">
    <defs>
      <pattern id="florapat" x="0" y="0" width="180" height="180" patternUnits="userSpaceOnUse">
        <g fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round">
          <g transform="translate(40 40)">
            <circle r="2" />
            {[0,1,2,3,4,5].map(i => (
              <ellipse key={i} cx="0" cy="-6" rx="2" ry="4"
                       transform={`rotate(${i*60})`} />
            ))}
          </g>
          <g transform="translate(130 90)">
            <path d="M0 0 q -6 -10 -14 -6 q 4 10 14 6 Z" />
          </g>
          <g transform="translate(70 140)">
            <circle cx="0" cy="0" r="1.4" />
            <circle cx="4" cy="-2" r="1.2" />
            <circle cx="-3" cy="-3" r="1.2" />
          </g>
          <g transform="translate(150 30)">
            <path d="M0 0 q 6 -8 14 -4 q -4 10 -14 4 Z" />
          </g>
        </g>
      </pattern>
    </defs>
    <rect width="100%" height="100%" fill="url(#florapat)" />
  </svg>
);

// soft paper grain
const PaperGrain = ({ opacity = 0.5 }) => (
  <div style={{
    position:'absolute', inset:0, pointerEvents:'none', opacity,
    backgroundImage: 'radial-gradient(circle at 20% 30%, rgba(0,0,0,0.025) 0%, transparent 40%), radial-gradient(circle at 80% 70%, rgba(0,0,0,0.02) 0%, transparent 50%)',
    mixBlendMode: 'multiply'
  }} />
);

// ─── New minimalist motifs (inspired by qi87 + user ref) ──────────────

// 4-point sparkle star — used like sparkles/glitter
const Sparkle = ({ size = 16, color = "currentColor", style = {} }) => (
  <svg className="fx-sparkle" viewBox="0 0 20 20" width={size} height={size}
       fill={color} style={{display:'inline-block', ...style}}>
    <path d="M10 0 C 10.5 6, 14 9.5, 20 10 C 14 10.5, 10.5 14, 10 20 C 9.5 14, 6 10.5, 0 10 C 6 9.5, 9.5 6, 10 0 Z" />
  </svg>
);

// Daisy — 5 rounded petals, flat fill
const Daisy = ({ size = 36, color = "currentColor", centerColor, style = {} }) => (
  <svg className="fx-daisy" viewBox="0 0 60 60" width={size} height={size} style={{display:'inline-block', ...style}}>
    <g transform="translate(30 30)">
      {[0,1,2,3,4].map(i => (
        <ellipse key={i} cx="0" cy="-14" rx="7" ry="11"
                 fill={color} transform={`rotate(${i*72})`} />
      ))}
      <circle r="5" fill={centerColor || "#FAF7EF"} />
      <circle r="2.5" fill={color} opacity="0.4"/>
    </g>
  </svg>
);

// Tiny line-art flower (5 petals, outline only)
const TinyFlower = ({ size = 24, color = "currentColor", style = {} }) => (
  <svg className="fx-daisy" viewBox="0 0 40 40" width={size} height={size} fill="none"
       stroke={color} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round"
       style={{display:'inline-block', ...style}}>
    <g transform="translate(20 20)">
      <circle r="1.6" fill={color}/>
      {[0,1,2,3,4].map(i => (
        <ellipse key={i} cx="0" cy="-7" rx="2.4" ry="5"
                 transform={`rotate(${i*72})`} />
      ))}
    </g>
  </svg>
);

// Eucalyptus branch — alternating rounded leaves
const EucalyptusBranch = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 200 80" fill="none" stroke="currentColor" strokeWidth="1.2"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <path d="M5 40 Q 80 35 195 40" />
    {[20, 50, 80, 110, 140, 170].map((x, i) => {
      const top = i % 2 === 0;
      const cy = top ? 28 : 52;
      const ry = 7;
      return (
        <ellipse key={i} cx={x} cy={cy} rx="5" ry={ry}
                 fill="currentColor" fillOpacity="0.18"
                 transform={`rotate(${top ? -25 : 25} ${x} ${cy})`} />
      );
    })}
    {[35, 65, 95, 125, 155].map((x, i) => {
      const top = i % 2 === 0;
      const cy = top ? 30 : 50;
      return (
        <ellipse key={'b'+i} cx={x} cy={cy} rx="4" ry="6"
                 fill="none"
                 transform={`rotate(${top ? -20 : 20} ${x} ${cy})`} />
      );
    })}
  </svg>
);

// Fern frond — thin spine with paired pinnae
const FernLeaf = ({ className = "", style = {} }) => (
  <svg viewBox="0 0 80 200" fill="none" stroke="currentColor" strokeWidth="1.1"
       strokeLinecap="round" strokeLinejoin="round" className={className} style={style}>
    <path d="M40 200 Q 42 100 38 8" />
    {Array.from({length: 12}).map((_, i) => {
      const y = 20 + i * 14;
      const len = 26 - i * 1.6;
      const skew = 8 - i * 0.5;
      return (
        <g key={i}>
          <path d={`M40 ${y} Q ${40 - len/2 + skew} ${y - len/3}  ${40 - len} ${y - 4}`} />
          <path d={`M40 ${y} Q ${40 + len/2 - skew} ${y - len/3}  ${40 + len} ${y - 4}`} />
        </g>
      );
    })}
  </svg>
);

// Small sun — circle with rays
const SunBurst = ({ size = 32, color = "currentColor", style = {} }) => (
  <svg viewBox="0 0 40 40" width={size} height={size} fill="none"
       stroke={color} strokeWidth="1.2" strokeLinecap="round"
       style={{display:'inline-block', ...style}}>
    <circle cx="20" cy="20" r="6" />
    {[0,1,2,3,4,5,6,7].map(i => {
      const a = (i / 8) * Math.PI * 2;
      const x1 = 20 + Math.cos(a) * 10;
      const y1 = 20 + Math.sin(a) * 10;
      const x2 = 20 + Math.cos(a) * 15;
      const y2 = 20 + Math.sin(a) * 15;
      return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} />;
    })}
  </svg>
);

// Scattered sparkles container — uses absolute positioning
const SparkleField = ({ count = 10, color = "currentColor", opacity = 0.6, seed = 0 }) => {
  const items = React.useMemo(() => {
    const rand = (i) => {
      const x = Math.sin(i * 12.9898 + seed * 78.233) * 43758.5453;
      return x - Math.floor(x);
    };
    return Array.from({length: count}).map((_, i) => ({
      top: rand(i*3) * 100 + '%',
      left: rand(i*3+1) * 100 + '%',
      size: 8 + rand(i*3+2) * 14,
      opacity: 0.4 + rand(i*5) * 0.6,
    }));
  }, [count, seed]);
  return (
    <div style={{position:'absolute', inset:0, pointerEvents:'none', opacity}}>
      {items.map((p, i) => (
        <Sparkle key={i} size={p.size} color={color}
          style={{position:'absolute', top: p.top, left: p.left, opacity: p.opacity}} />
      ))}
    </div>
  );
};

// Animated blob shape (organic background element)
const SoftBlob = ({ size = 400, color = "currentColor", opacity = 0.12, style = {} }) => (
  <svg viewBox="0 0 200 200" width={size} height={size}
       style={{position:'absolute',pointerEvents:'none',opacity,...style}}>
    <path fill={color}
      d="M44.7,-67.2C58.8,-60.1,71.8,-49.4,77.4,-35.4C83,-21.5,81.2,-4.3,76.9,11.4C72.6,27.1,65.8,41.4,55.1,52.6C44.4,63.8,29.8,72,13.6,76.2C-2.6,80.4,-20.4,80.7,-35.5,74C-50.5,67.3,-62.9,53.6,-69.9,38C-77,22.4,-78.7,4.9,-75.6,-11.4C-72.4,-27.7,-64.3,-42.8,-52.4,-50.9C-40.5,-59,-24.7,-60.1,-9.4,-62.2C5.9,-64.3,30.6,-74.4,44.7,-67.2Z"
      transform="translate(100 100)" />
  </svg>
);

Object.assign(window, {
  FloralBranch1, FloralCornerTL, FloralCornerBR, FloralSprig,
  FloralWreath, FloralDivider, FloralPattern, PaperGrain, SoftBlob,
  Sparkle, Daisy, TinyFlower, EucalyptusBranch, FernLeaf, SunBurst, SparkleField
});
