@extends('layouts.app')

@section('title', '利用者マスタ｜新規')

@section('content')
  {{-- ▼ パンくず --}}
  <div class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-lg-6"><h1 class="m-0 text-dark">新規</h1></div>
        <div class="col-lg-6">
          <ol class="breadcrumb float-sm-right text-sm">
            <li class="breadcrumb-item"><a href="{{ route('home') }}">ホーム</a></li>
            <li class="breadcrumb-item"><a href="{{ route('users') }}">利用者マスタ</a></li>
            <li class="breadcrumb-item active">新規</li>
          </ol>
        </div>
      </div>
    </div>
  </div>

  <section class="content">
    <div class="container-fluid">

      {{-- ▼ 成功/エラー表示 --}}
      @if ($errors->any())
        <div class="alert alert-danger">
          <ul class="mb-0">
            @foreach ($errors->all() as $e)
              <li>{{ $e }}</li>
            @endforeach
          </ul>
        </div>
      @endif

      <form method="post" action="{{ route('users_add') }}" enctype="multipart/form-data">
        @csrf

        <div class="card">
          <div class="card-header">
            <h3 class="card-title">基本情報</h3>
          </div>
          <div class="card-body">

            {{-- ▼ 1列レイアウト（ラベル左 / 入力右） --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">会員ID</label>
              <div class="col-md-10">
                <input type="text" name="member_id" value="{{ old('member_id') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">利用者ID <span class="text-danger">*</span></label>
              <div class="col-md-10">
                <input type="text" name="user_id" value="{{ old('user_id') }}" class="form-control" required>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">パスワード</label>
              <div class="col-md-10">
                <input type="password" name="user_pass" class="form-control" autocomplete="new-password">
              </div>
            </div>

            {{-- タグ/QR & シリアル --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">タグ／QR</label>
              <div class="col-md-10 d-flex align-items-center">
                <div class="form-check mr-3">
                  <input class="form-check-input" type="radio" name="tag_qr_flag" id="tag_qr_qr" value="1" {{ old('tag_qr_flag','0')=='1'?'checked':'' }}>
                  <label for="tag_qr_qr" class="form-check-label">QR</label>
                </div>
                <div class="form-check">
                  <input class="form-check-input" type="radio" name="tag_qr_flag" id="tag_qr_tag" value="0" {{ old('tag_qr_flag','0')=='0'?'checked':'' }}>
                  <label for="tag_qr_tag" class="form-check-label">タグ</label>
                </div>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">タグシリアル</label>
              <div class="col-md-10">
                <input type="text" name="user_tag_serial" value="{{ old('user_tag_serial') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">タグシリアル(64)</label>
              <div class="col-md-10">
                <input type="text" name="user_tag_serial_64" value="{{ old('user_tag_serial_64') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">QRコード</label>
              <div class="col-md-10">
                <input type="text" name="qr_code" value="{{ old('qr_code') }}" class="form-control">
              </div>
            </div>

            {{-- AID / 設置場所QR --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">AID</label>
              <div class="col-md-10">
                <input type="text" name="user_aid" value="{{ old('user_aid') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">設置場所QR</label>
              <div class="col-md-10">
                <input type="text" name="user_place_qrid" value="{{ old('user_place_qrid') }}" class="form-control">
              </div>
            </div>

            {{-- 利用者属性 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">利用者分類ID</label>
              <div class="col-md-10">
                <input type="text" name="user_categoryid" value="{{ old('user_categoryid') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">氏名 <span class="text-danger">*</span></label>
              <div class="col-md-10">
                <input type="text" name="user_name" value="{{ old('user_name') }}" class="form-control" required>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">フリガナ</label>
              <div class="col-md-10">
                <input type="text" name="user_phonetic" value="{{ old('user_phonetic') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">性別</label>
              <div class="col-md-10 d-flex align-items-center">
                <label class="mr-3"><input type="radio" name="user_gender" value="男性" {{ old('user_gender')=='男性'?'checked':'' }}> 男性</label>
                <label class="mr-3"><input type="radio" name="user_gender" value="女性" {{ old('user_gender')=='女性'?'checked':'' }}> 女性</label>
                <label><input type="radio" name="user_gender" value="未入力" {{ old('user_gender')=='未入力'?'checked':'' }}> 未入力</label>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">生年月日</label>
              <div class="col-md-4">
                <input type="date" name="user_birthdate" value="{{ old('user_birthdate') }}" class="form-control">
              </div>
              <label class="col-md-2 col-form-label text-md-right">年齢</label>
              <div class="col-md-4">
                <input type="number" name="user_age" value="{{ old('user_age') }}" class="form-control">
              </div>
            </div>

            {{-- 連絡先 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">携帯電話番号</label>
              <div class="col-md-10">
                <input type="text" name="user_mobile" value="{{ old('user_mobile') }}" class="form-control" placeholder="080-0000-0000">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">自宅電話番号</label>
              <div class="col-md-10">
                <input type="text" name="user_homephone" value="{{ old('user_homephone') }}" class="form-control" placeholder="000-0000-0000">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">メールアドレス</label>
              <div class="col-md-10">
                <input type="email" name="user_primemail" value="{{ old('user_primemail') }}" class="form-control" placeholder="name@example.com">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">予備メール</label>
              <div class="col-md-10">
                <input type="email" name="user_submail" value="{{ old('user_submail') }}" class="form-control" placeholder="name@example.com">
              </div>
            </div>

            {{-- 現住所 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">現住所 郵便番号</label>
              <div class="col-md-10">
                <input type="text" name="user_regident_zip" value="{{ old('user_regident_zip') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">現住所 都道府県</label>
              <div class="col-md-10">
                <input type="text" name="user_regident_pre" value="{{ old('user_regident_pre') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">現住所 市区町村</label>
              <div class="col-md-10">
                <input type="text" name="user_regident_city" value="{{ old('user_regident_city') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">現住所 住所</label>
              <div class="col-md-10">
                <input type="text" name="user_regident_add" value="{{ old('user_regident_add') }}" class="form-control">
              </div>
            </div>

            {{-- 連絡先住所 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">連絡先 郵便番号</label>
              <div class="col-md-10">
                <input type="text" name="user_relate_zip" value="{{ old('user_relate_zip') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">連絡先 都道府県</label>
              <div class="col-md-10">
                <input type="text" name="user_relate_pre" value="{{ old('user_relate_pre') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">連絡先 市区町村</label>
              <div class="col-md-10">
                <input type="text" name="user_relate_city" value="{{ old('user_relate_city') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">連絡先 住所</label>
              <div class="col-md-10">
                <input type="text" name="user_relate_add" value="{{ old('user_relate_add') }}" class="form-control">
              </div>
            </div>

            {{-- その他属性 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">区民</label>
              <div class="col-md-10">
                <input type="text" name="ward_residents" value="{{ old('ward_residents') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">勤務先</label>
              <div class="col-md-10">
                <input type="text" name="user_workplace" value="{{ old('user_workplace') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">学校名</label>
              <div class="col-md-10">
                <input type="text" name="user_school" value="{{ old('user_school') }}" class="form-control">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">卒業年</label>
              <div class="col-md-10">
                <input type="date" name="user_graduate" value="{{ old('user_graduate') }}" class="form-control">
              </div>
            </div>

            {{-- 本人確認 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認書類</label>
              <div class="col-md-10">
                <input type="text" name="user_idcard" value="{{ old('user_idcard') }}" class="form-control" placeholder="運転免許証 など">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認チェック</label>
              <div class="col-md-10">
                {{-- 0/1のみのDBの場合は 0=未チェック / 1=手動チェックOK で保存 --}}
                <label class="mr-3"><input type="radio" name="user_idcard_chk_flag" value="0" {{ old('user_idcard_chk_flag','0')=='0'?'checked':'' }}> 未チェック</label>
                <label><input type="radio" name="user_idcard_chk_flag" value="1" {{ old('user_idcard_chk_flag')=='1'?'checked':'' }}> 手動チェックOK</label>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認日時</label>
              <div class="col-md-10">
                <input type="date" name="user_chk_day" value="{{ old('user_chk_day') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認オペレータID</label>
              <div class="col-md-10">
                <input type="text" name="user_chk_opeid" value="{{ old('user_chk_opeid') }}" class="form-control">
              </div>
            </div>

            {{-- タグ発行 / 発行可否 / 退会 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">タグ発行数</label>
              <div class="col-md-10">
                <input type="number" name="user_tag_issue" value="{{ old('user_tag_issue') }}" class="form-control">
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">発行可否</label>
              <div class="col-md-10">
                <label class="mr-3"><input type="radio" name="issue_permission" value="1" {{ old('issue_permission')=='1'?'checked':'' }}> 発行可</label>
                <label><input type="radio" name="issue_permission" value="0" {{ old('issue_permission','0')=='0'?'checked':'' }}> 発行不可</label>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">退会フラグ</label>
              <div class="col-md-10">
                <label class="mr-3"><input type="radio" name="user_quit_flag" value="1" {{ old('user_quit_flag')=='1'?'checked':'' }}> はい</label>
                <label><input type="radio" name="user_quit_flag" value="0" {{ old('user_quit_flag','0')=='0'?'checked':'' }}> いいえ</label>
              </div>
            </div>

            <div class="form-group row">
              <label class="col-md-2 col-form-label">退会日</label>
              <div class="col-md-10">
                <input type="date" name="user_quitday" value="{{ old('user_quitday') }}" class="form-control">
              </div>
            </div>

            {{-- 本人確認写真（ダミー：実装は後日） --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認写真ファイル1</label>
              <div class="col-md-10">
                <input type="file" name="id_photo1" class="form-control-file">
              </div>
            </div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label">本人確認写真ファイル2</label>
              <div class="col-md-10">
                <input type="file" name="id_photo2" class="form-control-file">
              </div>
            </div>

            {{-- 備考 --}}
            <div class="form-group row">
              <label class="col-md-2 col-form-label">備考</label>
              <div class="col-md-10">
                <textarea name="user_remarks" rows="4" class="form-control">{{ old('user_remarks') }}</textarea>
              </div>
            </div>

          </div>
          <div class="card-footer">
            <button type="submit" class="btn btn-primary">登録</button>
            <a href="{{ route('users') }}" class="btn btn-default ml-2">戻る</a>
          </div>
        </div>

      </form>

    </div>
  </section>

  {{-- 見た目の微調整（間隔を広げる） --}}
  <style>
    .card .form-group { margin-bottom: .85rem; }
  </style>
@endsection
