(() => {
const NS = window.VakantiehuisplatformDesignSystem_2f09bb;
const { Button, Icon, Stepper, CalendarMonth, PriceBlock, FormField, ErrorMessage } = NS;
const { VHContainer: Container, vhLabel } = window;
const u = k => window.VH_I18N.ui(k);
const eur = n => new Intl.NumberFormat('nl-NL', { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }).format(n);

function Counter({ label, sub, value, set, min = 0 }) {
  const b = { width: 44, height: 44, display: 'grid', placeItems: 'center', borderRadius: 'var(--radius-btn)', border: '1.5px solid var(--border)', background: 'var(--surface-card)', color: 'var(--text-1)', cursor: 'pointer' };
  return <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '12px 0', borderBottom: '1px solid var(--border)' }}>
    <div style={{ display: 'flex', flexDirection: 'column' }}><strong style={{ fontSize: 17 }}>{label}</strong><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{sub}</span></div>
    <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
      <button aria-label={label + ' minder'} style={{ ...b, opacity: value <= min ? .4 : 1 }} onClick={() => set(Math.max(min, value - 1))}><Icon name="minus" /></button>
      <span style={{ minWidth: 24, textAlign: 'center', fontWeight: 700, fontSize: 18 }}>{value}</span>
      <button aria-label={label + ' meer'} style={b} onClick={() => set(value + 1)}><Icon name="plus" /></button>
    </div>
  </div>;
}
function Card({ children, style }) {
  return <div style={{ padding: 24, background: 'var(--surface-card)', border: 'var(--border-card)', borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow-card)', display: 'flex', flexDirection: 'column', gap: 16, ...style }}>{children}</div>;
}
function PayMethod({ id, label, sub, sel, set }) {
  const on = sel === id;
  return <button role="radio" aria-checked={on} onClick={() => set(id)} style={{ display: 'flex', alignItems: 'center', gap: 14, minHeight: 64, padding: '0 16px', textAlign: 'left', borderRadius: 'var(--radius-md)', border: (on ? '2px solid var(--accent)' : '1.5px solid var(--border)'), background: on ? 'var(--accent-soft)' : 'var(--surface-card)', color: 'var(--text-1)', cursor: 'pointer' }}>
    <span style={{ width: 22, height: 22, borderRadius: 11, border: '2px solid ' + (on ? 'var(--accent)' : 'var(--border-strong)'), display: 'grid', placeItems: 'center' }}>{on && <span style={{ width: 10, height: 10, borderRadius: 5, background: 'var(--accent)' }}></span>}</span>
    <span style={{ display: 'flex', flexDirection: 'column' }}><strong style={{ fontSize: 17 }}>{label}</strong><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{sub}</span></span>
  </button>;
}
function BookingScreen({ m, n, house, onNav, unit }) {
  const U = window.VH_DATA.units[unit] || window.VH_DATA.units[Object.keys(window.VH_DATA.units)[0]];
  const vhS = window.vhS;
  const [step, setStep] = React.useState(0);
  const [range, setRange] = React.useState([13, 20]);
  const [adults, setAdults] = React.useState(Math.min(6, U.max - 2));
  const [kids, setKids] = React.useState(2);
  const [pay, setPay] = React.useState('ideal');
  const [err, setErr] = React.useState(false);
  const nights = range[1] - range[0];
  const guests = adults + kids;
  const lines = [{ label: nights + ' ' + u('nachten') + ' × ' + eur(U.top) + ' ' + vhS('peakLabel', '(krokus)'), amount: nights * U.top }, { label: u('Eindschoonmaak'), amount: U.clean }, { label: u('Toeristenbelasting') + ' (' + adults + ' × ' + nights + ' × € 3,50, ' + u('schatting') + ')', amount: Math.round(adults * nights * 3.5) }];
  const total = lines.reduce((s, l) => s + l.amount, 0);
  const pick = d => setRange(r => (r[1] && d > r[0] && d - r[0] <= 14) ? [r[0], d] : [d, d + 7]);
  const next = () => setStep(s => Math.min(4, s + 1));
  const L = window.VH_I18N.T(document.documentElement.lang), lg = document.documentElement.lang;
  const stayLine = range[0] + ' – ' + range[1] + ' ' + (lg === 'nl' || !lg ? L.feb.toLowerCase() : L.feb) + ' · ' + guests + ' ' + u('gasten') + (unit && house.units && house.units.length > 1 ? ' · ' + window.vhName(unit) : '');
  let body;
  if (step === 0) body = <><Card><h2 style={{ fontSize: 26 }}>{u('Wanneer kom je?')}</h2><CalendarMonth month={window.VH_I18N.T(document.documentElement.lang).feb} weekdays={window.VH_I18N.T(document.documentElement.lang).wd} startOffset={0} booked={[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]} range={range} onSelect={pick} /><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{window.vhS('changeNote', u('Wisseldag is zaterdag. Minimaal 7 nachten in het hoogseizoen.'))}</span></Card>
    <Card><h2 style={{ fontSize: 26 }}>{u('Met hoeveel ben je?')}</h2><div><Counter label={u('Volwassenen')} sub={u('18 jaar en ouder')} value={adults} set={v => setAdults(Math.min(v, U.max - kids))} min={1} /><Counter label={u('Kinderen')} sub={u('0 – 17 jaar')} value={kids} set={v => setKids(Math.min(v, U.max - adults))} /></div><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{vhS('maxNote', window.vhName(unit) + ': maximaal ' + U.max + ' gasten, kinderen meegeteld. In het hele huis zijn nooit meer dan 10 gasten tegelijk.')}</span></Card></>;
  if (step === 1) body = <Card><h2 style={{ fontSize: 26 }}>{u('Klopt dit?')}</h2>
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, fontSize: 17 }}>
      <span style={{ display: 'flex', gap: 10 }}><Icon name="calendar" />{stayLine}</span>
      <span style={{ display: 'flex', gap: 10 }}><Icon name="key-round" />{u('Aankomst vanaf 16:00, vertrek voor 10:00')}</span>
      <span style={{ display: 'flex', gap: 10 }}><Icon name="shield-check" />{u('Gratis annuleren tot 30 dagen voor aankomst')}</span>
    </div>
    <ErrorMessage variant="info" title={u('Geen extra kosten later')}>{u('Het totaal rechts is het totaal. Borg € 300 wordt niet afgeschreven, alleen gereserveerd.')}</ErrorMessage></Card>;
  if (step === 2) body = <Card><h2 style={{ fontSize: 26 }}>{u('Jouw gegevens')}</h2>
    <div style={{ display: 'grid', gridTemplateColumns: m ? '1fr' : '1fr 1fr', gap: 16 }}>
      <FormField label={u('Voornaam')} required autoComplete="given-name" defaultValue="Marieke" /><FormField label={u('Achternaam')} required autoComplete="family-name" defaultValue="van Dijk" />
      <FormField label={u('E-mailadres')} type="email" required hint={u('Hier sturen we je bevestiging naartoe.')} defaultValue="marieke@voorbeeld.nl" /><FormField label={u('Telefoon')} type="tel" required error={err ? u('Vul een telefoonnummer in, bijv. +31 6 12345678') : undefined} />
      <FormField label={u('Land')} as="select" required options={['Nederland', 'België', 'Duitsland', 'Oostenrijk', 'Anders']} /><FormField label={u('Verwachte aankomsttijd')} as="select" options={['16:00 – 18:00', '18:00 – 20:00', 'Na 20:00']} />
      <FormField label={u('Bericht aan de eigenaar')} as="textarea" style={{ gridColumn: '1 / -1' }} placeholder={u('Bijvoorbeeld: we nemen een kinderbedje mee')} />
    </div></Card>;
  if (step === 3) body = <Card><h2 style={{ fontSize: 26 }}>{u('Betalen')}</h2>
    <div role="radiogroup" aria-label="Betaalmethode" style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
      <PayMethod id="ideal" label="iDEAL" sub={u('Direct via je eigen bank')} sel={pay} set={setPay} />
      <PayMethod id="bancontact" label="Bancontact" sub={u('Voor Belgische rekeningen')} sel={pay} set={setPay} />
      <PayMethod id="card" label="Creditcard" sub="Visa, Mastercard, American Express" sel={pay} set={setPay} />
    </div>
    <span style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 16, color: 'var(--text-2)' }}><Icon name="lock" size={18} />{u('Veilig betalen via Mollie. Je betaalt nu 30% aanbetaling:')} {eur(Math.round(total * .3))}.</span></Card>;
  if (step === 4) body = <Card><ErrorMessage variant="success" title={u('Je boeking is bevestigd')}>{u('Boekingsnummer')} {vhS('bookingNo', 'TRB-2027-0213')}. {u('Je ontvangt binnen 5 minuten een e-mail.')}</ErrorMessage>
    <span style={{ fontSize: 17 }}>{stayLine}</span>
    <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}><Button icon="book-open" onClick={() => onNav('gastenmap')}>{u('Naar je gastenmap')}</Button><Button variant="secondary" onClick={() => onNav('gastomgeving')}>{u('Mijn boeking')}</Button></div>
    {window.VHTripShare && <window.VHTripShare house={house} dates={range[0] + ' – ' + range[1] + ' ' + (lg === 'nl' || !lg ? L.feb.toLowerCase() : L.feb)} photo="img/hero.jpg" />}</Card>;
  const cta = [u('Verder naar overzicht'), u('Verder naar gegevens'), u('Verder naar betalen'), u('Betaal') + ' ' + eur(Math.round(total * .3)), null][step];
  const onCta = () => { if (step === 2 && !err) { setErr(true); return; } setErr(false); next(); };
  return <div style={{ minHeight: '100%', background: 'var(--surface-page)', paddingBottom: m ? 140 : 80 }}>
    <div style={{ borderBottom: '1px solid var(--border)' }}><Container m={m} style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', minHeight: 64 }}>
      <button onClick={() => step ? setStep(step - 1) : onNav('home')} style={{ display: 'flex', alignItems: 'center', gap: 6, minHeight: 44, background: 'none', border: 0, color: 'var(--text-1)', cursor: 'pointer', fontSize: 16, fontWeight: 600 }}><Icon name="chevron-left" />{step ? u('Terug') : house.name}</button>
      <span style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 16, color: 'var(--text-2)' }}><Icon name="lock" size={16} />{u('Veilig boeken')}</span>
    </Container></div>
    <Container m={m} style={{ paddingTop: m ? 20 : 40 }}>
      <div style={{ marginBottom: m ? 20 : 40 }}><Stepper steps={u('steps')} current={step} compact={m} /></div>
      <div style={{ display: 'grid', gridTemplateColumns: m ? '1fr' : n ? 'minmax(0,1fr) 320px' : 'minmax(0,1fr) 380px', gap: 32, alignItems: 'start' }}>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>{body}
          {!m && cta && <div><Button size="lg" onClick={onCta} iconRight={step < 3 ? 'arrow-right' : 'lock'}>{cta}</Button></div>}
          {err && step === 2 && <ErrorMessage title={u('Nog 1 veld')}>{u('Vul je telefoonnummer in, dan kan de eigenaar je bereiken bij aankomst. Klik daarna opnieuw op verder.')}</ErrorMessage>}
        </div>
        {!m && <div style={{ position: 'sticky', top: 24, display: 'flex', flexDirection: 'column', gap: 12 }}>
          <span style={vhLabel}>{house.name}</span><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{stayLine}</span>
          <PriceBlock lines={lines} cta={null} totalLabel={u('Totaal')} />
        </div>}
      </div>
    </Container>
    {m && step < 4 && <div style={{ position: 'sticky', bottom: 0, marginTop: 24, background: 'var(--surface-card)', borderTop: '1px solid var(--border)', padding: '12px 20px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
      <span style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.25 }}><span style={{ fontSize: 16, color: 'var(--text-2)' }}>{u('Totaal incl. alles')}</span><strong style={{ fontSize: 20 }}>{eur(total)}</strong></span>
      <Button onClick={onCta}>{step === 3 ? u('Betaal') : u('Verder')}</Button>
    </div>}
  </div>;
}
window.VHBooking = BookingScreen;
})();
