// Legal screens — Privacy Policy + Terms of Service
// v=1

function LegalScreen({ title, kicker, children, app }) {
  return (
    <div style={{
      width: '100%', height: '100%', background: '#fff',
      display: 'flex', flexDirection: 'column', overflowY: 'hidden',
    }}>
      {/* Header */}
      <div style={{
        padding: '20px 24px 16px',
        borderBottom: `1.5px solid ${GL.line}`,
        display: 'flex', alignItems: 'center', gap: 12, flexShrink: 0,
      }}>
        <button onClick={() => app.back()} style={{
          width: 36, height: 36, border: `1.5px solid ${GL.ink}`,
          background: 'none', cursor: 'pointer',
          display: 'grid', placeItems: 'center', flexShrink: 0,
        }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none"
               stroke={GL.ink} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
            <path d="M19 12H5M12 19l-7-7 7-7"/>
          </svg>
        </button>
        <div>
          <div className="gl-mono" style={{ fontSize: 9, letterSpacing: '0.25em', color: GL.muted, textTransform: 'uppercase', marginBottom: 2 }}>
            {kicker}
          </div>
          <div className="gl-display" style={{ fontSize: 18, color: GL.ink, lineHeight: 1 }}>{title}</div>
        </div>
      </div>

      {/* Scrollable content */}
      <div className="gl-scrollable" style={{
        flex: 1, overflowY: 'auto', padding: '28px 24px 48px',
      }}>
        {children}
      </div>
    </div>
  );
}

// ── Typography helpers ──────────────────────────────────────────────────────
function LH2({ children }) {
  return (
    <div className="gl-display" style={{
      fontSize: 15, color: GL.ink, letterSpacing: '0.06em',
      textTransform: 'uppercase', marginTop: 28, marginBottom: 10,
      paddingBottom: 8, borderBottom: `1.5px solid ${GL.line}`,
    }}>{children}</div>
  );
}
function LP({ children, style = {} }) {
  return (
    <p style={{
      fontSize: 13, lineHeight: 1.75, color: '#333', margin: '0 0 10px',
      fontFamily: 'Inter, system-ui, sans-serif',
      ...style,
    }}>{children}</p>
  );
}
function LTable({ rows }) {
  return (
    <div style={{
      border: `1.5px solid ${GL.line}`, marginBottom: 12, overflowX: 'auto',
    }}>
      <table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 12, fontFamily: 'Inter, system-ui, sans-serif' }}>
        <thead>
          <tr style={{ background: GL.ink }}>
            {rows[0].map((h, i) => (
              <th key={i} style={{
                padding: '8px 12px', color: '#fff', textAlign: 'left',
                fontWeight: 700, letterSpacing: '0.06em', fontSize: 11,
                textTransform: 'uppercase',
              }}>{h}</th>
            ))}
          </tr>
        </thead>
        <tbody>
          {rows.slice(1).map((row, ri) => (
            <tr key={ri} style={{ borderTop: `1px solid ${GL.line}`, background: ri % 2 === 0 ? '#fff' : '#F8FAFA' }}>
              {row.map((cell, ci) => (
                <td key={ci} style={{ padding: '8px 12px', color: '#333', verticalAlign: 'top', lineHeight: 1.5 }}>{cell}</td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}
function LBullet({ items }) {
  return (
    <ul style={{ margin: '0 0 12px', paddingLeft: 18 }}>
      {items.map((item, i) => (
        <li key={i} style={{ fontSize: 13, lineHeight: 1.75, color: '#333', marginBottom: 4, fontFamily: 'Inter, system-ui, sans-serif' }}>
          {item}
        </li>
      ))}
    </ul>
  );
}

// ── Privacy Policy ──────────────────────────────────────────────────────────
function GLPrivacyPolicy({ app }) {
  return (
    <LegalScreen title="Privacy Policy" kicker="Gustai Hospitality Group" app={app}>

      <div style={{ marginBottom: 20, padding: '10px 14px', background: '#F8FAFA', border: `1.5px solid ${GL.line}` }}>
        <div className="gl-mono" style={{ fontSize: 10, color: GL.muted, letterSpacing: '0.15em' }}>
          EFFECTIVE DATE — APRIL 21, 2026
        </div>
      </div>

      <LP>
        This policy explains how Gustai Hospitality Group Co., LTD ("we," "us," or "our") collects,
        uses, and protects your personal data in compliance with Thailand's Personal Data Protection Act
        B.E. 2562 (PDPA).
      </LP>

      <LH2>1. Data We Collect</LH2>
      <LTable rows={[
        ['Data', 'Why'],
        ['Email address', 'Account creation and OTP verification'],
        ['Display name', 'Personalising your orders'],
        ['Delivery address', 'Fulfilling your orders'],
        ['Order history', 'Service delivery, customer support'],
        ['Facebook / Google account ID', 'Authentication and account creation'],
        ['WhatsApp number', 'Order updates (optional, if provided)'],
        ['Device / app usage data', 'Improving the app experience'],
      ]}/>
      <LP style={{ fontSize: 12, color: GL.muted }}>
        We do not collect passwords or government ID numbers.
      </LP>

      <LH2>2. Legal Basis for Processing</LH2>
      <LP>We process your data under the following PDPA lawful bases:</LP>
      <LBullet items={[
        'Contract: To fulfil your orders and subscriptions.',
        'Consent: To send marketing messages (see Section 4).',
        'Legitimate Interest: To prevent fraud and improve our service.',
      ]}/>

      <LH2>3. How We Use Your Data</LH2>
      <LBullet items={[
        'Sending your OTP verification code via Email.',
        'Confirming and updating you on your orders.',
        'Processing payments.',
        'Managing your subscription.',
        'Improving our app and service quality.',
        'Sending you marketing messages only if you have opted in.',
      ]}/>

      <LH2>4. Marketing Consent</LH2>
      <LP>
        By ticking the consent box at registration, you agree to receive:
      </LP>
      <LBullet items={[
        'New product announcements ("The Drop" alerts).',
        'Promotions, discounts, and limited edition releases.',
        'Personalised recommendations based on your order history via WhatsApp or Email.',
      ]}/>
      <LP>
        <strong>Opt-out:</strong> You can opt out at any time exclusively through the app by toggling
        notifications off in your profile settings. Opting out of marketing does not affect essential
        order notifications.
      </LP>

      <LH2>5. Data Sharing</LH2>
      <LP>We do not sell your data. We share it only with:</LP>
      <LBullet items={[
        'Payment Processors (e.g., PromptPay) for transaction processing.',
        'Delivery Partners: Name, phone number and address only, for fulfilment.',
        'Cloud Infrastructure (Supabase / Hostinger) for secure data storage.',
        'Authorities: If required by Thai law.',
      ]}/>

      <LH2>6. Data Retention</LH2>
      <LTable rows={[
        ['Data type', 'Retention period'],
        ['Account data', 'Until you delete your account + 1 year'],
        ['Order records', '5 years (Thai tax law requirement)'],
        ['OTP codes', 'Deleted within 5 minutes of use'],
        ['Marketing opt-in record', 'Until you withdraw consent + 3 years'],
      ]}/>

      <LH2>7. Your Rights Under PDPA</LH2>
      <LP>You have the right to:</LP>
      <LBullet items={[
        'Access your personal data',
        'Rectify inaccurate data',
        'Erase your data ("right to be forgotten")',
        'Withdraw consent at any time',
        'Data portability',
        'Lodge a complaint with Thailand\'s PDPC',
      ]}/>

      <LH2>8. Security</LH2>
      <LP>
        We use encrypted connections (TLS), hashed OTP codes, and role-based access controls.
        Staff access to customer data is logged and audited.
      </LP>

      <LH2>9. Children</LH2>
      <LP>
        Our service is not intended for users under 18. We do not knowingly collect data from minors.
      </LP>

      <LH2>10. Changes</LH2>
      <LP>
        We will notify you of material changes via WhatsApp or Email at least 7 days in advance.
      </LP>

      <LH2>11. Contact</LH2>
      <LP>For questions or to exercise your rights, contact our Data Protection representative:</LP>
      <div style={{
        background: '#F8FAFA', border: `1.5px solid ${GL.line}`,
        padding: '14px 16px', fontSize: 13, lineHeight: 1.8, color: '#333',
        fontFamily: 'Inter, system-ui, sans-serif',
      }}>
        <strong>Gustai Hospitality Group Co., LTD</strong><br/>
        2/106, Village No. 2, Kathu Subdistrict,<br/>
        Kathu District, Phuket Province. 83120. Thailand<br/>
        <strong>Email:</strong> privacy@gustai.co<br/>
        <strong>Website:</strong> lab.gustai.co
      </div>

    </LegalScreen>
  );
}

// ── Terms of Service ────────────────────────────────────────────────────────
function GLTerms({ app }) {
  return (
    <LegalScreen title="Terms of Service" kicker="Gustai Hospitality Group" app={app}>

      <div style={{ marginBottom: 20, padding: '10px 14px', background: '#F8FAFA', border: `1.5px solid ${GL.line}` }}>
        <div className="gl-mono" style={{ fontSize: 10, color: GL.muted, letterSpacing: '0.15em', lineHeight: 1.8 }}>
          EFFECTIVE DATE — APRIL 21, 2026{'\n'}
          OPERATOR — GUSTAI HOSPITALITY GROUP CO., LTD{'\n'}
          DBD 0835567003547
        </div>
      </div>

      <LH2>1. Who We Are</LH2>
      <LP>
        Gustai Lab is a fresh pasta brand based in Kathu, Phuket, Thailand. These Terms govern your
        use of our app, website, and ordering services.
      </LP>

      <LH2>2. Your Account</LH2>
      <LP>
        You sign in using your Google account, Facebook account, or email address. If using email,
        we send a one-time verification code — no password required.
      </LP>
      <LBullet items={[
        'You must be 18 or older, or have parental consent.',
        'You are responsible for keeping your account secure.',
        'Notify us immediately if you believe someone else has accessed your account.',
      ]}/>

      <LH2>3. Orders & Payment</LH2>
      <LBullet items={[
        'Prices are in Thai Baht (THB) and include VAT where applicable.',
        'Orders are confirmed once you receive an order confirmation via Email or WhatsApp.',
        'We reserve the right to cancel any order we cannot fulfil (e.g. sold out, delivery area unavailable). You will receive a full refund or credit.',
        'Payment methods accepted: cash on delivery, PromptPay QR, or credit/debit card.',
      ]}/>

      <LH2>4. Delivery</LH2>
      <LBullet items={[
        'We deliver to selected areas in Phuket. Coverage is shown at checkout.',
        'Delivery slots are estimated, not guaranteed. Factors outside our control (traffic, weather) may cause delays.',
        'If you are not available at delivery, we will contact you via WhatsApp or Email. Unclaimed orders are not refunded unless we are at fault.',
      ]}/>

      <LH2>5. The Drop — Subscription Service</LH2>
      <LBullet items={[
        'Subscribing to "The Drop" means you agree to a recurring weekly or bi-weekly order at the agreed price.',
        'You may pause or cancel at any time via the app with no penalty, provided you do so before your next billing cycle closes (stated clearly in the app).',
        'Subscription discounts (e.g. 15% off) apply only while your subscription is active.',
      ]}/>

      <LH2>6. Food Safety & Allergens</LH2>
      <LP>
        Our products contain <strong>wheat</strong> and <strong>eggs</strong>, and may contain
        traces of <strong>nuts</strong> and <strong>dairy</strong>.
      </LP>
      <LP>
        Products are fresh and perishable. Follow storage and cooking instructions provided.
        We are not liable for illness resulting from improper storage or handling after delivery.
      </LP>

      <LH2>7. Refunds & Complaints</LH2>
      <LBullet items={[
        'Contact us within 24 hours of delivery for issues with product quality (photo evidence helps).',
        'Approved refunds are issued within 5 business days to your original payment method, or as store credit at our discretion.',
        'We do not accept returns of perishable food items.',
      ]}/>

      <LH2>8. Acceptable Use</LH2>
      <LP>You agree not to:</LP>
      <LBullet items={[
        'Use the app for any unlawful purpose.',
        'Create multiple accounts to abuse promotions.',
        'Attempt to reverse-engineer, scrape, or damage the app or its services.',
      ]}/>

      <LH2>9. Intellectual Property</LH2>
      <LP>
        All content, branding, recipes, photography, and text are owned by Gustai Lab.
        You may not reproduce or use them without our written permission.
      </LP>

      <LH2>10. Limitation of Liability</LH2>
      <LP>
        To the fullest extent permitted under Thai law, Gustai Lab is not liable for indirect,
        incidental, or consequential damages arising from your use of our services.
      </LP>

      <LH2>11. Changes to These Terms</LH2>
      <LP>
        We may update these Terms. We will notify you via Email or WhatsApp at least 7 days before
        material changes take effect. Continued use of the service after that date constitutes acceptance.
      </LP>

      <LH2>12. Governing Law</LH2>
      <LP>
        These Terms are governed by the laws of the Kingdom of Thailand. Any disputes shall be
        resolved in the courts of Phuket Province.
      </LP>

      <LH2>13. Contact</LH2>
      <div style={{
        background: '#F8FAFA', border: `1.5px solid ${GL.line}`,
        padding: '14px 16px', fontSize: 13, lineHeight: 1.8, color: '#333',
        fontFamily: 'Inter, system-ui, sans-serif',
      }}>
        <strong>Gustai Hospitality Group Co., LTD</strong><br/>
        2/106, Village No. 2, Kathu Subdistrict,<br/>
        Kathu District, Phuket Province. 83120. Thailand<br/>
        <strong>Email:</strong> privacy@gustai.co
      </div>

    </LegalScreen>
  );
}
