/* PortfolioPage — projects with honest placeholders until photography arrives. */
function PortfolioPage({ onNav }) {
  const { Eyebrow, Button, Divider } = window.DomumDesignSystem_84ba75;
  const { Photo, PageHeader, InquiryBand, TextureBand, Rule } = window;
  const [filter, setFilter] = React.useState('All');
  const [slide, setSlide] = React.useState(0);
  const [reveal, setReveal] = React.useState(50);
  const [dragging, setDragging] = React.useState(false);
  const [shotIdx, setShotIdx] = React.useState({});
  const groups = [
    {
      eyebrow: 'Project One', t: 'The Kitchen, Timelessness recapture', place: "Governor's Mansion Historic District", type: 'Kitchen', ratio: '4 / 3', start: 1,
      problem: '',
      d: 'We worked with the structure already there, keeping the plan largely where it was and putting the budget into what shows: timeless millwork details, elevated materials, and a more functional use of the space the house already had.',
      facts: [['Project', 'Kitchen renovation'], ['Era', 'Dutch Colonial, c. 1902'], ['Materials', 'Marble, walnut, unlacquered brass']],
      shots: [
        { src: './assets/photo-craftsman-kitchen-before.jpg', label: 'Before', alt: 'Kitchen before renovation with navy cabinets, yellow walls, and a laminate island' },
        { src: './assets/photo-craftsman-kitchen.jpg', label: 'After', alt: 'Kitchen after renovation with greige cabinetry, marble surfaces, brass pendants, and a walnut work table' },
      ],
    },
    {
      eyebrow: 'Project Two', t: 'The Primary Bath, Rebuilt', place: "Governor's Mansion Historic District", type: 'Primary Bath', ratio: '3 / 4', start: 1,
      problem: '',
      d: 'The surround came out for a curbed marble shower with glass and brass, the standalone sinks were replaced by a double vanity under marble giving the space richer detail and a more elevated finish.',
      facts: [['Scope', 'Primary bath renovation'], ['Fixtures', 'Double vanity, walk-in shower with frameless glass'], ['Materials', 'Marble, limestone, brass']],
      shots: [
        { src: './assets/photo-bath-before.jpg', label: 'Before', alt: 'Bathroom before renovation with oak cabinetry, yellow walls, and a fiberglass shower surround' },
        { src: './assets/photo-bath-after.jpg', label: 'After', alt: 'Bathroom after renovation with marble tile shower, brass fittings, and stone checkerboard floor' },
        { src: './assets/photo-bath-vanity.jpg', label: 'After', alt: 'Black double vanity with marble top, brass fittings, arched mirrors, and pleated sconces' },
      ],
    },
  ];
  const pairs = [
    {
      t: 'The Dining Room, Reconsidered', place: 'Spring Street', type: 'Whole-home',
      before: './assets/ba-dining-1-before-fit.jpg', after: './assets/ba-dining-1-after-fit.jpg',
      ratio: '1290 / 2003',
      beforeAlt: 'Dining room before renovation with original wallpaper and empty floors',
      afterAlt: 'Dining room after renovation with antique tapestry, dark walls, and layered lighting',
      d: 'The room kept its millwork, doors, and floors. Wall color, lighting, and furnishings were rebuilt around them so the architecture finally reads as the point of the room.',
    },
    {
      t: 'Light at the Bay Window', place: 'Spring Street', type: 'Renovation',
      before: './assets/ba-dining-2-before-fit.jpg', after: './assets/ba-dining-2-after-fit.jpg',
      ratio: '1207 / 1686',
      beforeAlt: 'Bay window dining room before renovation with dated wallpaper and bare windows',
      afterAlt: 'Bay window dining room after renovation with linen drapery, sconce, and tapestry',
      d: 'Drapery, a wall sconce, and a deeper wall tone turned a bright, bare corner into the warmest seat at the table.',
    },
    {
      t: 'A Kitchen Worth Standing In', place: 'Spring Street', type: 'Kitchen',
      before: './assets/ba-kitchen-before-fit.jpg', after: './assets/ba-kitchen-after-fit.jpg',
      ratio: '1021 / 1540',
      beforeAlt: 'Kitchen before renovation with white laminate cabinets and bare subfloor',
      afterAlt: 'Kitchen after renovation with stained wood cabinetry, marble counters, brass fixtures, and checkerboard tile floor',
      d: 'New cabinetry, marble surfaces, open shelving, and a checkerboard floor gave the room the character the house always implied.',
    },
    {
      t: 'Galley Kitchen, Rebuilt in Character', place: 'Spring Street', type: 'Kitchen',
      before: './assets/ba-kitchen-2-before-fit.jpg', after: './assets/ba-kitchen-2-after-fit.jpg',
      ratio: '1600 / 2235',
      beforeAlt: 'Kitchen before renovation with navy base cabinets, yellow walls, and white laminate counters',
      afterAlt: 'Kitchen after renovation with greige cabinetry, marble counters and backsplash, brass fixtures, and marble tile floor',
      d: 'Cabinetry was rebuilt with full crown and paneling, marble replaced laminate, and brass lighting and a farmhouse sink set the tone. A freestanding walnut island keeps the plan reading like furniture, not fixtures.',
    },
    {
      t: 'Under-Stair Closet, Fully Fitted', place: 'Spring Street', type: 'Storage',
      before: './assets/ba-closet-before-fit.jpg', after: './assets/ba-closet-after-fit.jpg',
      ratio: '1200 / 1600',
      beforeAlt: 'Closet before renovation with exposed sheathing, a single rod, and an unfinished sloped ceiling',
      afterAlt: 'Closet after renovation with built-in shelving, double hanging rods, and finished painted walls under the stair slope',
      d: 'The awkward slope became the plan. Built-in shelving, double rods, and finished surfaces turned a raw cavity into usable storage without moving a wall.',
    },
  ];
  const trackSet = (e) => {
    const r = e.currentTarget.getBoundingClientRect();
    setReveal(Math.max(0, Math.min(100, ((e.clientX - r.left) / r.width) * 100)));
  };

  const projects = [
    {
      t: 'A Craftsman Renewed', place: 'Hillcrest', type: 'Whole-home', tone: 'oak', feature: true,
      problem: 'A closed-off kitchen, no usable entry, and a family avoiding half their own house.',
      d: 'Original millwork and proportions retained while the kitchen, baths, and circulation were reworked for how the family actually lives.',
      outcome: 'Mornings now start in the room they used to walk past.',
      facts: [['Scope', 'Whole-home renovation'], ['Era', 'Craftsman, c. 1924'], ['Preserved', 'Millwork, stair, windows']],
    },
    {
      t: 'Light Through Oak', place: 'The Heights', type: 'Kitchen', tone: 'linen',
      problem: 'Two years of collected ideas and no way to tell what the project should cost.',
      d: 'A quieter material palette lets the cabinetry and architecture carry the room.',
      outcome: 'Every dollar went to daylight, storage, and surfaces that will last.',
      facts: [['Scope', 'Kitchen & butler’s pantry'], ['Materials', 'Rift-sawn oak, limestone']],
    },
    {
      t: 'The Quiet Study', place: 'Quapaw Quarter', type: 'Addition', tone: 'walnut',
      problem: 'Nowhere to work from home without taking a room from someone else.',
      d: 'A small addition that reads as though it had always been part of the house.',
      outcome: 'A door that closes, and a facade nobody can tell was changed.',
      facts: [['Scope', 'Addition & millwork'], ['Materials', 'Walnut, plaster, brass']],
    },
    {
      t: 'Threshold & Passage', place: 'Little Rock', type: 'Renovation', tone: 'oak',
      problem: 'Guests arrived into a dark hallway stacked with coats and shoes.',
      d: 'Entry, hall, and stair reconsidered as the sequence that sets the tone for the whole home.',
      outcome: 'The house now introduces itself properly.',
      facts: [['Scope', 'Entry, hall, stair'], ['Preserved', 'Original floors']],
    },
  ];

  const showFilter = false;
  const types = ['All', 'Whole-home', 'Kitchen', 'Addition', 'Renovation'];
  const shown = filter === 'All' ? projects : projects.filter((p) => p.type === filter);
  const feature = shown.find((p) => p.feature) || shown[0];
  const rest = shown.filter((p) => p !== feature);

  return (
    <div>
      <PageHeader
        align="center"
        video="./assets/hero-home.mp4" position="center 55%"
        eyebrow="Portfolio"
        title="Selected work." />

      {/* Filter — hidden for now; flip showFilter to true to bring it back. */}
      <section style={{ padding: 'var(--space-8) var(--gutter) var(--space-7)', maxWidth: 'var(--page-max)', margin: '0 auto' }}>
        <div style={{ display: 'flex', gap: '30px', flexWrap: 'wrap', justifyContent: 'center', visibility: showFilter ? 'visible' : 'hidden' }}>
          {types.map((t) => (
            <button key={t} onClick={() => setFilter(t)} style={{
              fontFamily: 'var(--font-sans)', fontSize: '11px', fontWeight: 500,
              letterSpacing: '.22em', textTransform: 'uppercase',
              padding: '6px 2px', cursor: 'pointer', background: 'transparent',
              border: 'none',
              borderBottom: `1px solid ${filter === t ? 'var(--oxblood)' : 'transparent'}`,
              color: filter === t ? 'var(--oxblood)' : 'var(--text-muted)',
              transition: 'color var(--dur-base) var(--ease-quiet)',
            }}>{t}</button>
          ))}
        </div>
      </section>

      {/* Project groups */}
      {groups.map((g, gi) => {
        const idx = shotIdx[gi] ?? g.start ?? 0;
        const set = (n) => setShotIdx((s) => ({ ...s, [gi]: (n + g.shots.length) % g.shots.length }));
        const shot = g.shots[idx];
        const flip = gi % 2 === 1;
        return (
          <section key={g.t} style={{ padding: '0 var(--gutter) var(--space-9)', maxWidth: 'var(--page-max)', margin: '0 auto' }}>
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 'var(--space-8)', alignItems: 'flex-start' }}>
              <div style={{ order: flip ? 2 : 1, flex: '1.7 1 340px', minWidth: 0, maxWidth: g.ratio === '3 / 4' ? '440px' : 'none' }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: '14px', marginBottom: '14px' }}>
                  <span style={{ fontFamily: 'var(--font-sans)', fontSize: '11px', fontWeight: 600, letterSpacing: '.22em', color: 'var(--oxblood)' }}>{String(gi + 1).padStart(2, '0')}</span>
                  <span style={{ flex: '0 0 auto', width: '48px', height: '1px', background: 'var(--line-soft)' }}></span>
                  <span style={{ flex: 1 }}></span>
                  <span style={{ fontFamily: 'var(--font-sans)', fontSize: '10px', fontWeight: 600, letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{g.type} · {g.place}</span>
                </div>
                <div style={{ position: 'relative' }}>
                  <Photo image={shot.src} alt={shot.alt} ratio={g.ratio} position="center" />
                  {[['\u2190', -1, { left: '18px' }], ['\u2192', 1, { right: '18px' }]].map(([glyph, dir, pos]) => (
                    <button key={glyph} type="button" aria-label={dir === -1 ? 'Previous photo' : 'Next photo'}
                      onClick={() => set(idx + dir)}
                      style={{ position: 'absolute', top: '50%', transform: 'translateY(-50%)', ...pos, width: '42px', height: '42px', borderRadius: '50%', border: '1px solid rgba(244,240,230,.6)', background: 'rgba(43,33,27,.34)', color: 'var(--ivory)', fontSize: '14px', lineHeight: 1, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{glyph}</button>
                  ))}
                </div>
                <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '16px', marginTop: '14px' }}>
                  <span style={{ fontFamily: 'var(--font-sans)', fontSize: '10px', fontWeight: 600, letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{shot.label}</span>
                  <div style={{ display: 'flex', gap: '8px' }}>
                    {g.shots.map((s, i) => (
                      <button key={s.src} type="button" aria-label={`${s.label} photo ${i + 1}`} onClick={() => set(i)}
                        style={{ width: '44px', height: '44px', padding: 0, cursor: 'pointer', border: `1px solid ${i === idx ? 'var(--oxblood)' : 'var(--line-soft)'}`, background: `url(${s.src}) center/cover`, opacity: i === idx ? 1 : .6 }}></button>
                    ))}
                  </div>
                </div>
              </div>

              <div style={{ order: flip ? 1 : 2, flex: '1 1 260px', minWidth: 0, maxWidth: '38ch' }}>
                <div aria-hidden style={{ display: 'flex', alignItems: 'center', marginBottom: '14px', visibility: 'hidden' }}>
                  <span style={{ fontFamily: 'var(--font-sans)', fontSize: '11px', fontWeight: 600, letterSpacing: '.22em' }}>00</span>
                </div>
                <h2 style={{ fontSize: 'clamp(1.45rem, 2.1vw, 1.85rem)', fontWeight: 400, margin: '0 0 16px', lineHeight: 1.2 }}>{g.t}</h2>
                {g.problem && <p style={{ fontFamily: 'var(--font-display)', fontSize: '1rem', color: 'var(--text-primary)', margin: '0 0 14px', lineHeight: 1.55 }}>{g.problem}</p>}
                <p style={{ fontSize: 'var(--fs-small)', color: 'var(--text-secondary)', margin: 0, lineHeight: 1.7 }}>{g.d}</p>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px 28px', marginTop: '26px', paddingTop: '20px', borderTop: '1px solid var(--line-soft)' }}>
                  {g.facts.map(([k, v]) => (
                    <div key={k} style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}>
                      <span style={{ fontFamily: 'var(--font-sans)', fontSize: '10px', fontWeight: 600, letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{k}</span>
                      <span style={{ fontSize: 'var(--fs-small)', color: 'var(--text-primary)' }}>{v}</span>
                    </div>
                  ))}
                </div>
              </div>
            </div>
          </section>
        );
      })}

      {/* Before / after + in progress, split */}
      <section style={{ padding: '0 var(--gutter) var(--space-9)', maxWidth: 'var(--page-max)', margin: '0 auto' }}>
        <div style={{ marginBottom: 'var(--space-7)' }}><Divider label="Before & After" /></div>
        <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', gap: 'var(--space-8)', alignItems: 'center' }}>
          {(() => {
            const p = pairs[slide % pairs.length];
            return (
              <div>
                <div
                  onPointerDown={(e) => { setDragging(true); trackSet(e); }}
                  onPointerMove={(e) => { if (dragging) trackSet(e); }}
                  onPointerUp={() => setDragging(false)}
                  onPointerLeave={() => setDragging(false)}
                  style={{ position: 'relative', width: '100%', maxWidth: '420px', margin: '0 auto', aspectRatio: '1290 / 2003', overflow: 'hidden', cursor: 'ew-resize', userSelect: 'none', touchAction: 'none', background: 'var(--parchment)' }}>
                  <img src={p.after} alt={p.afterAlt} draggable="false" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
                  <div style={{ position: 'absolute', inset: 0, clipPath: `inset(0 ${100 - reveal}% 0 0)` }}>
                    <img src={p.before} alt={p.beforeAlt} draggable="false" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
                  </div>
                  <div aria-hidden style={{ position: 'absolute', top: 0, bottom: 0, left: `${reveal}%`, width: '1px', background: 'var(--ivory)' }}>
                    <span style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: '40px', height: '40px', border: '1px solid var(--ivory)', borderRadius: '50%', background: 'rgba(43,33,27,.34)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--ivory)', fontSize: '12px' }}>&#8596;</span>
                  </div>
                  <span style={{ position: 'absolute', top: '14px', left: '14px', fontFamily: 'var(--font-sans)', fontSize: '10px', fontWeight: 600, letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--ivory)', background: 'rgba(43,33,27,.55)', padding: '5px 9px' }}>Before</span>
                  <span style={{ position: 'absolute', top: '14px', right: '14px', fontFamily: 'var(--font-sans)', fontSize: '10px', fontWeight: 600, letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--ivory)', background: 'rgba(43,33,27,.55)', padding: '5px 9px' }}>After</span>
                </div>

                <input type="range" min="0" max="100" value={reveal} aria-label="Reveal before and after"
                  onChange={(e) => setReveal(Number(e.target.value))}
                  style={{ display: 'block', width: '100%', maxWidth: '420px', margin: '12px auto 0', accentColor: 'var(--oxblood)' }} />

                <div style={{ maxWidth: '420px', margin: '16px auto 0', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                  <div style={{ display: 'flex', gap: '8px' }}>
                    {pairs.map((r, i) => (
                      <button key={r.t} type="button" aria-label={r.t}
                        onClick={() => { setSlide(i); setReveal(50); }}
                        style={{ width: '26px', height: '2px', border: 'none', padding: 0, cursor: 'pointer', background: i === slide % pairs.length ? 'var(--oxblood)' : 'var(--border-strong)' }}></button>
                    ))}
                  </div>
                  <div style={{ display: 'flex', gap: '10px' }}>
                    {[['\u2190', -1], ['\u2192', 1]].map(([glyph, dir]) => (
                      <button key={glyph} type="button" aria-label={dir === -1 ? 'Previous project' : 'Next project'}
                        onClick={() => { setSlide((c) => (c + dir + pairs.length) % pairs.length); setReveal(50); }}
                        style={{ width: '38px', height: '38px', border: '1px solid var(--border-strong)', background: 'transparent', cursor: 'pointer', color: 'var(--text-primary)', fontSize: '13px' }}>{glyph}</button>
                    ))}
                  </div>
                </div>
              </div>
            );
          })()}

          <div style={{ maxWidth: '46ch' }}>
            <Eyebrow>In Progress</Eyebrow>
            <h2 style={{ fontSize: 'var(--fs-h2)', fontWeight: 400, margin: '16px 0 18px' }}>More work underway.</h2>
            <p style={{ fontSize: 'var(--fs-body)', color: 'var(--text-secondary)', margin: '0 0 30px', lineHeight: 1.7 }}>
              Several projects are currently in design and construction. If you would like to see work that
              resembles what you are considering, we are glad to share it directly.
            </p>
            <Button variant="secondary" onClick={() => onNav('contact')}>Ask to See More</Button>
          </div>
        </div>
      </section>

      <InquiryBand eyebrow="Your Home" title="Let's talk about what yours could become." />
    </div>
  );
}
window.PortfolioPage = PortfolioPage;
