/* global React */
// House Hunt Diary — sample data + helpers shared across canvas & prototype.

const SAMPLE = [
  {
    id: 'p1',
    title: 'Cedar bungalow with the porch swing',
    label: 'Cedar bungalow',
    neighborhood: 'Sellwood',
    city: 'Portland, OR',
    region: 'Inner SE',
    price: 689000,
    beds: 3, baths: 2, sqft: 1840,
    source: 'Redfin',
    saved: '2 days ago',
    note: 'The kitchen is dated but the light in the front room is unreal.',
    tags: ['light', 'walkable'],
    status: 'shortlisted',
    visibility: 'private',
    color: '#c89770',
    accent: '#8b5e3c',
    commute: '22 min to downtown',
    aspect: 1.10,
  },
  {
    id: 'p2',
    title: 'Mid-century on a corner lot',
    label: 'Mid-century corner',
    neighborhood: 'Mt Tabor',
    city: 'Portland, OR',
    region: 'Inner SE',
    price: 825000,
    beds: 4, baths: 2, sqft: 2100,
    source: 'Zillow',
    saved: 'yesterday',
    note: '',
    tags: ['mid-century'],
    status: 'visited',
    visibility: 'public',
    color: '#9aaf94',
    accent: '#4f6b4f',
    commute: '28 min to downtown',
    aspect: 0.78,
  },
  {
    id: 'p3',
    title: 'Two-bed loft above the bakery',
    label: 'Bakery loft',
    neighborhood: 'Pearl District',
    city: 'Portland, OR',
    region: 'NW',
    price: 540000,
    beds: 2, baths: 1, sqft: null,
    source: 'private',
    saved: '5 days ago',
    note: 'Maya found it on Craigslist. No floorplan, ask for one.',
    tags: ['loft', 'incomplete'],
    status: null,
    visibility: 'private',
    color: '#b89978',
    accent: '#6b4f37',
    commute: null,
    aspect: 1.32,
  },
  {
    id: 'p4',
    title: 'Stone cottage near the reservoir',
    label: 'Stone cottage',
    neighborhood: 'Mt Tabor',
    city: 'Portland, OR',
    region: 'Inner SE',
    price: 720000,
    beds: 3, baths: 2, sqft: 1620,
    source: 'Redfin',
    saved: 'a week ago',
    note: 'Walkable to the reservoir loop. Roof was redone in 2022.',
    tags: ['stone', 'reservoir'],
    status: 'favorite',
    visibility: 'public',
    color: '#a8a098',
    accent: '#5e554c',
    commute: '26 min to downtown',
    aspect: 0.85,
  },
  {
    id: 'p5',
    title: 'Craftsman with the wraparound',
    label: 'Craftsman',
    neighborhood: 'Alberta Arts',
    city: 'Portland, OR',
    region: 'NE',
    price: 615000,
    beds: 3, baths: 1, sqft: 1480,
    source: 'Compass',
    saved: '3 days ago',
    note: '',
    tags: ['craftsman'],
    status: null,
    visibility: 'private',
    color: '#c2624a',
    accent: '#7a3a26',
    commute: '18 min to downtown',
    aspect: 1.0,
  },
  {
    id: 'p6',
    title: 'Garden flat with the south light',
    label: 'Garden flat',
    neighborhood: 'Buckman',
    city: 'Portland, OR',
    region: 'Inner SE',
    price: 425000,
    beds: 1, baths: 1, sqft: 780,
    source: 'private',
    saved: '4 hours ago',
    note: 'Maybe the most affordable thing in our list. Garden is huge.',
    tags: ['garden'],
    status: null,
    visibility: 'private',
    color: '#8a9b6f',
    accent: '#4a5736',
    commute: '14 min to downtown',
    aspect: 1.5,
  },
  {
    id: 'p7',
    title: 'Brick four-square',
    label: 'Brick four-square',
    neighborhood: 'Irvington',
    city: 'Portland, OR',
    region: 'NE',
    price: 875000,
    beds: 4, baths: 3, sqft: 2480,
    source: 'Zillow',
    saved: 'a week ago',
    note: '',
    tags: ['family'],
    status: 'shortlisted',
    visibility: 'public',
    color: '#a45c47',
    accent: '#6a3520',
    commute: '20 min to downtown',
    aspect: 0.92,
  },
  {
    id: 'p8',
    title: 'Tiny A-frame on the bluff',
    label: 'A-frame',
    neighborhood: 'Linnton',
    city: 'Portland, OR',
    region: 'NW',
    price: 489000,
    beds: 2, baths: 1, sqft: null,
    source: 'private',
    saved: 'today',
    note: 'Off-market. Owner is a friend of David. Worth visiting before listing.',
    tags: ['off-market', 'incomplete'],
    status: 'favorite',
    visibility: 'private',
    color: '#7d8f9f',
    accent: '#3f4d5b',
    commute: '34 min to downtown',
    aspect: 1.18,
  },
  {
    id: 'p9',
    title: 'Apartment over the corner store',
    label: 'Corner store flat',
    neighborhood: 'Division',
    city: 'Portland, OR',
    region: 'Inner SE',
    price: 379000,
    beds: 1, baths: 1, sqft: 640,
    source: 'Redfin',
    saved: 'yesterday',
    note: '',
    tags: [],
    status: null,
    visibility: 'public',
    color: '#cab68c',
    accent: '#7a6539',
    commute: '16 min to downtown',
    aspect: 0.7,
  },
];

