/* Mobile inline, reviewable waiver / code of conduct / policies document.
   Rendered above the consent checkboxes in RegStepGuardian.
   Faithful transcription of the program's legal text — edit copy here. */

(function () {
  const regwDoc = {
    sectionNum: {
      fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: "0.12em",
      textTransform: "uppercase", color: "var(--c-red)", fontWeight: 500,
      display: "block", marginTop: 26, marginBottom: 8,
      paddingBottom: 8, borderBottom: "1.5px solid var(--c-line)",
    },
    sectionTitle: {
      fontFamily: "var(--font-display)", letterSpacing: "0.005em",
      textTransform: "uppercase", lineHeight: 1.05, fontSize: 19, color: "var(--c-ink)",
      margin: "0 0 12px",
    },
    sub: { fontWeight: 700, fontSize: 13.5, color: "var(--c-ink)", margin: "16px 0 6px" },
    p: { fontSize: 12.5, lineHeight: 1.6, color: "var(--c-ink-soft)", margin: "0 0 10px" },
    caps: { fontSize: 12, lineHeight: 1.6, color: "var(--c-ink)", fontWeight: 600, margin: "0 0 10px" },
    list: { margin: "0 0 11px", padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 6 },
    li: { fontSize: 12.5, lineHeight: 1.5, color: "var(--c-ink-soft)", display: "flex", gap: 9, alignItems: "flex-start" },
    bullet: { flex: "0 0 auto", width: 5, height: 5, borderRadius: 999, background: "var(--c-red)", marginTop: 7 },
  };

  function Sec({ n, label, title, first, children }) {
    return (
      <section>
        <span style={{ ...regwDoc.sectionNum, ...(first ? { marginTop: 4 } : {}) }}>{n} · {label}</span>
        <h4 className="display" style={regwDoc.sectionTitle}>{title}</h4>
        {children}
      </section>
    );
  }
  function Sub({ children }) { return <div style={regwDoc.sub}>{children}</div>; }
  function P({ children }) { return <p style={regwDoc.p}>{children}</p>; }
  function Caps({ children }) { return <p style={regwDoc.caps}>{children}</p>; }
  function List({ items }) {
    return (
      <ul style={regwDoc.list}>
        {items.map((it, i) => (
          <li key={i} style={regwDoc.li}><span style={regwDoc.bullet}/><span>{it}</span></li>
        ))}
      </ul>
    );
  }

  function RegWaiverReview() {
    const [open, setOpen] = React.useState(false);
    const scrollRef = React.useRef(null);
    const [atBottom, setAtBottom] = React.useState(false);

    const onScroll = () => {
      const el = scrollRef.current;
      if (!el) return;
      setAtBottom(el.scrollTop + el.clientHeight >= el.scrollHeight - 8);
    };

    return (
      <div style={{ border: "1px solid var(--c-line)", borderRadius: 10, overflow: "hidden", background: "var(--c-paper)" }}>
        <button
          onClick={() => setOpen(o => !o)}
          aria-expanded={open}
          className="tappable"
          style={{
            width: "100%", display: "flex", alignItems: "center", gap: 12,
            padding: "13px 14px", background: "transparent", border: "none",
            color: "var(--c-ink)", textAlign: "left", cursor: "pointer",
          }}
        >
          <span style={{
            flex: "0 0 auto", width: 32, height: 32, borderRadius: 8,
            background: "var(--c-red)", color: "#fff",
            display: "grid", placeItems: "center", fontSize: 15,
          }}>§</span>
          <span style={{ flex: 1, minWidth: 0 }}>
            <span className="mono" style={{ color: "var(--c-ink-soft)", display: "block", fontSize: 9.5 }}>
              Before you accept · review
            </span>
            <span className="display" style={{ fontSize: 14.5, lineHeight: 1.1, display: "block", marginTop: 2, color: "var(--c-ink)" }}>
              Waiver, Code of Conduct &amp; Policies
            </span>
          </span>
          <span style={{
            flex: "0 0 auto", display: "inline-flex", alignItems: "center", gap: 6,
            color: "var(--c-red)", fontFamily: "var(--font-mono)", fontSize: 10,
            letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 500,
          }}>
            {open ? "Close" : "Read"}
            <span style={{ display: "inline-block", transition: "transform 220ms ease", transform: open ? "rotate(180deg)" : "rotate(0deg)", fontSize: 12 }}>▾</span>
          </span>
        </button>

        {open && (
          <div style={{ borderTop: "1px solid var(--c-line)", animation: "pageIn 280ms var(--ease-snap) both" }}>
            <div
              ref={scrollRef}
              onScroll={onScroll}
              style={{ maxHeight: 340, overflowY: "auto", WebkitOverflowScrolling: "touch", padding: "6px 16px 16px", background: "var(--c-bg)" }}
            >
              <p style={{ fontFamily: "var(--font-mono)", fontSize: 9, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--c-ink-soft)", margin: "14px 0 4px" }}>
                London LOGIC Basketball Camp · 2026 · for Matthews Hall &amp; London LOGIC Basketball
              </p>

              <Sec n="Part I" label="Program Waiver" title="Camp Waiver & Release of Liability" first>
                <Sub>1. Consent to Participate</Sub>
                <P>
                  I/We am/are the parent(s)/legal guardian(s) of the participant named above. I consent to my
                  child’s participation in the basketball camp activities, including gym-based drills, games,
                  and age-appropriate physical conditioning.
                </P>
                <P>
                  I/We understand that this Camp Waiver is a legally binding agreement made for the benefit of
                  Matthews Hall, London LOGIC Basketball Camp and their directors, officers, employees, group
                  leaders, administrators, volunteers, chaperones, and respective insurers (collectively, the
                  “Releasees”). This Camp Waiver inures to the benefit of the Releasees and binds the student
                  (and in the case of a student under the age of eighteen, the student’s parent or guardian),
                  and their respective heirs, executors, administrators and representatives, successors, and
                  assigns.
                </P>
                <P>
                  I/We understand that participation in the Camp is voluntary, and the student has, at all
                  times, the right to choose not to participate in the Camp if they do not feel comfortable.
                </P>

                <Sub>2. Acknowledgement of Risk</Sub>
                <P>
                  I/We understand that participation in basketball and related athletic activities involves
                  inherent risks, including slips, trips, falls, collisions with other participants, contact
                  with equipment, and potential strains, sprains. I understand that injuries may occur despite
                  proper instruction and supervision.
                </P>
                <P>
                  I/We acknowledge and understand that there are inherent risks, dangers, and hazards (“Risks”)
                  associated with the student’s involvement and participation in this Camp. These Risks include
                  but are not limited to,
                </P>
                <List items={[
                  "Food preparation and contact with items or equipment that may contain or have been exposed to known and potentially unknown irritants and allergens;",
                  "Physical activity, such as walking, and personal and general injuries arising from physical activity (including fatigue, concussion, overexertion, exhaustion, and cardio-pulmonary strain);",
                  "Contact with known and unknown allergens;",
                  "Traffic and pedestrian hazards (risks associated with traveling or navigating public roadways, parking lots, and sidewalks in vehicles, public transit, or as a pedestrian);",
                  "Natural hazards (including inclement weather, terrain, manmade or other objects on the road or sidewalk, natural disasters, and poor visibility);",
                  "Environmental hazards (including allergies, sun-related ailments, cold-related ailments, dehydration, altitude related ailments/injuries, and animal encounters);",
                  "Unexpected contact with others, including physical contact and assault;",
                  "Theft, vandalism, and loss or damage to personal property;",
                  "Interaction with other members of Camp and members of the public;",
                  "Becoming lost or disoriented; and",
                  "The use of public transportation or use of another facility’s services, amenities, and equipment.",
                ]}/>
                <P>
                  I/We are aware that the Risks may also include but are not limited to, the potential for
                  serious personal injury, death, property damage, or illness (e.g., communicable diseases such
                  as influenza, and COVID-19).
                </P>

                <Sub>3. Release and Waiver</Sub>
                <Caps>
                  I/WE FREELY ACCEPT AND FULLY ASSUME ALL RESPONSIBILITIES for all Risks and possibilities of
                  personal injury, death, property damage, illness or other loss resulting from the student’s
                  involvement and participation in the Camp.
                </Caps>
                <P>
                  With an acknowledgement of these Risks, I/We give permission and consent for the student to
                  participate in the Camp.
                </P>
                <Sub>Indemnity</Sub>
                <Caps>
                  I/WE AGREE TO RELEASE, INDEMNIFY, HOLD HARMLESS AND FOREVER DISCHARGE the Releasees to the
                  fullest extent permitted by law from all liability for all personal injury (including, but not
                  limited, to communicable diseases and illness), death, property damage, illness, or other loss
                  resulting from the Student’s participation in the Camp (including, but not limited, any such
                  loss to third parties caused or contributed to by the acts of the Student) due to any cause,
                  WHETHER ARISING FROM THE NEGLIGENCE OF THE RELEASEES, VICARIOUS LIABILITY, BREACH OF ANY DUTY
                  IMPOSED BY LAW (INCLUDING BUT NOT LIMITED TO THE OCCUPIERS' LIABILITY ACT, R.S.O. 1990, c. O.2),
                  BREACH OF CONTRACT OR MISTAKE OR ERROR OF JUDGMENT OF THE RELEASEES, OR OTHERWISE.
                </Caps>
                <Caps>
                  I/WE AGREE TO BE LIABLE FOR AND TO HOLD HARMLESS AND INDEMNIFY the Releasees from all actions,
                  proceedings, claims, damages, costs, demands including court costs and costs on a solicitor and
                  client basis, and liabilities whatsoever nature or kind arising out the student’s participation
                  in the Camp.
                </Caps>
                <P>To the fullest extent permitted by law, I release and waive any and all claims against:</P>
                <List items={[
                  "the Camp Organizer (London LOGIC Basketball), including its directors, employees, coaches, volunteers, and agents; and",
                  "the Facility Owner/Operator: Matthews Hall, including its directors, officers, employees, volunteers, and agents",
                ]}/>
                <P>
                  for injury, loss, or damage arising from participation in the camp, except where caused by the
                  gross negligence or wilful misconduct of the released parties.
                </P>

                <Sub>4. Medical and Emergency Authorization</Sub>
                <P>
                  To the best of my/our knowledge, the student does not have any contagious illnesses (including
                  COVID-19 or a variant thereof) and is physically, mentally, and emotionally capable of
                  participating in all activities relating to the Camp. I/We accept responsibility to verify that
                  the student does not have any known impairments or problems that would impair their ability to
                  participate or would create a heightened risk to the student or others during the Camp. I/We
                  acknowledge that it is my/our responsibility to advise the Camp staff of any medical or health
                  concerns of the student that may affect their participation in the Camp.
                </P>
                <P>
                  I/We acknowledge that the health information provided is up-to-date and accurate. I/We have
                  fully read, completed, and updated the Medical Form provided by the Camp and accept full
                  responsibility for the information and any errors or omissions on the Medical Form.
                </P>
              </Sec>

              <Sec n="Part II" label="Code of Conduct" title="Behaviour Expectations">
                <P>
                  I understand that safe participation requires respectful behaviour and following instructions.
                  I acknowledge that the Camp Organizer may restrict participation or dismiss a participant for
                  unsafe or disruptive behaviour.
                </P>
              </Sec>

              <Sec n="Part III" label="Policies" title="Athlete Placement Policy">
                <P>
                  To ensure all athletes are training in an environment that best supports their development,
                  London LOGIC operates using a division-based placement model aligned with both age and skill
                  level.
                </P>
                <P>
                  While divisions are primarily structured by grade level, London LOGIC reserves the right to
                  make select placement adjustments at the discretion of the Program Director. These adjustments
                  may be made in cases where an athlete’s skill level, experience, physical readiness, or overall
                  development would be better supported in a different training environment.
                </P>
                <P>
                  Placement decisions are guided by the learning goals and success criteria of each age division.
                  This ensures that athletes are placed in the environment where they can safely access the
                  intended training focus, respond to the expectations of the group, and continue progressing
                  within the London LOGIC development pathway.
                </P>
                <P>This approach is intended to:</P>
                <List items={[
                  "Maintain developmentally appropriate training groups;",
                  "Ensure athlete safety and confidence;",
                  "Maximize skill progression and learning outcomes; and",
                  "Support athletes in meeting the learning goals of their division.",
                ]}/>
                <P>
                  All placement decisions are made with the athlete’s best interest in mind and are considered
                  final to preserve the integrity of the program structure.
                </P>
              </Sec>

              <div style={{
                marginTop: 20, paddingTop: 12, borderTop: "1.5px solid var(--c-line)",
                fontFamily: "var(--font-mono)", fontSize: 9, letterSpacing: "0.08em",
                textTransform: "uppercase",
                color: atBottom ? "var(--c-red)" : "var(--c-ink-soft)",
                transition: "color 200ms ease",
              }}>
                {atBottom ? "— End of document · you may now accept below —" : "— Scroll for the full document —"}
              </div>
            </div>
          </div>
        )}
      </div>
    );
  }

  window.RegWaiverReview = RegWaiverReview;
})();
