// Albanna Conwood — neutral architectural placeholder photos.
// Restrained, brand-coloured, material-led. Replace with real photography later.

const Photo = ({ pattern, className = "", children, dark = false }) => (
  <div className={`photo ${className}`} style={{ position: "relative", overflow: "hidden", background: dark ? "#1d2122" : "#cfd2d3" }}>
    <PhotoArt pattern={pattern} dark={dark} />
    {children}
  </div>
);

const fillStyle = { position: "absolute", inset: 0, width: "100%", height: "100%" };

// Palette
const E = "#37857d";
const ED = "#2d6e67";
const LIGHT = "#f6f4ef";
const K = "#1a1918";
const S = "#898b8d";

const PhotoArt = ({ pattern, dark }) => {
  const sky = dark ? "#1d2122" : "#dadcdd";
  const ink = dark ? LIGHT : K;
  const wall = dark ? "#2a2d2e" : "#e6e7e8";
  const wallDk = dark ? "#1f2222" : "#cfd0d1";

  if (pattern === "modern-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={sky}/>
        {/* horizon shadow */}
        <rect x="0" y="320" width="800" height="180" fill={wallDk} opacity="0.5"/>
        {/* low long house */}
        <rect x="80" y="220" width="640" height="110" fill={wall}/>
        {/* upper volume offset */}
        <rect x="200" y="160" width="320" height="60" fill={wall}/>
        {/* deep eave shadow */}
        <rect x="80" y="218" width="640" height="6" fill={ink} opacity="0.55"/>
        <rect x="200" y="158" width="320" height="4" fill={ink} opacity="0.55"/>
        {/* floor-to-ceiling glazing rhythm */}
        {Array.from({length: 8}).map((_, i) => (
          <rect key={i} x={120 + i * 76} y="240" width="60" height="80" fill={dark ? "#0d1212" : "#3a4a4c"} opacity="0.85"/>
        ))}
        {/* upper slot */}
        <rect x="220" y="180" width="280" height="22" fill={dark ? "#0d1212" : "#3a4a4c"} opacity="0.85"/>
        {/* reflecting pool */}
        <rect x="80" y="340" width="640" height="40" fill={E} opacity="0.55"/>
        <rect x="80" y="340" width="640" height="2" fill={E}/>
        {/* ground line */}
        <rect x="0" y="380" width="800" height="2" fill={ink} opacity="0.25"/>
      </svg>
    );
  }

  if (pattern === "courtyard-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={sky}/>
        {/* three pavilions */}
        {[80, 320, 560].map((x, i) => (
          <g key={i}>
            <rect x={x} y={180} width={160} height={150} fill={wall}/>
            <rect x={x} y={178} width={160} height={4} fill={ink} opacity="0.5"/>
            {/* arch openings */}
            <path d={`M ${x+30} 320 Q ${x+50} 260 ${x+70} 320 Z`} fill={dark ? "#0d1212" : "#3a4a4c"} opacity="0.85"/>
            <path d={`M ${x+90} 320 Q ${x+110} 260 ${x+130} 320 Z`} fill={dark ? "#0d1212" : "#3a4a4c"} opacity="0.85"/>
          </g>
        ))}
        {/* connecting colonnade */}
        {Array.from({length: 12}).map((_, i) => (
          <rect key={i} x={100 + i * 56} y="330" width="6" height="46" fill={ink} opacity="0.35"/>
        ))}
        <rect x="80" y="328" width="640" height="3" fill={ink} opacity="0.5"/>
        {/* ground */}
        <rect x="0" y="376" width="800" height="124" fill={wallDk} opacity="0.6"/>
      </svg>
    );
  }

  if (pattern === "stone-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={sky}/>
        {/* heavy stone block massing */}
        <rect x="120" y="200" width="560" height="160" fill={wall}/>
        <rect x="120" y="160" width="280" height="40" fill={wall}/>
        {/* stone coursing — horizontal lines */}
        {Array.from({length: 7}).map((_, i) => (
          <rect key={i} x="120" y={210 + i * 22} width="560" height="1" fill={ink} opacity="0.18"/>
        ))}
        {/* vertical block joints */}
        {Array.from({length: 8}).map((_, i) => (
          <rect key={i} x={180 + i * 60} y="200" width="1" height="160" fill={ink} opacity="0.14"/>
        ))}
        {/* deep slot windows */}
        {[260, 360, 460, 560].map((x, i) => (
          <rect key={i} x={x} y="240" width="40" height="100" fill={dark ? "#0d1212" : "#2c3a3c"}/>
        ))}
        <rect x="160" y="180" width="200" height="14" fill={dark ? "#0d1212" : "#2c3a3c"}/>
        {/* ground */}
        <rect x="0" y="360" width="800" height="140" fill={wallDk} opacity="0.65"/>
      </svg>
    );
  }

  if (pattern === "shore-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <defs>
          <linearGradient id="water" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0" stopColor={E} stopOpacity="0.45"/>
            <stop offset="1" stopColor={ED} stopOpacity="0.7"/>
          </linearGradient>
        </defs>
        <rect width="800" height="500" fill={sky}/>
        {/* mansion volumes */}
        <rect x="80" y="180" width="640" height="140" fill={wall}/>
        <rect x="180" y="120" width="220" height="60" fill={wall}/>
        <rect x="500" y="140" width="160" height="40" fill={wall}/>
        {/* eave shadows */}
        <rect x="80" y="178" width="640" height="4" fill={ink} opacity="0.5"/>
        <rect x="180" y="118" width="220" height="3" fill={ink} opacity="0.5"/>
        {/* observatory */}
        <circle cx="290" cy="115" r="14" fill={wall}/>
        <rect x="287" y="100" width="6" height="20" fill={ink} opacity="0.4"/>
        {/* glazing */}
        {Array.from({length: 9}).map((_, i) => (
          <rect key={i} x={110 + i * 70} y="200" width="56" height="90" fill={dark ? "#0d1212" : "#2c3a3c"} opacity="0.85"/>
        ))}
        {/* sea */}
        <rect x="0" y="320" width="800" height="180" fill="url(#water)"/>
        {/* deck rail */}
        <rect x="80" y="320" width="640" height="2" fill={ink} opacity="0.5"/>
      </svg>
    );
  }

  if (pattern === "modernist-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={sky}/>
        {/* cantilevered volume */}
        <rect x="120" y="160" width="500" height="80" fill={wall}/>
        {/* shadow under */}
        <rect x="120" y="240" width="500" height="6" fill={ink} opacity="0.5"/>
        {/* lower volume offset */}
        <rect x="220" y="246" width="380" height="100" fill={wallDk}/>
        {/* deep horizontal glass slot */}
        <rect x="160" y="180" width="420" height="40" fill={dark ? "#0d1212" : "#2c3a3c"}/>
        {/* support walls */}
        <rect x="240" y="260" width="20" height="86" fill={ink} opacity="0.7"/>
        <rect x="540" y="260" width="20" height="86" fill={ink} opacity="0.7"/>
        {/* sunken pool court */}
        <rect x="280" y="346" width="240" height="30" fill={E} opacity="0.6"/>
        {/* ground */}
        <rect x="0" y="376" width="800" height="124" fill={wallDk} opacity="0.6"/>
      </svg>
    );
  }

  if (pattern === "estate-villa") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={sky}/>
        {/* multiple villas in a compound */}
        {[60, 240, 420, 600].map((x, i) => (
          <g key={i}>
            <rect x={x} y={210 + (i % 2) * 14} width={140} height={130} fill={wall}/>
            <rect x={x} y={208 + (i % 2) * 14} width={140} height={3} fill={ink} opacity="0.5"/>
            {/* windows */}
            <rect x={x+24} y={240 + (i%2)*14} width={28} height={56} fill={dark?"#0d1212":"#2c3a3c"} opacity="0.85"/>
            <rect x={x+88} y={240 + (i%2)*14} width={28} height={56} fill={dark?"#0d1212":"#2c3a3c"} opacity="0.85"/>
          </g>
        ))}
        {/* path */}
        <rect x="0" y="350" width="800" height="2" fill={ink} opacity="0.25"/>
        <rect x="0" y="352" width="800" height="148" fill={wallDk} opacity="0.55"/>
        {/* boundary wall */}
        <rect x="0" y="200" width="800" height="2" fill={ink} opacity="0.18"/>
      </svg>
    );
  }

  if (pattern === "detail-rebar") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={dark ? "#1a1d1e" : "#d4d6d7"}/>
        {/* concrete formwork */}
        {Array.from({length: 14}).map((_, i) => (
          <rect key={i} x="0" y={i * 36} width="800" height="2" fill={ink} opacity="0.18"/>
        ))}
        {/* rebar grid */}
        {Array.from({length: 12}).map((_, i) => (
          <rect key={`h${i}`} x="0" y={50 + i * 36} width="800" height="3" fill={ink} opacity="0.6"/>
        ))}
        {Array.from({length: 16}).map((_, i) => (
          <rect key={`v${i}`} x={50 + i * 50} y="0" width="3" height="500" fill={ink} opacity="0.55"/>
        ))}
        {/* tie wires (dots at intersections) */}
        {Array.from({length: 12}).map((_, r) =>
          Array.from({length: 16}).map((_, c) => (
            <circle key={`d${r}-${c}`} cx={51 + c * 50} cy={51 + r * 36} r="3" fill={E} opacity="0.85"/>
          ))
        )}
      </svg>
    );
  }

  if (pattern === "detail-stone") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={dark ? "#2a2c2c" : "#dcdcd8"}/>
        {/* stone slabs */}
        {Array.from({length: 5}).map((_, r) => (
          <g key={r}>
            {Array.from({length: 4}).map((_, c) => {
              const x = c * 200 + (r % 2 ? 40 : 0);
              return (
                <g key={c}>
                  <rect x={x} y={r * 100} width="200" height="100" fill={dark ? "#3a3c3c" : "#cdcdc6"} opacity={0.55 + (r * c) % 4 * 0.08}/>
                  <rect x={x} y={r * 100} width="200" height="1" fill={ink} opacity="0.18"/>
                  <rect x={x} y={r * 100} width="1" height="100" fill={ink} opacity="0.14"/>
                  {/* veining */}
                  <path d={`M ${x+20} ${r*100+30} Q ${x+70} ${r*100+45} ${x+150} ${r*100+25} T ${x+200} ${r*100+50}`} stroke={ink} strokeWidth="0.5" fill="none" opacity="0.18"/>
                </g>
              );
            })}
          </g>
        ))}
      </svg>
    );
  }

  if (pattern === "detail-mep") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={dark ? "#15191a" : "#1c1f20"}/>
        {/* services on a soffit — copper and steel runs */}
        {[80, 140, 220, 300, 360, 420].map((y, i) => (
          <rect key={i} x="0" y={y} width="800" height="6" fill={i % 2 ? "#c9a363" : "#a8a8a4"} opacity="0.7"/>
        ))}
        {/* hangers */}
        {Array.from({length: 12}).map((_, i) => (
          <rect key={i} x={50 + i * 65} y="0" width="2" height="480" fill="#888a8c" opacity="0.45"/>
        ))}
        {/* ductwork rectangle */}
        <rect x="180" y="200" width="440" height="60" fill={dark ? "#2a2e2f" : "#5a5e5f"} opacity="0.8"/>
        <rect x="180" y="200" width="440" height="2" fill={LIGHT} opacity="0.2"/>
        {/* light gleam */}
        <rect x="500" y="206" width="80" height="2" fill={E} opacity="0.35"/>
      </svg>
    );
  }

  if (pattern === "studio") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={dark ? "#1a1d1e" : "#e6e7e6"}/>
        {/* drafting paper / plan */}
        <rect x="60" y="60" width="680" height="380" fill={dark ? "#2a2d2e" : LIGHT}/>
        <rect x="60" y="60" width="680" height="2" fill={ink} opacity="0.2"/>
        {/* plan-view villa */}
        <rect x="180" y="140" width="440" height="220" fill="none" stroke={ink} strokeWidth="1.2" opacity="0.65"/>
        {/* interior walls */}
        <rect x="180" y="220" width="260" height="1.5" fill={ink} opacity="0.55"/>
        <rect x="350" y="140" width="1.5" height="220" fill={ink} opacity="0.55"/>
        <rect x="440" y="270" width="180" height="1.5" fill={ink} opacity="0.55"/>
        <rect x="520" y="140" width="1.5" height="130" fill={ink} opacity="0.55"/>
        {/* dimension lines */}
        <rect x="180" y="120" width="440" height="0.6" fill={E} opacity="0.7"/>
        <rect x="180" y="118" width="2" height="6" fill={E}/>
        <rect x="618" y="118" width="2" height="6" fill={E}/>
        {/* north arrow */}
        <circle cx="700" cy="400" r="14" fill="none" stroke={E} strokeWidth="0.8"/>
        <path d="M 700 388 L 705 410 L 700 404 L 695 410 Z" fill={E}/>
        {/* title block */}
        <rect x="540" y="380" width="180" height="40" fill="none" stroke={ink} strokeWidth="0.6" opacity="0.5"/>
        <rect x="540" y="394" width="180" height="0.5" fill={ink} opacity="0.4"/>
      </svg>
    );
  }

  if (pattern === "interior") {
    return (
      <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
        <rect width="800" height="500" fill={wall}/>
        {/* big window */}
        <rect x="100" y="60" width="600" height="280" fill={dark ? "#0d1212" : "#3a4a4c"} opacity="0.7"/>
        <rect x="397" y="60" width="6" height="280" fill={wall}/>
        <rect x="100" y="195" width="600" height="3" fill={wall}/>
        {/* floor — perspective */}
        <polygon points={`100,340 700,340 800,500 0,500`} fill={wallDk}/>
        {Array.from({length: 7}).map((_, i) => (
          <line key={i} x1={100 + i * 100} y1="340" x2={i * 100 - 200} y2="500" stroke={ink} strokeWidth="0.5" opacity="0.18"/>
        ))}
        {/* low sofa silhouette */}
        <rect x="220" y="380" width="360" height="46" fill={dark ? "#0d1212" : "#2c3032"}/>
        <rect x="220" y="370" width="360" height="12" fill={dark ? "#1c2020" : "#3c4042"}/>
      </svg>
    );
  }

  // default — quiet wall
  return (
    <svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice" style={fillStyle}>
      <rect width="800" height="500" fill={wall}/>
      <rect x="0" y="0" width="800" height="2" fill={ink} opacity="0.1"/>
      <rect x="0" y="498" width="800" height="2" fill={ink} opacity="0.1"/>
    </svg>
  );
};

window.Photo = Photo;
