// Public legal documents and collection notices. Keep both languages in sync.
function LegalLink({ page, lang, children, newTab = false }) {
  return <a href={`?page=${page}&lang=${lang}`} target={newTab ? '_blank' : undefined} rel={newTab ? 'noopener noreferrer' : undefined} style={{ color: '#0F3D24', textDecoration: 'underline', textUnderlineOffset: 3 }}>{children}</a>;
}

function CollectionNotice({ lang, context = 'booking' }) {
  const en = lang === 'EN';
  const copy = {
    account: [
      'Your name, email and password are required to create and secure your free account. We use account information to manage access and your bookings.',
      '建立免費帳戶須提供姓名、電郵及密碼，用作帳戶認證、管理登入及預訂。',
    ],
    contact: [
      'Name, email, subject and message are required to answer your enquiry. Please do not include identity documents, health information or unrelated personal data.',
      '姓名、電郵、主旨及訊息為回覆查詢所需。請勿提交身分證明文件、健康資料或無關個人資料。',
    ],
    tournament: [
      'We use your account name and email to administer registration and send event notices. Provide a partner’s information only with their permission. This notice is not an event payment or cancellation policy.',
      '我哋使用帳戶姓名及電郵處理報名及發送賽事通知。提供拍檔資料前請先取得對方許可。本聲明並非賽事付款或取消條款。',
    ],
    fps: [
      'The screenshot is required for staff to verify your FPS payment and is emailed to authorised staff through our email provider. Hide unrelated transactions, balances and account details; keep the amount, date and payment reference visible.',
      '付款截圖用作職員核實 FPS 付款，會經電郵服務供應商寄予獲授權職員。請遮蓋無關交易、結餘及帳戶資料，保留金額、日期及交易參考編號。',
    ],
    booking: [
      'We use your booking details and required contact phone to arrange the session and service notices. Card receipt email is optional; FPS email is required for confirmation. Payment details are handled by Stripe or, for FPS, authorised staff. No promotional use.',
      '預訂資料及必填聯絡電話用作安排場地及服務通知。信用卡收據電郵可選填；FPS 必須提供電郵以接收確認。付款資料由 Stripe 或負責 FPS 核實嘅獲授權職員處理，不用作優惠推廣。',
    ],
  };
  return <aside style={{ fontSize: 12, lineHeight: 1.7, color: '#6B5D4E', margin: '12px 0', overflowWrap: 'anywhere' }}>
    <p>{(copy[context] || copy.booking)[en ? 0 : 1]}</p>
    <LegalLink page="collection" lang={lang} newTab>{en ? 'Personal Information Collection Statement' : '收集個人資料聲明'}</LegalLink>
    {' · '}<LegalLink page="privacy" lang={lang} newTab>{en ? 'Privacy Policy' : '私隱政策'}</LegalLink>
  </aside>;
}

