@extends('layouts.web')

@section('css')
<link rel="stylesheet" href="{{ asset('css/bootstrap-select.min.css') }}">
<link rel="stylesheet" href="{{ asset('css/bootstrap-datepicker.min.css') }}">
<link rel="stylesheet" href="{{ asset('css/icheck-bootstrap.min.css') }}">
<link rel="stylesheet" href="https://earthchie.github.io/jquery.Thailand.js/jquery.Thailand.js/dist/jquery.Thailand.min.css">
@endsection

@section('content')
<div class="container-fluid pt-3">
    <form action="{{ route('teacher.update', $teacher->id) }}"
            novalidate class="{{ ($errors->any()) ? 'was-validated' : 'needs-validation' }}"
            method="post"
    >
    @csrf
    @method('PUT')
        <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-sm-12 col-md-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($teacher->title == "นาย") selected @endif>นาย</option>
                                      <option value="นาง" @if($teacher->title == "นาง") selected @endif>นาง</option>
                                      <option value="นางสาว" @if($teacher->title == "นางสาว") selected @endif>นางสาว</option>
                                    </select>
                                    @error('gender')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-4">
                                <div class="form-group">
                                    <label for="firstname">ชื่อ <span class="text-red">*</span></label>
                                    <input type="text" class="form-control" id="firstname" name="firstname" value="{{ $teacher->firstname }}" placeholder="ชื่อ" required>
                                    @error('lastnfirstnameame')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-4">
                                <div class="form-group">
                                    <label for="lastname">นามสกุล <span class="text-red">*</span></label>
                                    <input type="text" class="form-control" id="lastname" name="lastname" value="{{ $teacher->lastname }}" placeholder="นามสกุล" required>
                                    @error('lastname')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-2">
                                <div class="form-group">
                                    <label for="nickname">ชื่อเล่น</label>
                                    <input type="text" class="form-control" id="nickname" name="nickname" value="{{ $teacher->nickname }}" placeholder="ชื่อเล่น" >
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-md-3">
                                <div class="form-group">
                                    <label for="idCard">เลขที่บัตรประาชาชน <span class="text-red">*</span></label>
                                    <input type="text" class="form-control" id="idCard" name="idCard" placeholder="เลขที่บัตรประาชาชน" value="{{ $teacher->idcard }}" required>
                                    @error('idCard')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-3">
                                <div class="form-group">
                                    <label for="birthdate">วันเกิด <span class="text-red">*</span></label>
                                    <div class="input-group mb-3">
                                        <input type="hidden" value="{{ $teacher->birthdate }}" id="birthdateValue" >
                                        <input type="text" class="form-control" id="birthdate" name="birthdate" placeholder="วันเกิด" autocomplete="off"  required>
                                        <div class="input-group-append">
                                            <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                                        </div>
                                    </div>
                                    @error('birthdate')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-6">
                                <div class="form-group">
                                    <label for="address">ที่อยู่</label>
                                    <input type="text" id="address" name="address" class="form-control" value="{{ $teacher->address }}" placeholder="ที่อยู่">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-md-4">
                                <div class="form-group">
                                    <label for="district">ตำบล / แขวง</label>
                                    <input type="text" name="district" id="district" class="form-control" value="{{ $teacher->district }}" placeholder="ตำบล / แขวง">
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-4">
                                <div class="form-group">
                                    <label for="amphoe">อำเภอ / เขต</label>
                                    <input type="text" name="amphoe" id="amphoe" class="form-control" value="{{ $teacher->amphoe }}" placeholder="อำเภอ / เขต">
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-4">
                                <div class="form-group">
                                    <label for="province">จังหวัด</label>
                                    <input type="text" name="province" id="province" class="form-control" value="{{ $teacher->province }}" placeholder="จังหวัด">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-md-3">
                                <div class="form-group">
                                    <label for="phone1">หมายเลขโทรศัพท์ 1 <span class="text-red">*</span></label>
                                    <input type="number" name="phone1" id="phone1" class="form-control" value="{{ $teacher->phone_1 }}" placeholder="หมายเลขโทรศัพท์" required>
                                    @error('phone1')
                                    <div class="text-danger">{{  $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-3">
                                <div class="form-group">
                                    <label for="phone2">หมายเลขโทรศัพท์ 2</label>
                                    <input type="number" name="phone2" id="phone2" class="form-control" value="{{ $teacher->phone_2 }}" placeholder="หมายเลขโทรศัพท์">
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-6">
                                <div class="form-group">
                                    <label>ประเภท <span class="text-red">*</span></label>
                                    <div>
                                        <div class="icheck-nephritis icheck-inline">
                                            <input type="radio" id="all" name="teacherType" value="a" @if($teacher->type == "a") checked @endif required>
                                            <label for="all">ทั้งสอนและสแกน</label>
                                        </div>
                                        <div class="icheck-nephritis icheck-inline">
                                            <input type="radio" id="teach" name="teacherType" value="t" @if($teacher->type == "t") checked @endif>
                                            <label for="teach">สอนอย่างเดียว</label>
                                        </div>
                                        <div class="icheck-nephritis icheck-inline">
                                            <input type="radio" id="scan" name="teacherType" value="s" @if($teacher->type == "s") checked @endif>
                                            <label for="scan">สแกนอย่างเดียว</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>  <!-- div card body -->

                </div>
                <div class="row mt-3">
                    <div class="col-12">
                        <div style="float:left">
                            <a href="{{ route('teacher.index') }}" class="btn btn-outline-secondary"><i class="fas fa-chevron-left"></i> ย้อนกลับ</a>
                        </div>
                        <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>

                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
@endsection

@section('footerscript')
<script src="{{ asset('js/bootstrap-select.min.js') }}"></script>
<script src="{{ asset('js/bootstrap-datepicker-custom.min.js') }}"></script>
<script src="{{ asset('js/bootstrap-datepicker.th.min.js') }}"></script>
<script src="{{ asset('js/JQL.min.js') }}"></script>
<script src="{{ asset('js/typeahead.bundle.js') }}"></script>
<script src="{{ asset('js/jquery.Thailand.min.js') }}"></script>
<script src="{{ asset('js/custom.js') }}"></script>
<script>
    $(document).ready(function(){
        $('.selectpicker').selectpicker();

        $('#birthdate').datepicker({
            format: 'dd/mm/yyyy',
            autoclose: true,
            language: 'th',
            orientation: 'bottom',
        }).datepicker("update", convertDateforPicker('birthdateValue'));

        $.Thailand({
            $district: $('#district'),
            $amphoe: $('#amphoe'),
            $province: $('#province'),
            $zipcode: $('#zipcode')
        });
    });
</script>
@endsection
