@extends('layouts.web')

@section('css')
<link href="{{ asset('css/bootstrap-select.min.css') }}" rel="stylesheet" />
@endsection

@section('content')
<div class="container-fluid pt-3">
    <form action="{{ route('user.info_update') }}"
            novalidate class="{{ ($errors->any()) ? 'was-validated' : 'needs-validation' }}"
            method="post"
    >
    @csrf
        <input type="hidden" name="uid" value="{{$user->id}}">
        <div class="row">
            <div class="col-12">
                <div class="card card-outline card-success">
                    <div class="card-header">
                        <h3 class="card-title">ข้อมูลผู้ใช้ระบบ</h3>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="username">ชื่อผู้ใช้ <span class="text-red">*</span></label>
                                    <input type="text" class="form-control" id="username" name="username" value="{{ $user->username }}" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-2">
                                <div class="form-group">
                                    <label for="title">คำนำหน้า <span class="text-red">*</span></label>
                                    <select id="title" name="title" class="selectpicker show-menu-arrow form-control" required>
                                      <option value="นาย" @if($user->title == "นาย") selected @endif>นาย</option>
                                      <option value="นาง" @if($user->title == "นาง") selected @endif>นาง</option>
                                      <option value="นางสาว" @if($user->title == "นางสาว") selected @endif>นางสาว</option>
                                    </select>
                                    @error('gender')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="firstname">ชื่อ <span class="text-red">*</span></label>
                                    <input type="text" class="form-control" id="firstname" name="firstname" value="{{ $user->firstname }}" placeholder="ชื่อ" required>
                                    @error('firstname')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="lastname">นามสกุล</label>
                                    <input type="text" class="form-control" id="lastname" name="lastname" value="{{ $user->lastname }}" placeholder="นามสกุล" >
                                </div>
                            </div>
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="phone">หมายเลขโทรศัพท์ <span class="text-red">*</span></label>
                                    <input type="number" name="phone" id="phone" class="form-control" value="{{ $user->phone }}" placeholder="หมายเลขโทรศัพท์" required>
                                    @error('phone')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="email">email</label>
                                    <input type="email" class="form-control  @error('email') is-invalid @enderror" value="{{ $user->email }}" id="email" name="email" placeholder="อีเมล์">
                                </div>
                            </div>
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="branch">สาขา <span class="text-red">*</span></label>
                                    <select id="branch" name="branch" class="selectpicker show-menu-arrow form-control" title="--เลือก--" required>
                                        @foreach ($branchs as $indexKey => $branch)
                                        <option value="{{ $branch->id }}" @if($user->branch_id == $branch->id) selected @endif>{{ $branch->name }}</option>
                                        @endforeach
                                    </select>
                                    @error('branch')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-3">
                                <div class="form-group">
                                    <label for="role">สิทธิ์ <span class="text-red">*</span></label>
                                    <select id="role" name="role" class="selectpicker show-menu-arrow form-control" title="--เลือก--" required>
                                        <option value="superadmin" @if($user->role == "superadmin") selected @endif>Superadmin</option>
                                        <option value="admin" @if($user->role == "admin") selected @endif>Admin</option>
                                        <option value="user" @if($user->role == "user") selected @endif>User</option>
                                    </select>
                                    @error('role')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>  <!-- div card body -->
                </div>
                <div class="row mt-3">
                    <div class="col-12">

                        <div style="float: right">
                            <button type="reset" class="btn btn-outline-secondary" value="reset">ล้างข้อความ</button>
                            <button type="submit" class="btn btn-success ml-2" value="add-course">แก้ไขผู้ใช้ระบบ</button>
                        </div>
    </form>
                        <div style="float:left">
                            <form action="{{ route('user.info') }}" method="get">
                                <button class="btn btn-outline-secondary" type="submit"><i class="fas fa-chevron-left"></i> ย้อนกลับ</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</div>
@endsection

@section('footerscript')
<script src="{{ asset('js/bootstrap-select.min.js') }}"></script>
<script>
    $(document).ready(function(){
        $('.selectpicker').selectpicker();
    });
</script>
@endsection