function LegalPage({ lang, page }) {
  const en = lang === 'EN';
  const version = window.PM_BOOKING.TERMS_VERSION;
  const operator = en
    ? 'Winner Culture And Sports Association Ltd, operating Pickle Master. Address: Shop 303, We Go Mall, Ma On Shan, New Territories, Hong Kong. Privacy and service enquiries: George Lau, Manager; picklemasterhk@gmail.com.'
    : 'Pickle Master 營運者：Winner Culture And Sports Association Ltd。地址：香港新界馬鞍山 We Go Mall 303 號鋪。私隱及服務查詢：George Lau，Manager；picklemasterhk@gmail.com。';
  const rates = en
    ? 'Rates per court per hour in HKD, for all customers: weekdays 07:00–12:00 $220; 12:00–18:00 $280; 18:00–22:00 $380. Saturdays, Sundays and public holidays: 07:00–22:00 $380. Every day 22:00–00:00 $220. Each session is one hour. Dates, cut-offs and times use Hong Kong time (UTC+8).'
    : '所有客人每場每小時收費（港幣）：平日 07:00–12:00 $220；12:00–18:00 $280；18:00–22:00 $380。星期六、日及公眾假期 07:00–22:00 $380。每日 22:00–00:00 $220。每節一小時，所有日期、期限及時間按香港時間（UTC+8）計。';
  const cancel = en
    ? 'Cancel at least 24 hours before the session starts to receive a full refund of the amount paid for that session. Cancellations less than 24 hours before the session and no-shows are not refundable, subject to your statutory rights. Logged-in customers may cancel their own eligible bookings in My Account. Guests should email the booking reference, date and contact details to picklemasterhk@gmail.com; the time the request is received is used for the cut-off, after we verify the booking.'
    : '在場次開始前至少 24 小時取消，可獲退回該場次已付全額款項。少於 24 小時取消或缺席不獲退款，惟客人法定權利不受影響。已登入客人可於「我的帳戶」取消合資格預訂；訪客請將預訂編號、日期及聯絡資料寄至 picklemasterhk@gmail.com，核實預訂後按收到要求嘅時間計算期限。';
  const weather = en
    ? 'We normally remain open in adverse weather and the usual cancellation rules apply. Follow official safety advice and any mandatory access or closure restrictions. If we cancel or cannot provide the booked court, we will refund the full amount paid for the affected session; a credit or alternative session is offered only with your agreement.'
    : '惡劣天氣期間一般照常開放，並適用一般取消規則。請遵從官方安全指引及任何強制進出或關閉限制。如由我哋取消或未能提供已預訂場地，將全額退回受影響場次款項；積分或改期只會在你同意下安排。';
  const sections = {
    privacy: en ? [
      ['Who we are', operator],
      ['Information we handle', 'Account name, email and authentication information; booking dates, times, court, contact phone, price and payment references; optional card receipt email; required FPS confirmation email and uploaded payment proof; enquiry messages; event registration details you provide; and historic subscription and transaction records. We do not ask for HKID copies or unrelated bank records. Card details are entered into Stripe’s payment interface, rather than stored as full card numbers by this website.'],
      ['Purposes and recipients', 'We use information to authenticate accounts, provide bookings and customer support, verify payments, process refunds, administer events, keep business records and handle disputes or legal duties. Access is limited to people who need it for these functions, including authorised venue managers and staff. Providers include Supabase (accounts/database), Stripe (card payments and historic subscriptions), Resend (transactional email), Google Calendar (booking administration) and Vercel (hosting). Booking and enquiry emails may be copied to authorised operational recipients. We may disclose data to professional advisers or authorities where necessary and lawful.'],
      ['Overseas processing', 'These cloud and email providers may process information outside Hong Kong according to their infrastructure and service arrangements. We remain responsible for our handling of personal data and must use appropriate contractual or other measures with processors for security and retention. We do not promise that all data stays in Hong Kong.'],
      ['Retention and security', 'We keep personal data only as long as needed for the stated purposes, disputes and applicable legal obligations. Required business transaction records are retained for at least seven years under applicable tax requirements; this does not mean every enquiry or unrelated personal detail is kept for seven years. Staff must periodically review and securely remove unnecessary data, including payment proofs held in email and copies. Access controls and service providers support our security arrangements; no system is guaranteed to be completely secure.'],
      ['Browser storage and external resources', 'The site uses localStorage to remember language, page, cart and account/session information (including the login token). Sign out on shared devices. Browser settings can clear this storage, which may remove saved carts or sign you out. The site loads React/Babel from unpkg, fonts from Google Fonts, payment resources from Stripe and some images from Pexels; requests to those services disclose technical information such as IP address and browser details. External social links and websites have their own policies. This policy does not represent all of those services as essential cookies or promise that they do not collect data.'],
      ['Service notices, rights and enquiries', 'We use contact details for service notifications, not promotional campaigns. To request access to or correction of your personal data, contact George Lau, Manager, at the address or email above. We may reasonably verify your identity. We handle requests under the Personal Data (Privacy) Ordinance, including the applicable 40-day response requirements and permitted exceptions; a data access fee, if any, must not be excessive. You may complain to the Hong Kong Privacy Commissioner for Personal Data. We review this statement when our practices change.'],
    ] : [
      ['營運者及聯絡方法', operator],
      ['處理嘅資料類別', '包括帳戶姓名、電郵及認證資料；預訂日期、時間、場地、聯絡電話、價格及付款參考資料；選填信用卡收據電郵；FPS 必填確認電郵及付款截圖；查詢訊息；你提供嘅比賽報名資料；以及歷史訂閱及交易紀錄。我哋唔要求身分證副本或無關銀行紀錄。信用卡資料於 Stripe 付款介面輸入，網站唔會自行儲存完整卡號。'],
      ['用途及資料接收者', '資料用作帳戶認證、提供預訂及客戶服務、核實付款、退款、處理報名、保存業務紀錄及處理爭議或法定責任。只有執行相關工作所需嘅獲授權經理及職員可取用。服務供應商包括 Supabase（帳戶／資料庫）、Stripe（信用卡付款及歷史訂閱）、Resend（服務電郵）、Google Calendar（預訂管理）及 Vercel（網站寄存）。預訂及查詢電郵可能抄送獲授權營運人員。有需要及合法時，資料亦可能向專業顧問或主管機關披露。'],
      ['境外處理', '上述雲端及電郵供應商可能按其基建及服務安排，在香港以外處理資料。我哋仍須對所處理嘅個人資料負責，並以適當合約或其他方法，處理受託方嘅保安及資料保存要求，唔會保證所有資料只留喺香港。'],
      ['保存及保安', '個人資料只會在上述用途、爭議處理及適用法律要求所需期間保存。適用稅務規定要求嘅業務交易紀錄須保存最少七年，唔代表所有查詢或無關個人資料都要保存七年。職員須定期檢視及安全移除不再需要嘅資料，包括電郵內嘅付款截圖及副本。存取權限及服務供應商支援資料保安，但任何系統都無法保證完全無風險。'],
      ['瀏覽器儲存及外部資源', '網站使用 localStorage 記住語言、頁面、購物車及帳戶／登入資料（包括登入 token）。使用共用裝置後請登出。你可在瀏覽器清除儲存資料，但可能失去購物車或需要重新登入。網站從 unpkg 載入 React／Babel、Google Fonts 載入字體、Stripe 載入付款資源，部分圖片來自 Pexels；相關請求會向供應商傳送 IP 地址、瀏覽器等技術資料。外部社交連結及網站受各自政策規管。本政策唔會將上述所有服務一概稱為必要 cookies，亦唔保證佢哋完全唔收集資料。'],
      ['服務通知、權利及查詢', '聯絡資料只用於服務通知，不用於優惠推廣。查閱或改正個人資料，請透過上述地址或電郵聯絡 George Lau，Manager。我哋可能合理核實你嘅身分，並按《個人資料（私隱）條例》處理，包括適用嘅 40 日回覆期限及法定例外；如收取查閱費用，金額不得超乎適度。你亦可向香港個人資料私隱專員公署投訴。資料處理方式改變時會檢視本政策。'],
    ],
    collection: en ? [
      ['Data user and requests', operator],
      ['Why we collect information', 'We collect data to create and secure accounts, arrange bookings, verify payments, send confirmations and service updates, answer enquiries, administer event registrations, process refunds and meet record-keeping or legal obligations. We do not collect it for promotional marketing.'],
      ['Required and optional information', 'Registration requires name, email and password. Enquiries require name, email, subject and message. Court bookings require court/date/time and a contact phone; card receipt email is optional, while FPS requires email and payment proof. Event registration uses your logged-in account, with partner name and notes optional where offered. If required data is withheld we cannot complete the relevant request; optional information may be left blank. Fields marked required in the form apply to that particular service.'],
      ['Transfers and your rights', 'Data may be passed to authorised staff, the hosting, authentication/database, payment, email and calendar providers described in our Privacy Policy, and advisers or authorities where necessary and lawful, including processing outside Hong Kong. You may request access to and correction of your data by contacting George Lau, Manager, at the address or email above. Please provide only necessary information; obtain permission before sharing another person’s details.'],
    ] : [
      ['資料使用者及查詢', operator],
      ['收集用途', '用作建立及保障帳戶、安排場地、核實付款、發送確認及服務更新、回覆查詢、處理比賽報名及退款，以及履行紀錄保存或法律責任，不用作優惠推廣。'],
      ['必須及自願提供嘅資料', '註冊須提供姓名、電郵及密碼；查詢須提供姓名、電郵、主旨及訊息。訂場須提供場地、日期、時間及聯絡電話；信用卡收據電郵可選填，FPS 則須提供電郵及付款證明。比賽報名使用已登入帳戶，如有拍檔姓名及備註欄則屬選填。未提供必需資料時，我哋無法完成相關要求；選填欄可留空。各服務以表格所示必填欄位為準。'],
      ['資料轉移及你嘅權利', '資料可能交予獲授權職員、私隱政策列明嘅寄存、認證／資料庫、付款、電郵及日曆供應商，以及有需要及合法時嘅顧問或主管機關，包括香港以外處理。你可透過上述地址或電郵聯絡 George Lau，Manager，要求查閱及改正資料。請只提供必要資料，提供他人資料前先取得許可。'],
    ],
    terms: en ? [
      ['Operator and scope', operator + ' These terms govern court bookings. They do not replace separate merchandise, coaching or tournament terms. Paid membership sales have ended; a free account is optional for court booking. Existing subscriptions retain a cancellation channel in My Account.'],
      ['Prices and sessions', rates + ' The total is shown before payment. All customers pay the same court rates. Old carts are repriced before a new order is created; existing payment orders and submitted FPS requests retain their agreed prices.'],
      ['Booking and payment', 'Card bookings are confirmed only after successful payment and a booking confirmation. An FPS screenshot is a payment-review request, not a confirmed court reservation; staff must verify payment and availability. Keep your confirmation and order reference. If payment has been received but the court cannot be supplied, contact us for a full refund. Do not pay a revised FPS amount until you have reviewed the current total.'],
      ['Cancellation and weather', cancel + ' ' + weather],
      ['Safe and fair use', 'Use the court only during your booked session, follow reasonable venue and equipment rules, wear suitable footwear, supervise children and stop if you feel unwell or conditions are unsafe. Sport involves physical risk; seek appropriate advice about your ability to participate. These terms do not exclude liability for death or personal injury caused by negligence or any liability or consumer right that cannot lawfully be excluded.'],
      ['Problems, changes and governing law', 'Contact the Manager at picklemasterhk@gmail.com with your booking reference and issue. Changes apply to future bookings; they do not retrospectively change an agreed booking. Hong Kong SAR law applies, with disputes subject to Hong Kong courts and any mandatory consumer protections. Both language versions are intended to have the same meaning; discrepancies are handled fairly without reducing statutory rights.'],
    ] : [
      ['營運者及適用範圍', operator + ' 本條款適用於場地預訂，唔取代商品、教練課程或比賽嘅獨立條款。付費會員已停止銷售；訂場可選擇免費帳戶或訪客方式。現有訂閱可於「我的帳戶」申請停止續費。'],
      ['收費及場次', rates + ' 付款前會顯示總額，所有客人訂場同價。舊購物車會於建立新訂單前重新計價；已建立嘅付款訂單及已提交 FPS 要求保留原先價格。'],
      ['預訂及付款確認', '信用卡訂場須成功付款並獲預訂確認，先算完成。FPS 截圖屬付款核實要求，唔代表已留起場地，須由職員核實付款及空位。請保存確認及訂單編號。如已收款但無法提供場地，請聯絡我哋安排全額退款。FPS 金額如有變動，請先確認最新總額再付款。'],
      ['取消及天氣安排', cancel + ' ' + weather],
      ['安全及場地使用', '請只於已預訂時段使用場地、遵守合理場地及器材規則、穿著合適鞋履、照顧同行小童，並在身體不適或環境不安全時停止活動。運動涉及身體風險，如有需要請就參與能力尋求適當意見。本條款不排除因疏忽造成死亡或人身傷害嘅責任，亦不排除依法不能排除嘅責任或消費者權利。'],
      ['查詢、修改及適用法律', '如有問題，請將預訂編號及詳情寄至 picklemasterhk@gmail.com 聯絡 Manager。條款更新適用於未來預訂，唔會追溯更改已達成嘅預訂。適用香港特別行政區法律，爭議由香港法院及任何強制消費者保障規定處理。兩個語言版本旨在表達相同意思；如有差異會公平處理，唔會減損法定權利。'],
    ],
    cancellation: en ? [
      ['Contact', operator], ['Customer cancellations', cancel], ['Adverse weather and venue cancellations', weather],
      ['How refunds are handled', 'Card refunds return to the original payment method and cover only the cancelled session’s actual paid amount, not other sessions or items in the order. Bank processing times vary. FPS refunds require manual verification and arrangement with staff. We show refund processing, manual action needed, failure or completion separately from cancellation. A cancelled booking does not mean the refund has completed. If a refund fails, staff will follow up; contact us with your reference. No credit is substituted without your agreement.'],
    ] : [
      ['聯絡方法', operator], ['客人取消', cancel], ['惡劣天氣及場地方取消', weather],
      ['退款處理', '信用卡退款退回原付款方式，只退取消場次嘅實付金額，唔包括同一訂單其他場次或商品。銀行處理時間各有不同。FPS 退款須由職員核實及另行安排。預訂取消同退款處理中、待人工處理、失敗或完成會分開顯示；「已取消」唔代表已完成退款。退款失敗時會由職員跟進，請提供參考編號聯絡我哋。未經你同意唔會以積分代替退款。'],
    ],
  };
  const titles = { privacy: ['Privacy Policy', '私隱政策'], collection: ['Personal Information Collection Statement', '收集個人資料聲明'], terms: ['Court Booking Terms', '場地預訂條款'], cancellation: ['Cancellation & Refund Policy', '取消及退款政策'] };
  const key = sections[page] ? page : 'privacy';
  return <article style={{ maxWidth: 880, margin: '0 auto', padding: '48px 24px 64px', lineHeight: 1.85, overflowWrap: 'anywhere' }}>
    <h1 style={{ fontSize: 'clamp(26px,5vw,38px)', color: '#0F3D24', marginBottom: 12 }}>{titles[key][en ? 0 : 1]}</h1>
    <p style={{ color: '#6B5D4E', fontSize: 13 }}>{en ? 'Version' : '版本'} {version} · {en ? 'Effective' : '生效日期'} {window.PM_BOOKING.EFFECTIVE_DATE}</p>
    <nav aria-label={en ? 'Legal documents' : '法律文件'} style={{ display: 'flex', gap: 16, flexWrap: 'wrap', margin: '20px 0 28px' }}>{Object.keys(titles).map(k => <LegalLink key={k} page={k} lang={lang}>{titles[k][en ? 0 : 1]}</LegalLink>)}</nav>
    {sections[key].map(([heading, text]) => <section key={heading} style={{ margin: '24px 0' }}><h2 style={{ fontSize: 20, marginBottom: 8, color: '#0F3D24' }}>{heading}</h2><p>{text}</p></section>)}
    <p><a href="mailto:picklemasterhk@gmail.com">picklemasterhk@gmail.com</a></p>
  </article>;
}

Object.assign(window, { LegalPage, LegalLink, CollectionNotice });
