// legal-pages.jsx — Privacy / Terms / Cookies pages.
//
// The Privacy Policy is a real policy: it has to disclose how we use Google
// Calendar data (per Google's API Services User Data Policy / Limited Use
// requirements) for the OAuth app's verification. Terms / Cookies are lighter
// but accurate. Reachable at #privacy / #terms / #cookies and linked from the
// footer.

const LEGAL_LAST_UPDATED = 'May 2026';

const LegalShell = ({ title, kicker, children, setPage }) => (
  <div style={{ background: 'oklch(98% 0.008 60)', minHeight: '100vh', paddingTop: 140, paddingBottom: 80, fontFamily: "'Plus Jakarta Sans', sans-serif" }}>
    <section style={{ maxWidth: 760, margin: '0 auto', padding: '0 32px' }}>
      <p style={{ fontSize: 12, fontWeight: 700, letterSpacing: '0.14em', color: 'oklch(72% 0.17 80)', textTransform: 'uppercase', marginBottom: 12 }}>{kicker}</p>
      <h1 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 'clamp(32px, 4vw, 46px)', fontWeight: 600, color: 'oklch(22% 0.06 265)', lineHeight: 1.15, marginBottom: 12 }}>
        {title}
      </h1>
      <div style={{ fontSize: 13, color: 'oklch(55% 0.03 265)', marginBottom: 36 }}>Last updated: {LEGAL_LAST_UPDATED}</div>
      <div style={{ fontSize: 15, lineHeight: 1.75, color: 'oklch(30% 0.04 265)' }}>
        {children}
      </div>
      <button onClick={() => setPage('home')}
        style={{ marginTop: 48, background: 'transparent', color: 'oklch(22% 0.06 265)', border: '1.5px solid oklch(82% 0.04 265)', borderRadius: 10, padding: '10px 22px', fontWeight: 600, fontSize: 14, cursor: 'pointer', fontFamily: "'Plus Jakarta Sans', sans-serif" }}>
        ← Back to home
      </button>
    </section>
  </div>
);

const LegalSection = ({ heading, children }) => (
  <div style={{ marginBottom: 28 }}>
    <h2 style={{ fontSize: 18, fontWeight: 700, color: 'oklch(22% 0.06 265)', marginBottom: 10 }}>{heading}</h2>
    <div>{children}</div>
  </div>
);

const PrivacyPage = ({ setPage }) => (
  <LegalShell title="Privacy Policy" kicker="Coaching legal" setPage={setPage}>
    <p>Coaching ("we", "us"), operated by The Music Mastery at coachingforall.co, connects students with private-lesson instructors. This policy explains what we collect, how we use it, and the choices you have. Questions: <a href="mailto:hello@themusicmastery.com">hello@themusicmastery.com</a>.</p>
    <LegalSection heading="What we collect">
      <p>Account info you provide (name, email, optional phone and address), lesson activity (bookings, attendance, payments), and basic device/usage data so the site stays fast and secure.</p>
    </LegalSection>
    <LegalSection heading="How we use it">
      <p>To run lessons (matching students with instructors, scheduling, billing), to communicate with you about your account, and to improve the product. We do not sell personal data and we do not use it for advertising.</p>
    </LegalSection>
    <LegalSection heading="Google Calendar data">
      <p>Connecting a Google Calendar is optional and only available to instructors. If an instructor connects one, we request Google's Calendar "events" permission and use it for a single purpose: keeping their schedule in sync. We read their Google Calendar events so that time shows as busy on Coaching, and we write the lessons and time-blocks they create on Coaching back to their Google Calendar.</p>
      <p>We store an encrypted Google authorisation token (so the sync can run) plus the dates and titles of synced events. We never sell or share Google Calendar data, never use it for advertising, and never use it to train AI or machine-learning models. The sync is automated; a person only views this data at the instructor's explicit request (e.g. support), to comply with the law, or to keep the service secure.</p>
      <p>Coaching's use and transfer of information received from Google APIs adheres to the <a href="https://developers.google.com/terms/api-services-user-data-policy" target="_blank" rel="noopener noreferrer">Google API Services User Data Policy</a>, including the Limited Use requirements.</p>
      <p>An instructor can disconnect at any time from Settings on Coaching, or by removing access at <a href="https://myaccount.google.com/permissions" target="_blank" rel="noopener noreferrer">myaccount.google.com/permissions</a>. Disconnecting stops all future sync.</p>
    </LegalSection>
    <LegalSection heading="Who we share it with">
      <p>Service providers required to operate the platform (auth + database via Supabase, hosting via Vercel, email delivery, payments). Each is bound by their own contracts and only sees what they need. We do not sell personal data.</p>
    </LegalSection>
    <LegalSection heading="Your choices">
      <p>You can request a copy of your data, correct it, disconnect a connected Google Calendar, or have your account deleted by emailing us. We honour valid requests within 30 days.</p>
    </LegalSection>
    <LegalSection heading="Contact">
      <p><a href="mailto:hello@themusicmastery.com">hello@themusicmastery.com</a></p>
    </LegalSection>
  </LegalShell>
);

const TermsPage = ({ setPage }) => (
  <LegalShell title="Terms of Service" kicker="Coaching legal" setPage={setPage}>
    <p>By using Coaching you agree to these terms. They cover both students booking lessons and instructors offering them.</p>
    <LegalSection heading="Your account">
      <p>Keep your login credentials private. You're responsible for activity on your account. Don't share or sell access.</p>
    </LegalSection>
    <LegalSection heading="Lessons and payments">
      <p>Lessons are arranged between students and instructors through the platform. Payments are processed via the methods we support and become final once a lesson is marked completed. Cancellation rules are shown at booking time.</p>
    </LegalSection>
    <LegalSection heading="Acceptable use">
      <p>No harassment, no impersonation, no illegal content, no automated scraping. We may suspend accounts that break these rules.</p>
    </LegalSection>
    <LegalSection heading="Liability">
      <p>The service is provided "as is". To the extent permitted by law, we're not liable for indirect or consequential damages. Your statutory rights as a consumer aren't affected.</p>
    </LegalSection>
    <LegalSection heading="Changes">
      <p>We may update these terms. Material changes will be announced by email or in-app. Continued use after changes means you accept the new terms.</p>
    </LegalSection>
    <LegalSection heading="Contact">
      <p><a href="mailto:hello@themusicmastery.com">hello@themusicmastery.com</a></p>
    </LegalSection>
  </LegalShell>
);

const CookiesPage = ({ setPage }) => (
  <LegalShell title="Cookie Policy" kicker="Coaching legal" setPage={setPage}>
    <p>This page explains the cookies and similar storage Coaching uses.</p>
    <LegalSection heading="Essential">
      <p>We use <code>localStorage</code> to keep you signed in across page refreshes (Supabase auth session). Without it, you'd be logged out every time you reload.</p>
    </LegalSection>
    <LegalSection heading="Analytics">
      <p>We don't currently load any third-party analytics or advertising trackers on this site. If that changes, we'll update this page and ask for your consent where required.</p>
    </LegalSection>
    <LegalSection heading="Your choices">
      <p>You can clear local storage at any time from your browser settings. Doing so will sign you out of Coaching.</p>
    </LegalSection>
    <LegalSection heading="Contact">
      <p><a href="mailto:hello@themusicmastery.com">hello@themusicmastery.com</a></p>
    </LegalSection>
  </LegalShell>
);

Object.assign(window, { PrivacyPage, TermsPage, CookiesPage });