// Pretty-print helpers
const fmt = {
  price: (n) => n == null ? '—' : '$' + (n / 1000).toFixed(0) + 'k',
  priceFull: (n) => n == null ? '—' : '$' + n.toLocaleString(),
  facts: (p) => {
    const parts = [];
    if (p.beds) parts.push(p.beds + ' bd');
    if (p.baths) parts.push(p.baths + ' ba');
    if (p.sqft) parts.push(p.sqft.toLocaleString() + ' sf');
    return parts;
  },
};

// Tiny inline icons (stroke-based; warm ink color)
const I = {
  bed: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M2 11V5M14 11V8a2 2 0 0 0-2-2H7v5M2 11h12M2 13h12"/></svg>
  ),
  bath: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M2 9h12v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9zM4 9V4a1.5 1.5 0 0 1 3 0M3 13l-1 1.5M13 13l1 1.5"/></svg>
  ),
  sqft: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <rect x="2.5" y="2.5" width="11" height="11" rx="0.5"/><path d="M5 2.5v3M5 13.5v-3M2.5 5h3M2.5 11h3"/></svg>
  ),
  pin: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M8 14s5-4.5 5-8.5A5 5 0 0 0 3 5.5C3 9.5 8 14 8 14z"/><circle cx="8" cy="6" r="1.5"/></svg>
  ),
  link: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M7 9a3 3 0 0 0 4.2.3l2-2A3 3 0 0 0 9 3l-1 1M9 7a3 3 0 0 0-4.2-.3l-2 2A3 3 0 0 0 7 13l1-1"/></svg>
  ),
  note: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 2.5h7l3 3V13a.5.5 0 0 1-.5.5h-9.5A.5.5 0 0 1 2.5 13V3a.5.5 0 0 1 .5-.5z"/><path d="M10 2.5v3h3M5 8.5h6M5 11h4"/></svg>
  ),
  heart: (s = 14, filled) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill={filled ? 'currentColor' : 'none'} stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M8 13.5S2.5 10 2.5 6.2A2.7 2.7 0 0 1 8 5a2.7 2.7 0 0 1 5.5 1.2C13.5 10 8 13.5 8 13.5z"/></svg>
  ),
  bookmark: (s = 14, filled) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill={filled ? 'currentColor' : 'none'} stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3.5 2.5h9V14L8 10.5 3.5 14V2.5z"/></svg>
  ),
  eye: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="2"/></svg>
  ),
  lock: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="7" width="10" height="7" rx="1"/><path d="M5 7V5a3 3 0 0 1 6 0v2"/></svg>
  ),
  globe: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="8" cy="8" r="6"/><path d="M2 8h12M8 2c2 2 2 10 0 12M8 2c-2 2-2 10 0 12"/></svg>
  ),
  plus: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
      <path d="M8 3v10M3 8h10"/></svg>
  ),
  search: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round">
      <circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5L13.5 13.5"/></svg>
  ),
  close: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round">
      <path d="M3 3l10 10M13 3L3 13"/></svg>
  ),
  arrow: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 8h10M9 4l4 4-4 4"/></svg>
  ),
  external: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M9 3h4v4M13 3L7 9M11 9v3.5a.5.5 0 0 1-.5.5h-7a.5.5 0 0 1-.5-.5v-7a.5.5 0 0 1 .5-.5H7"/></svg>
  ),
};

// A subtle, recognizable mini-map illustration. Not real geo — feels like a
// hand-drawn neighborhood diagram. Colors pull from --paper-2 / accent.
function MiniMap({ width = 240, height = 96, neighborhood = '', accent = '#c2624a', dim = false }) {
  // deterministic seed from neighborhood
  let s = 0; for (const c of (neighborhood || 'x')) s = (s * 31 + c.charCodeAt(0)) & 0xffff;
  const r = (n) => { s = (s * 9301 + 49297) % 233280; return (s / 233280) * n; };
  const roads = [];
  for (let i = 0; i < 4; i++) roads.push({ y: 14 + i * 22 + r(8), w: 30 + r(60) });
  const cross = [];
  for (let i = 0; i < 5; i++) cross.push({ x: 18 + i * 50 + r(8), h: 30 + r(50) });
  return (
    <svg viewBox={`0 0 ${width} ${height}`} width={width} height={height} style={{ display: 'block' }} aria-hidden>
      <rect x="0" y="0" width={width} height={height} fill="var(--paper-2)" />
      {/* park / green blob */}
      <ellipse cx={width * 0.78} cy={height * 0.32} rx="34" ry="20" fill="rgba(120,140,100,.22)" />
      {/* water sliver */}
      <path d={`M0 ${height - 18} Q ${width*0.3} ${height - 8}, ${width*0.6} ${height - 22} T ${width} ${height - 14} L ${width} ${height} L 0 ${height} Z`} fill="rgba(120,150,170,.20)" />
      {/* roads */}
      <g stroke={dim ? 'rgba(31,27,22,.18)' : 'rgba(31,27,22,.30)'} strokeWidth="1" fill="none">
        {roads.map((rd, i) => <line key={i} x1="0" y1={rd.y} x2={width} y2={rd.y} />)}
        {cross.map((c, i) => <line key={i} x1={c.x} y1="0" x2={c.x} y2={height} />)}
      </g>
      {/* the pin */}
      <g transform={`translate(${width / 2}, ${height / 2 - 2})`}>
        <circle r="11" fill={accent} fillOpacity=".18" />
        <circle r="5" fill={accent} />
        <circle r="2" fill="#fff" />
      </g>
    </svg>
  );
}

Object.assign(window, { SAMPLE, fmt, I, MiniMap });
