<div class="demo-caption">Delivery, with a live total</div>
<div class="demo-split">
  <ray-radio-group id="demo-shipping" label="Delivery" name="shipping" value="standard" description="Prices include taxes.">
    <ray-radio value="standard" label="Standard · free" description="4–6 business days"></ray-radio>
    <ray-radio value="express" label="Express · $9.00" description="1–2 business days"></ray-radio>
    <ray-radio value="pickup" label="Pick up in store · free" description="Ready tomorrow from 10:00"></ray-radio>
    <ray-radio value="drone" label="Drone · $24.00" description="Not available at your address" disabled></ray-radio>
  </ray-radio-group>
  <dl class="demo-summary">
    <div><dt>Subtotal</dt><dd>$48.00</dd></div>
    <div><dt>Delivery</dt><dd id="demo-shipping-cost">$0.00</dd></div>
    <div class="total"><dt>Total</dt><dd id="demo-shipping-total">$48.00</dd></div>
    <p class="demo-muted" id="demo-shipping-eta">Arrives in 4–6 business days.</p>
  </dl>
</div>

<div class="demo-caption">Cards: ray-radio-card in a ray-grid</div>
<ray-radio-group id="demo-preset" label="Preset" name="preset" value="pro">
  <ray-grid cols="2" gap="sm">
    <ray-radio-card value="pro" label="Pro boxing" description="12 × 3:00 / 1:00"></ray-radio-card>
    <ray-radio-card value="amateur" label="Amateur" description="3 × 3:00 / 1:00"></ray-radio-card>
    <ray-radio-card value="mma" label="MMA" description="5 × 5:00 / 1:00"></ray-radio-card>
    <ray-radio-card value="hiit" label="HIIT" description="8 × 0:20 / 0:10"></ray-radio-card>
  </ray-grid>
</ray-radio-group>

<div class="demo-grid">
  <ray-radio-group label="Plan" name="plan" value="team" color="teal">
    <ray-radio-card value="solo" label="Solo" description="One seat, every component."><ray-icon slot="icon" name="user"></ray-icon></ray-radio-card>
    <ray-radio-card value="team" label="Team · $12/month" description="Up to 10 seats and shared themes."><ray-icon slot="icon" name="home"></ray-icon><ray-badge size="xs" variant="light" color="teal">Popular</ray-badge></ray-radio-card>
    <ray-radio-card value="enterprise" label="Enterprise" description="Contact us." disabled><ray-icon slot="icon" name="settings"></ray-icon></ray-radio-card>
  </ray-radio-group>
  <ray-radio-group label="Without the circle" value="dark" orientation="horizontal">
    <ray-radio-card value="light" label="Light" hide-indicator><ray-icon slot="icon" name="sun"></ray-icon></ray-radio-card>
    <ray-radio-card value="dark" label="Dark" hide-indicator><ray-icon slot="icon" name="moon"></ray-icon></ray-radio-card>
    <ray-radio-card value="system" label="System" hide-indicator><ray-icon slot="icon" name="monitor"></ray-icon></ray-radio-card>
  </ray-radio-group>
</div>

<div class="demo-caption">Horizontal, colors and the outline variant</div>
<div class="demo-grid">
  <ray-radio-group label="Theme" orientation="horizontal" color="violet" value="dark">
    <ray-radio value="light">Light</ray-radio>
    <ray-radio value="dark">Dark</ray-radio>
    <ray-radio value="system">System</ray-radio>
  </ray-radio-group>
  <ray-radio-group label="Backups" orientation="horizontal" variant="outline" color="teal" value="daily">
    <ray-radio value="hourly">Hourly</ray-radio>
    <ray-radio value="daily">Daily</ray-radio>
    <ray-radio value="weekly">Weekly</ray-radio>
  </ray-radio-group>
  <ray-radio-group label="Size" orientation="horizontal" color="orange" size="md" value="m">
    <ray-radio value="s">S</ray-radio>
    <ray-radio value="m">M</ray-radio>
    <ray-radio value="l">L</ray-radio>
    <ray-radio value="xl" disabled>XL</ray-radio>
  </ray-radio-group>
</div>

<div class="demo-caption">Sizes</div>
<div class="demo-row">
  <ray-radio-group aria-label="Extra small" size="xs" value="a"><ray-radio value="a">xs</ray-radio></ray-radio-group>
  <ray-radio-group aria-label="Small" size="sm" value="a"><ray-radio value="a">sm</ray-radio></ray-radio-group>
  <ray-radio-group aria-label="Medium" size="md" value="a"><ray-radio value="a">md</ray-radio></ray-radio-group>
  <ray-radio-group aria-label="Large" size="lg" value="a"><ray-radio value="a">lg</ray-radio></ray-radio-group>
  <ray-radio-group aria-label="Extra large" size="xl" value="a"><ray-radio value="a">xl</ray-radio></ray-radio-group>
</div>

<div class="demo-caption">Required, in a form</div>
<form class="demo-auth" id="demo-survey" novalidate>
  <ray-radio-group id="demo-source" name="source" label="How did you hear about ray·elements?" description-position="below" description="One answer." required>
    <ray-radio value="friend">A friend or a colleague</ray-radio>
    <ray-radio value="search">A search engine</ray-radio>
    <ray-radio value="talk">A talk or a meetup</ray-radio>
    <ray-radio value="other">Somewhere else</ray-radio>
  </ray-radio-group>
  <div class="demo-actions"><ray-button type="submit">Send</ray-button><span class="demo-muted" id="demo-survey-out"></span></div>
</form>

<script type="module">
  // Delivery: the total follows the choice.
  const prices = { standard: 0, express: 9, pickup: 0, drone: 24 };
  const eta = { standard: "Arrives in 4–6 business days.", express: "Arrives in 1–2 business days.", pickup: "Ready tomorrow from 10:00.", drone: "" };
  const shipping = document.getElementById("demo-shipping");
  const money = (n) => `$${n.toFixed(2)}`;
  shipping.addEventListener("change", () => {
    const cost = prices[shipping.value] ?? 0;
    document.getElementById("demo-shipping-cost").textContent = money(cost);
    document.getElementById("demo-shipping-total").textContent = money(48 + cost);
    document.getElementById("demo-shipping-eta").textContent = eta[shipping.value] ?? "";
  });

  // Required: the error shows on submit and goes away with an answer.
  const form = document.getElementById("demo-survey");
  const source = document.getElementById("demo-source");
  form.addEventListener("submit", (e) => {
    e.preventDefault();
    if (!source.value) {
      source.error = "Pick one to continue.";
      document.getElementById("demo-survey-out").textContent = "";
      return;
    }
    document.getElementById("demo-survey-out").textContent = `Thanks! source=${new FormData(form).get("source")}`;
  });
  source.addEventListener("change", () => { source.error = ""; });
</script>