EARLY ACCESS REGISTRATION

<!--
Shopify page template: early-access.liquid
Place this file as a new page template (or use it in a Page with custom HTML via the theme editor).
Important admin steps (you need to do this yourself in Shopify admin):
1) In Admin > Discounts, create an automatic or code discount of 10% with code: EA10 (or choose your own code).
2) In Admin > Customers, create a segment with the filter: Customer tag contains "early_access_2025" (or adjust the year).
3) (Optional, for a live public list) Set up a simple webhook/Zapier/Make/Serverless endpoint that adds new registrations to a JSON file in your theme assets or Google Sheets. The front-end below can retrieve that JSON to display a public visitor list/count.

NOTE: Shopify allows customer creation via the storefront form. To automatically create customers with tags, we use a hidden input: customer[tags] = early_access_2025
This tag field allows you to easily build a segment in admin.
-->

{% comment %} --- EARLY ACCESS PAGE --- {% endcomment %}
<section class="early-access-wrap">
<div class="ea-card">
<header class="ea-header">
Early Access — Sign Up
<p class="sub">Register before <strong>October 10, 2025</strong> and get exclusive access at <strong>12:00</strong> (instead of 5:00 PM) and a 10% discount.</p>
</header>

<div class="ea-body">
<div class="ea-left">
We're launching our new collection exclusively for subscribers earlier today. Enter your details below — we'll send you the discount code and access information immediately after registering.

<!-- Signup form: creates a Shopify customer and adds a tag -->
<form id="ea-signup-form" method="post" action="/account">
<input type="hidden" name="form_type" value="create_customer">
<input type="hidden" name="utf8" value="✓">
<input type="hidden" name="customer[tags]" value="early_access_2025">
<input type="hidden" name="customer[note]" id="ea-customer-note" value="">

<label for="ea-email">Email address</label>
<input id="ea-email" name="customer[email]" type="email" placeholder="name@example.com" required>

<label for="ea-first">First Name (optional)</label>
<input id="ea-first" name="customer[first_name]" type="text" placeholder="First name">

<div class="ea-actions">
<button id="ea-submit" type="submit">Register & receive a discount</button>
</div>

By subscribing, you agree to our privacy policy. You'll receive unlimited access and one discount code for 10% off.
</form>

<div id="ea-message" class="ea-message" aria-live="polite"></div>
</div>

<aside class="ea-right">
<div class="ea-stats-card">
Who has registered?
<div id="ea-signup-count" class="ea-count">—</div>
<ul id="ea-signup-list" class="ea-list">
<li>Loading…</li>
</ul>
<p class="ea-note">You'll only see names or emails that you're allowed to share publicly — privacy first.</p>
</div>

<div class="ea-info">
<h4>What do you get?</h4>
<ul>
<li>Access to the collection at <strong>12:00</strong> on launch day.</li>
<li>10% off with code <strong>EA10</strong>.</li>
<li>Direct email with instructions after registration.</li>
</ul>
</div>
</aside>
</div>
</div>
</section>

<style>
.early-access-wrap{font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial; padding:40px; display:flex; justify-content:center}
.ea-card{max-width:1100px; width:100%; background:#fff; border-radius:12px; box-shadow:0 8px 30px rgba(10,10,10,0.06); overflow:hidden; display:block}
.ea-header{padding:36px 40px; border-bottom:1px solid #f0f0f0}
.ea header h1{margin:0; font-size:28px}
.ea-header .sub{margin:8px 0 0; color:#666}
.ea-body{display:flex; gap:24px; padding:32px 40px}
.ea-left{flex:1}
.ea-right{width:320px}
label{display:block; font-size:13px; margin-top:12px}
input[type=email], input[type=text]{width:100%; padding:12px; margin-top:6px; border-radius:8px; border:1px solid #e6e6e6}
.ea-actions{margin-top:18px}
button#ea-submit{background:#111; color:#fff; padding:12px 18px; border-radius:10px; border:0; cursor:pointer}
.ea-count{font-size:32px; font-weight:700; margin:8px 0}
.ea-list{list-style:none; padding:0; margin:0; max-height:180px; overflow:auto}
.ea-list li{padding:6px 0; border-bottom:1px dashed #f2f2f2; font-size:14px}
.ea-message{margin-top:12px; color:green}
.terms{font-size:12px; color:#888; margin-top:10px}
@media(max-width:880px){.ea-body{flex-direction:column}.ea-right{width:100%} }
</style>

<script>
(function(){
var signupDeadline = new Date('2025-10-10T23:59:59');
var publicListJsonUrl = '/apps/early-access-signups.json';
var thankYouPage = '/pages/early-access-thank-you';
var publicizeVisible = true;

var form = document.getElementById('ea-signup-form');
var email = document.getElementById('ea-email');
var first = document.getElementById('ea-first');
var message = document.getElementById('ea-message');
var noteInput = document.getElementById('ea-customer-note');

if(noteInput) noteInput.value = 'early_access_signup at ' + new Date().toISOString();

form.addEventListener('submit', function(ev){
var now = new Date();
if(now > signupDeadline){
ev.preventDefault();
message.innerText = 'The registration period is closed (deadline: October 10, 2025).';
return false;
}

document.getElementById('ea-submit').disabled = true;

ev.preventDefault();
var payload = new FormData(form);

fetch(form.action, {
method: 'POST',
body: payload,
credentials: 'same-origin'
}).then(function(resp){
window.location.href = thankYouPage + '?email=' + encodeURIComponent(email.value);
}).catch(function(err){
console.error(err);
message.innerText = 'Something went wrong while signing up. Please try again later.';
document.getElementById('ea-submit').disabled = false;
});
});

function loadPublicList(){
if(!publicizeVisible) return;
fetch(publicListJsonUrl, {cache:'no-store'})
.then(function(r){ if(!r.ok) throw new Error('no list'); return r.json(); })
.then(function(json){
var listEl = document.getElementById('ea-signup-list');
var countEl = document.getElementById('ea-signup-count');
listEl.innerHTML = '';
var publicEntries = json.filter(function(i){ return i.public === true; });
countEl.innerText = json.length + 'registrations';
if(publicEntries.length === 0){ listEl.innerHTML = '<li>No public names yet.</li>'; return; }
publicEntries.slice().reverse().forEach(function(p){
var li = document.createElement('li');
li.textContent = p.name || p.email;
listEl.appendChild(li);
});
}).catch(function(){
document.getElementById('ea-signup-count').innerText = '—';
document.getElementById('ea-signup-list').innerHTML = '<li>Public list not available.</li>';
});
}

document.addEventListener('DOMContentLoaded', loadPublicList);
})();
</script>

<!-- Thank You Page -->
<!--
<div class="ea-thank">
Thank you for subscribing!
You have successfully subscribed to Early Access. We received your email: {{ request.params.email | default: 'jouw e-mail' }}
Use the discount code EA10 for 10% off the launch. Note: Create this discount code first in Shopify Admin > Discounts and set the correct expiration date.
<p>You will get access to the collection at <strong>12:00</strong> on launch day (instead of 17:00).</p>
<a href="/en/collections/all" class="btn">Take a look at our shop</a>
</div>

<style>
.ea-thank{max-width:820px;margin:40px auto;padding:32px;background:#fff;border-radius:10px;box-shadow:0 8px 24px rgba(0,0,0,0.04)}
.ea-thank h1{margin-top:0}
.btn{display:inline-block;padding:10px 14px;border-radius:8px;background:#111;color:#fff;text-decoration:none}
</style>
-->