<?= $this->extend('auth/_shell') ?>

<?= $this->section('heading') ?>회원가입<?= $this->endSection() ?>

<?= $this->section('content') ?>
<?php $inputCls = 'block w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-[#007bff]/40 focus:border-[#007bff]'; ?>
<form action="<?= base_url('register') ?>" method="POST" class="space-y-4">
  <?= csrf_field() ?>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_id">아이디 <span class="text-red-500">*</span></label>
    <input class="<?= $inputCls ?>" id="mb_id" name="mb_id" type="text" value="<?= esc(old('mb_id')) ?>" autocomplete="username" autofocus/>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_passwd">비밀번호 <span class="text-red-500">*</span></label>
    <input class="<?= $inputCls ?>" id="mb_passwd" name="mb_passwd" type="password" autocomplete="new-password"/>
    <p class="mt-1 text-xs text-gray-500">8자 이상, 영문·숫자·특수문자를 모두 포함해야 합니다.</p>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_passwd_confirm">비밀번호 확인 <span class="text-red-500">*</span></label>
    <input class="<?= $inputCls ?>" id="mb_passwd_confirm" name="mb_passwd_confirm" type="password" autocomplete="new-password"/>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_name">이름 <span class="text-red-500">*</span></label>
    <input class="<?= $inputCls ?>" id="mb_name" name="mb_name" type="text" value="<?= esc(old('mb_name')) ?>" autocomplete="name"/>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_email">이메일</label>
    <input class="<?= $inputCls ?>" id="mb_email" name="mb_email" type="email" value="<?= esc(old('mb_email')) ?>"/>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_phone">연락처</label>
    <input class="<?= $inputCls ?>" id="mb_phone" name="mb_phone" type="tel" value="<?= esc(old('mb_phone')) ?>"/>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_lg_idx">지자체</label>
    <select class="<?= $inputCls ?>" id="mb_lg_idx" name="mb_lg_idx">
      <option value="">선택 안 함</option>
      <?php if (! empty($localGovernments)): ?>
        <?php foreach ($localGovernments as $lg): ?>
      <option value="<?= $lg->lg_idx ?>" <?= (string) old('mb_lg_idx') === (string) $lg->lg_idx ? 'selected' : '' ?>><?= esc($lg->lg_name) ?></option>
        <?php endforeach; ?>
      <?php endif; ?>
    </select>
  </div>
  <div>
    <label class="block text-sm font-bold text-gray-700 mb-1" for="mb_level">사용자 역할 <span class="text-red-500">*</span></label>
    <select class="<?= $inputCls ?>" id="mb_level" name="mb_level">
      <?php foreach (config('Roles')->levelNames as $level => $name): ?>
      <?php if (\Config\Roles::isSuperAdminEquivalent((int) $level)) continue; ?>
      <option value="<?= $level ?>" <?= old('mb_level', config('Roles')->defaultLevelForSelfRegister) == $level ? 'selected' : '' ?>><?= esc($name) ?></option>
      <?php endforeach; ?>
    </select>
    <p class="text-xs text-gray-500 mt-1">가입 후 관리자 승인 완료 시 로그인할 수 있습니다.</p>
  </div>
  <div class="flex gap-2 pt-2">
    <button type="submit" class="bg-btn-search text-white px-4 py-2 rounded-lg text-sm font-semibold shadow hover:brightness-110 transition">가입하기</button>
    <a href="<?= base_url('login') ?>" class="bg-white text-gray-700 border border-gray-300 px-4 py-2 rounded-lg text-sm shadow-sm hover:bg-gray-50 transition">로그인</a>
  </div>
</form>
<?= $this->endSection() ?>
