// TrafftBooking.jsx — patient-facing booking CTA + trust line (scheduling, not diagnosis).

function BookingTrustLine({ style }) {
  const text = window.BOOKING_TRUST_LINE
    || 'Schedule with the practice — confirm appointment details with the office.';
  return (
    <p className="t-fine disclosure" style={{ marginTop: 8, marginBottom: 0, ...style }}>
      {text}
    </p>
  );
}

function BookAppointmentCTA({ dentist, surface = 'directory', variant = 'primary', size = 'md', label = 'Book appointment', style, children }) {
  const d = dentist || {};
  const onBook = () => {
    if (typeof window.openTrafftBooking === 'function') {
      window.openTrafftBooking(d, { surface, provider: 'trafft' });
      return;
    }
    window.open(window.buildTrafftUrl(d), '_blank', 'noopener');
  };
  return (
    <div style={style}>
      <Button variant={variant} size={size} style={{ width: '100%' }} onClick={onBook}>
        {children || label}
      </Button>
      <BookingTrustLine />
    </div>
  );
}

Object.assign(window, { BookingTrustLine, BookAppointmentCTA });
