/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
 */

import React, { useState } from "react";

interface HonoratoLogoProps {
  className?: string;
}

export default function HonoratoLogo({ className = "h-12 w-12" }: HonoratoLogoProps) {
  const logoSources = [
    "/logo.png",
    "/logo.png (1).png",
    "/logo.jpg",
    "/logo.jpeg",
    "/logo.webp"
  ];
  const [sourceIndex, setSourceIndex] = useState(0);
  const [useFallback, setUseFallback] = useState(false);

  const handleImageError = () => {
    if (sourceIndex < logoSources.length - 1) {
      setSourceIndex(prev => prev + 1);
    } else {
      setUseFallback(true);
    }
  };

  if (!useFallback) {
    return (
      <img
        src={logoSources[sourceIndex]}
        className={`${className} object-contain`}
        alt="Honorato Barber Shop Logo"
        onError={handleImageError}
      />
    );
  }

  return (
    <svg
      viewBox="0 0 500 500"
      className={className}
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
    >
      {/* 1. BEARD - BACKGROUND LAYER (Filled Black, detailed with white strands) */}
      <path
        d="M 180,310 C 180,380 200,470 250,480 C 300,470 320,380 320,310 C 335,320 345,360 335,400 C 320,450 280,490 250,492 C 220,490 180,450 165,400 C 155,360 165,320 180,310 Z"
        fill="#000000"
      />
      {/* Beard hair strand details (White highlights on black beard) */}
      <path
        d="M 210,340 C 205,370 215,410 230,440 
           M 290,340 C 295,370 285,410 270,440 
           M 230,360 C 225,390 230,430 245,465 
           M 270,360 C 275,390 270,430 255,465 
           M 200,380 C 195,410 210,440 225,460
           M 300,380 C 305,410 290,440 275,460
           M 250,380 L 250,475"
        stroke="#ffffff"
        strokeWidth="2"
        strokeLinecap="round"
        opacity="0.85"
      />

      {/* 2. SKULL BASE (White/Light Off-white) */}
      <path
        d="M 175,170 C 175,130 325,130 325,170 C 325,190 330,220 325,250 C 320,265 315,275 310,285 C 310,305 305,315 295,320 C 295,335 290,340 285,340 C 270,340 268,325 250,325 C 232,325 230,340 215,340 C 210,340 205,335 205,320 C 195,315 190,305 190,285 C 185,275 180,265 175,250 C 170,220 175,190 175,170 Z"
        fill="#ffffff"
        stroke="#000000"
        strokeWidth="4"
        strokeLinejoin="round"
      />

      {/* Skull Shading and temple cracks */}
      <path
        d="M 185,190 C 192,192 195,205 188,210 
           M 315,190 C 308,192 305,205 312,210
           M 250,150 L 250,165
           M 210,145 C 215,148 220,155 218,160
           M 290,145 C 285,148 280,155 282,160"
        stroke="#000000"
        strokeWidth="2"
        strokeLinecap="round"
      />

      {/* Eye Sockets (Deep Black with high-contrast stylized textures) */}
      <path
        d="M 195,210 C 195,195 235,195 235,210 C 235,230 195,230 195,210 Z"
        fill="#0B0B0B"
        stroke="#000000"
        strokeWidth="3.5"
      />
      {/* Texture inside Left Eye Socket */}
      <path
        d="M 202,212 C 205,210 212,212 210,218 M 200,218 C 205,222 215,220 220,215"
        stroke="#444444"
        strokeWidth="2.5"
        strokeLinecap="round"
      />

      <path
        d="M 265,210 C 265,195 305,195 305,210 C 305,230 265,230 265,210 Z"
        fill="#0B0B0B"
        stroke="#000000"
        strokeWidth="3.5"
      />
      {/* Texture inside Right Eye Socket */}
      <path
        d="M 272,212 C 275,210 282,212 280,218 M 270,218 C 275,222 285,220 290,215"
        stroke="#444444"
        strokeWidth="2.5"
        strokeLinecap="round"
      />

      {/* Angry brow line */}
      <path
        d="M 190,195 C 210,192 230,202 238,208 
           M 310,195 C 290,192 270,202 262,208"
        stroke="#000000"
        strokeWidth="4"
        strokeLinecap="round"
      />

      {/* Nasal Cavity (Upside down detailed heart shape) */}
      <path
        d="M 250,230 C 244,220 236,225 240,245 C 244,252 250,256 250,256 C 250,256 256,252 260,245 C 264,225 256,220 250,230 Z"
        fill="#0B0B0B"
        stroke="#000000"
        strokeWidth="2.5"
        strokeLinejoin="round"
      />

      {/* Cheekbone details & skull cracks */}
      <path
        d="M 185,245 C 195,245 200,255 195,265
           M 315,245 C 305,245 300,255 305,265
           M 205,275 C 215,275 220,285 218,295
           M 295,275 C 285,275 280,285 282,295"
        stroke="#000000"
        strokeWidth="2"
        strokeLinecap="round"
      />

      {/* Teeth and Jaw under the mustache */}
      <path
        d="M 225,310 L 225,325 
           M 235,310 L 235,325 
           M 245,310 L 245,325 
           M 255,310 L 255,325 
           M 265,310 L 265,325 
           M 275,310 L 275,325"
        stroke="#000000"
        strokeWidth="2"
        strokeLinecap="round"
      />
      <path
        d="M 220,318 C 235,322 265,322 280,318"
        stroke="#000000"
        strokeWidth="1.5"
      />

      {/* 3. POMPADOUR HAIR - TOP LAYER (Filled Black with fine White stroke details) */}
      <path
        d="M 160,150 C 145,115 170,40 250,50 C 330,40 355,115 340,150 C 365,155 375,185 355,210 C 345,222 330,225 330,225 C 330,225 348,185 325,170 C 300,152 285,175 250,160 C 215,175 200,152 175,170 C 152,185 170,225 170,225 C 170,225 155,222 145,210 C 125,185 135,155 160,150 Z"
        fill="#000000"
        stroke="#000000"
        strokeWidth="4"
        strokeLinejoin="round"
      />
      {/* High-fidelity white hair flow lines */}
      <path
        d="M 250,50 C 235,75 210,95 190,110 
           M 250,50 C 265,75 290,95 310,110 
           M 215,65 C 205,85 190,105 175,115 
           M 285,65 C 295,85 310,105 325,115 
           M 250,85 C 250,115 235,140 215,150
           M 250,85 C 250,115 265,140 285,150
           M 175,130 C 165,145 158,165 152,185
           M 325,130 C 335,145 342,165 348,185"
        stroke="#ffffff"
        strokeWidth="2.5"
        strokeLinecap="round"
        opacity="0.9"
      />

      {/* 4. HIPSTER HANDLEBAR MUSTACHE - ON TOP (Solid Black with fine details) */}
      <path
        d="M 250,270 C 275,270 305,260 335,265 C 365,270 395,290 405,270 C 410,240 375,245 355,255 C 330,268 290,278 250,280 C 210,278 170,268 145,255 C125,245 90,240 95,270 C 105,290 135,270 165,265 C 195,260 225,270 250,270 Z"
        fill="#000000"
        stroke="#000000"
        strokeWidth="3.5"
        strokeLinejoin="round"
      />
      {/* Highlight strokes on the mustache */}
      <path
        d="M 250,274 C 280,274 315,268 345,262 
           M 250,274 C 220,274 185,268 155,262
           M 360,260 C 380,265 395,272 398,268
           M 140,260 C 120,265 105,272 102,268"
        stroke="#ffffff"
        strokeWidth="1.5"
        strokeLinecap="round"
        opacity="0.75"
      />
    </svg>
  );
}
