// Detailpagina per appartement: foto's per ruimte, indeling, praktische info, prijs en beschikbaarheid.
(() => {
const NS = window.VakantiehuisplatformDesignSystem_2f09bb;
const { Button, Icon, Photo, PriceBlock, CalendarMonth, StickyBookBar, FeaturePill } = NS;
const { VHContainer: Container, VHSection: Section, VHSectionHead: SectionHead, VHHeader, VHFooter, vhLabel } = window;
const I = window.VH_I18N;
const MAIN = ['Boven groot', 'Beneden', 'Boven klein'];

function Gallery({ m, photos }) {
  const [i, setI] = React.useState(0);
  React.useEffect(() => setI(0), [photos]);
  const [f, alt] = photos[i];
  return <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
    <div style={{ position: 'relative' }}>
      <Photo src={'img/u/' + f + '.jpg'} alt={alt} ratio={m ? '4/3' : '16/9'} />
      <span style={{ position: 'absolute', left: 12, bottom: 12, padding: '4px 12px', borderRadius: 'var(--radius-pill)', background: 'rgba(14,14,12,.7)', color: '#fff', fontSize: 15 }}>{alt} · {i + 1}/{photos.length}</span>
      {[['chevron-left', -1, { left: 12 }], ['chevron-right', 1, { right: 12 }]].map(([ic, d, pos]) => <button key={ic} aria-label={d < 0 ? 'Vorige foto' : 'Volgende foto'} onClick={() => setI((i + d + photos.length) % photos.length)} style={{ position: 'absolute', top: '50%', transform: 'translateY(-50%)', ...pos, width: 44, height: 44, borderRadius: 22, border: 0, background: 'rgba(255,255,255,.9)', display: 'grid', placeItems: 'center', cursor: 'pointer', color: '#111' }}><Icon name={ic} size={22} /></button>)}
    </div>
    <div style={{ display: 'grid', gridTemplateColumns: m ? 'repeat(4,1fr)' : 'repeat(8,1fr)', gap: 6 }}>
      {photos.map(([pf, pa], k) => <button key={pf} onClick={() => setI(k)} aria-label={pa} aria-pressed={k === i} style={{ padding: 0, border: k === i ? '3px solid var(--accent)' : '3px solid transparent', borderRadius: 'var(--radius-sm)', overflow: 'hidden', cursor: 'pointer', background: 'none' }}><img src={'img/u/' + pf + '.jpg'} alt="" loading="lazy" style={{ display: 'block', width: '100%', aspectRatio: '1/1', objectFit: 'cover' }} /></button>)}
    </div>
  </div>;
}

function UnitScreen(p) {
  const { m, n, house, lang, setLang, onNav, unit, setUnit } = p;
  const k = MAIN.includes(unit) ? unit : 'Boven groot';
  const U = window.VH_DATA.units[k], INFO = window.VH_UNITINFO[k], D = I.unitD(lang, k, U), X = I.T(lang);
  const rooms = (window.VH_ROOMS || {})[k] || [];
  const name = window.vhName(k);
  const book = () => { if (window.vhTrack) window.vhTrack('cta_book', { unit: k }); setUnit(k); onNav('boeken'); };
  return <div>
    <VHHeader m={m} n={n} house={house} lang={lang} setLang={setLang} onNav={onNav} />
    <Container m={m} style={{ paddingTop: m ? 16 : 28 }}>
      <button onClick={() => onNav('home')} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, minHeight: 44, background: 'none', border: 0, padding: 0, color: 'var(--accent-text)', fontSize: 16, fontWeight: 600, cursor: 'pointer' }}><Icon name="arrow-left" size={18} />Alle appartementen</button>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 6, margin: '8px 0 20px' }}>
        <span style={vhLabel}>{INFO.where} · {X.upTo(U.max)}</span>
        <h1 style={{ fontSize: m ? 36 : 52, lineHeight: 1.05 }}>{name}</h1>
        {window.VHShareBar && <window.VHShareBar house={house} label={name + ' in ' + house.name} style={{ marginTop: 8 }} />}
      </div>
      <Gallery m={m} photos={INFO.photos} />
    </Container>
    <Section m={m} style={{ paddingTop: m ? 32 : 48 }}>
      <div style={{ display: 'grid', gridTemplateColumns: m ? '1fr' : n ? 'minmax(0,1fr) 320px' : 'minmax(0,1fr) 380px', gap: m ? 32 : 48, alignItems: 'start' }}>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 28 }}>
          <p style={{ fontSize: m ? 18 : 21, lineHeight: 1.6 }}>{INFO.intro}</p>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            <FeaturePill icon="users">{X.upTo(U.max)}</FeaturePill><FeaturePill icon="bed-double">{D.beds}</FeaturePill><FeaturePill icon="bath">{D.bath}</FeaturePill>
          </div>
          <div>
            <h2 style={{ fontSize: 26, marginBottom: 8 }}>Indeling</h2>
            {rooms.map(([r, v]) => <div key={r} style={{ display: 'flex', justifyContent: 'space-between', gap: 16, padding: '12px 0', borderBottom: '1px solid var(--border)', fontSize: 17 }}><span style={{ color: 'var(--text-2)' }}>{r}</span><strong style={{ textAlign: 'right' }}>{v}</strong></div>)}
            <div style={{ display: 'flex', justifyContent: 'space-between', gap: 16, padding: '12px 0', fontSize: 17 }}><span style={{ color: 'var(--text-2)' }}>Oppervlakte</span><span style={{ color: 'var(--text-2)' }}>volgt</span></div>
          </div>
          {window.VHRoomTour ? <window.VHRoomTour m={m} unit={k} /> : <div>
            <h2 style={{ fontSize: 26, marginBottom: 12 }}>De ruimtes</h2>
            <div style={{ display: 'grid', gridTemplateColumns: m ? '1fr 1fr' : 'repeat(3,1fr)', gap: 12 }}>
              {INFO.photos.map(([f, alt]) => <figure key={f} style={{ margin: 0, display: 'flex', flexDirection: 'column', gap: 6 }}><Photo src={'img/u/' + f + '.jpg'} alt={alt} ratio="4/3" /><figcaption style={{ fontSize: 15, color: 'var(--text-2)' }}>{alt}</figcaption></figure>)}
            </div>
          </div>}
          <div>
            <h2 style={{ fontSize: 26, marginBottom: 8 }}>Goed om te weten</h2>
            <p style={{ fontSize: 17, color: 'var(--text-2)' }}>{D.extra}. Keuken, wifi, wasmachine en de rest van de voorzieningen staan in het overzicht op de homepage.</p>
            <div style={{ marginTop: 12 }}><Button variant="secondary" iconRight="arrow-right" onClick={() => { onNav('home'); setTimeout(() => { const el = document.getElementById('praktisch'); if (el) el.scrollIntoView(); }, 100); }}>Alle voorzieningen</Button></div>
          </div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 16, position: m ? 'static' : 'sticky', top: 24 }}>
          <PriceBlock from={U.from} unit={X.night} note={X.note(U.max, U.top)} trust={X.trust} cta={'Boek ' + name} onCta={book} />
          <CalendarMonth month={X.feb} weekdays={X.wd} startOffset={0} booked={[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]} range={[13, 20]} />
        </div>
      </div>
    </Section>
    <Section m={m} alt>
      <SectionHead m={m} kicker="Ook in dit huis" title="De andere appartementen" />
      <div style={{ display: 'grid', gridTemplateColumns: m ? '1fr' : '1fr 1fr', gap: 16 }}>
        {MAIN.filter(x => x !== k).map(x => { const I2 = window.VH_UNITINFO[x]; const U2 = window.VH_DATA.units[x];
          return <button key={x} onClick={() => { setUnit(x); window.scrollTo(0, 0); }} style={{ display: 'grid', gridTemplateColumns: '120px 1fr', gap: 16, alignItems: 'center', padding: 12, textAlign: 'left', background: 'var(--surface-card)', border: 'var(--border-card)', borderRadius: 'var(--radius-lg)', cursor: 'pointer', color: 'var(--text-1)' }}>
            <img src={'img/u/' + I2.photos[0][0] + '.jpg'} alt="" loading="lazy" style={{ width: 120, aspectRatio: '4/3', objectFit: 'cover', borderRadius: 'var(--radius-md)' }} />
            <span style={{ display: 'flex', flexDirection: 'column', gap: 4 }}><strong style={{ fontSize: 20 }}>{window.vhName(x)}</strong><span style={{ fontSize: 15, color: 'var(--text-2)' }}>{X.upTo(U2.max)} · {X.fromN(U2.from)}</span></span>
          </button>; })}
      </div>
      <p style={{ fontSize: 16, color: 'var(--text-2)', marginTop: 16 }}>Met meer? Heuboden + Kammerl samen of het hele huis boek je via “Kies je week”, voor maximaal 10 gasten.</p>
    </Section>
    <VHFooter m={m} house={house} lang={lang} />
    {m && <StickyBookBar position="sticky" from={U.from} unit={X.nightS} cta={'Boek ' + name} onCta={book} />}
  </div>;
}
window.VHUnit = UnitScreen;
})();
