---
interface Props {
  title?: string;
  description?: string;
}

const {
  title = "加入等待名单",
  description = "留下你的邮箱，我们会第一时间通知你"
} = Astro.props;
---

<div class="waitlist-form-container">
  <form id="waitlist-form" class="waitlist-form">
    <div class="form-header">
      <h2 class="title">{title}</h2>
      <p class="description">{description}</p>
    </div>

    <div class="form-fields">
      <div class="field">
        <label for="nickname">昵称（可选）</label>
        <input type="text" id="nickname" name="nickname" placeholder="你的昵称" />
      </div>

      <div class="field required">
        <label for="email">邮箱</label>
        <input type="email" id="email" name="email" placeholder="your@email.com" required />
      </div>

      <div class="field">
        <label for="device">使用设备</label>
        <select id="device" name="device">
          <option value="">请选择</option>
          <option value="iphone">iPhone</option>
          <option value="android">Android</option>
          <option value="ipad">iPad</option>
          <option value="mac">Mac</option>
        </select>
      </div>

      <div class="field">
        <label for="interest">感兴趣的方向</label>
        <select id="interest" name="interest">
          <option value="">请选择</option>
          <option value="gongkai">公考申论 AI 学习教练</option>
          <option value="ai-tools">AI 工具学习知识库</option>
          <option value="frontend-interview">程序员前端面试学习助手</option>
          <option value="other">其他</option>
        </select>
      </div>

      <div class="field">
        <label for="pain-point">当前最大痛点</label>
        <textarea id="pain-point" name="pain-point" rows="3" placeholder="描述你当前学习中遇到的最大困难..."></textarea>
      </div>

      <div class="field checkbox-field">
        <label class="checkbox-label">
          <input type="checkbox" name="beta" value="yes" />
          <span>愿意参加内测</span>
        </label>
      </div>

      <div class="field checkbox-field">
        <label class="checkbox-label">
          <input type="checkbox" name="notify" value="yes" checked />
          <span>接受后续邮件通知</span>
        </label>
      </div>
    </div>

    <button type="submit" class="submit-button">提交</button>
  </form>

  <div id="success-message" class="success-message" hidden>
    <div class="success-icon">✓</div>
    <h3>提交成功！</h3>
    <p>感谢你的关注，我们会在产品上线后第一时间通知你。</p>
  </div>
</div>

<script>
  const form = document.getElementById('waitlist-form') as HTMLFormElement;
  const successMessage = document.getElementById('success-message');

  form?.addEventListener('submit', (e) => {
    e.preventDefault();

    // Mock successful submission
    form.hidden = true;
    if (successMessage) {
      successMessage.hidden = false;
    }
  });
</script>

<style>
  .waitlist-form-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--color-bg-secondary);
    border-radius: 16px;
  }

  .form-header {
    text-align: center;
    margin-bottom: 2rem;
  }

  .title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
  }

  .description {
    margin-top: 0.5rem;
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
  }

  .form-fields {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .field.required label::after {
    content: " *";
    color: var(--color-text-secondary);
  }

  label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
  }

  input[type="text"],
  input[type="email"],
  select,
  textarea {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }

  input:focus,
  select:focus,
  textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
  }

  select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
  }

  textarea {
    resize: vertical;
    min-height: 80px;
  }

  .checkbox-field {
    flex-direction: row;
  }

  .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 400;
  }

  .checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--color-accent);
  }

  .submit-button {
    margin-top: 1.5rem;
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: #ffffff;
    background: var(--color-accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
  }

  .submit-button:hover {
    background: var(--color-accent-hover);
  }

  .submit-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  .success-message {
    text-align: center;
    padding: 2rem;
  }

  .success-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #ffffff;
    background: #34c759;
    border-radius: 50%;
  }

  .success-message h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
  }

  .success-message p {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
  }
</style>