@extends('admin.layouts.app')

@section('title', '관리자 계정 등록')
@section('page_title', '관리자 계정 등록')
@section('page_desc', '임시 비밀번호 생성 후 다음 로그인 시 변경이 강제됩니다.')

@push('head')
    <style>
        /* admins create only */
        .lbtn{padding:8px 12px;font-size:13px;border-radius:12px;line-height:1.1;text-decoration:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;
            border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.06);color:inherit;cursor:pointer;}
        .lbtn:hover{background:rgba(255,255,255,.10);text-decoration:none;}
        .lbtn--primary{background:rgba(59,130,246,.88);border-color:rgba(59,130,246,.95);color:#fff;}
        .lbtn--primary:hover{background:rgba(59,130,246,.98);}
        .lbtn--ghost{background:transparent;}
        .lbtn--sm{padding:7px 10px;font-size:12px;border-radius:11px;}
        .lbtn--wide{padding:10px 14px;font-weight:800;}
        .wrap{max-width:760px;}
    </style>
@endpush

@section('content')
    <div class="a-card" style="padding:16px; margin-bottom:16px;">
        <div style="display:flex; justify-content:space-between; align-items:flex-start; gap:12px; flex-wrap:wrap;">
            <div>
                <div style="font-weight:900; font-size:16px;">관리자 계정 등록</div>
                <div class="a-muted" style="font-size:12px; margin-top:4px;">
                    비밀번호는 입력하지 않습니다. 서버에서 임시 비밀번호 생성 → 다음 로그인 시 변경 강제
                </div>
            </div>

            <a class="lbtn lbtn--ghost lbtn--sm"
               href="{{ route('admin.admins.index', $filters ?? []) }}">
                ← 목록
            </a>
        </div>
    </div>

    <form method="POST" action="{{ route('admin.admins.store') }}"
          onsubmit="this.querySelector('button[type=submit]')?.setAttribute('disabled','disabled');">
        @csrf

        <div class="a-card wrap" style="padding:16px;">
            <div class="a-field">
                <label class="a-label">이메일</label>
                <input class="a-input" name="email" value="{{ old('email') }}" placeholder="admin@example.com" autocomplete="off">
                @error('email') <div class="a-error">{{ $message }}</div> @enderror
            </div>

            <div class="a-field">
                <label class="a-label">성명</label>
                <input class="a-input" name="name" value="{{ old('name') }}" placeholder="홍길동" autocomplete="off">
                @error('name') <div class="a-error">{{ $message }}</div> @enderror
            </div>

            <div class="a-field">
                <label class="a-label">닉네임</label>
                <input class="a-input" name="nickname" value="{{ old('nickname') }}" placeholder="정산담당1" autocomplete="off">
                @error('nickname') <div class="a-error">{{ $message }}</div> @enderror
            </div>

            <div class="a-field">
                <label class="a-label">휴대폰 (숫자만 10~11자리)</label>
                <input class="a-input" name="phone" value="{{ old('phone') }}" placeholder="01012345678" autocomplete="off">
                @error('phone') <div class="a-error">{{ $message }}</div> @enderror
            </div>

            <div class="a-field">
                <label class="a-label">역할(Role)</label>
                <select class="a-input" name="role">
                    @php $sel = old('role', 'support'); @endphp
                    @foreach($roles as $r)
                        <option value="{{ $r['code'] }}" {{ $sel===$r['code']?'selected':'' }}>
                            {{ $r['label'] }}
                        </option>
                    @endforeach
                </select>
                @error('role') <div class="a-error">{{ $message }}</div> @enderror
            </div>

            <div style="display:flex; gap:8px; flex-wrap:wrap; margin-top:14px;">
                <button class="lbtn lbtn--primary lbtn--wide" type="submit">등록</button>
                <a class="lbtn lbtn--ghost" href="{{ route('admin.admins.index', $filters ?? []) }}">취소</a>
            </div>
        </div>
    </form>
@endsection
