@php
$ad_conf = [
    ['code' => 0, 'name' => ''],
    ['code' => 1, 'name' => '未'],
    ['code' => 2, 'name' => '可'],
    ['code' => 3, 'name' => '不可'],
];

$blood = [
    ['code' => 0, 'name' => ''],
    ['code' => 1, 'name' => 'A'],
    ['code' => 2, 'name' => 'B'],
    ['code' => 3, 'name' => 'O'],
    ['code' => 4, 'name' => 'AB'],
];

$birth_month = [
    ['code' => 1, 'name' => 1],
    ['code' => 2, 'name' => 2],
    ['code' => 3, 'name' => 3],
    ['code' => 4, 'name' => 4],
    ['code' => 5, 'name' => 5],
    ['code' => 6, 'name' => 6],
    ['code' => 7, 'name' => 7],
    ['code' => 8, 'name' => 8],
    ['code' => 9, 'name' => 9],
    ['code' => 10, 'name' => 10],
    ['code' => 11, 'name' => 11],
    ['code' => 12, 'name' => 12],
];

$birth_day = [
    ['code' => 1, 'name' => 1],
['code' => 2, 'name' => 2],
['code' => 3, 'name' => 3],
['code' => 4, 'name' => 4],
['code' => 5, 'name' => 5],
['code' => 6, 'name' => 6],
['code' => 7, 'name' => 7],
['code' => 8, 'name' => 8],
['code' => 9, 'name' => 9],
['code' => 10, 'name' => 10],
['code' => 11, 'name' => 11],
['code' => 12, 'name' => 12],
['code' => 13, 'name' => 13],
['code' => 14, 'name' => 14],
['code' => 15, 'name' => 15],
['code' => 16, 'name' => 16],
['code' => 17, 'name' => 17],
['code' => 18, 'name' => 18],
['code' => 19, 'name' => 19],
['code' => 20, 'name' => 20],
['code' => 21, 'name' => 21],
['code' => 22, 'name' => 22],
['code' => 23, 'name' => 23],
['code' => 24, 'name' => 24],
['code' => 25, 'name' => 25],
['code' => 26, 'name' => 26],
['code' => 27, 'name' => 27],
['code' => 28, 'name' => 28],
['code' => 29, 'name' => 29],
['code' => 30, 'name' => 30],
['code' => 31, 'name' => 31],
];

$role=[
['code' => 0, 'name' => '選択してください'],
['code' => 1, 'name' => 'マスター管理者'],
['code' => 2, 'name' => 'ウェブ管理者'],
['code' => 3, 'name' => 'スタッフ'],
];


@endphp
@extends('admin.layouts.base')
@section('styles')
    <script src="/admin/js/upload-image.js"></script>
@endsection
@section('contents')
<div class="mt5">
    @include('admin.objects.components.regist-band', ['title' => '社員情報', 'conf_url' => '/staff/'.$user_detail['employee_number'].'.html'])
    <div class="user_regist">
        @if($errors->any())
        <div class="error">
        <ul>
            @foreach($errors->all() as $message)
            <li>{{ $message }}</li>
            @endforeach
        </ul>
        </div>
        @endif
        <form method="POST" action="{{ route('staff-edit', ['id'=>$user_detail['employee_number']]) }}" enctype="multipart/form-data" id="enter-off">
        {{ csrf_field() }}
        @include('admin.objects.components.hidden', ['name' => 'role', 'value' => $type])
        @include('admin.objects.components.hidden', ['name' => 'company_id', 'value' => $user->company_id])

            <div>
                <table>
                    <tr>
                        <th>社員ID</th>
                        <td>{{$user_detail['employee_number']}}</td>
                    </tr>
                    <tr>
                        <th>データベース権限</th><!--下記要修正-->
                        <td>
                          @if($user['role']==1)
                          @include('admin.objects.components.selectbox', ['name' => 'role', 'class' => 'mb-2', 'options' => $role, 'selected' => $user_info[0]['role']])
                          <!--<select class="c-selectbox  mb-2 " name="role">
                            <option value="">選択してください</option>
                            <option value="">----</option>
                            <option value="1" {{ $user_info[0]["role"] == 1 ? "selected" : "" }}>マスター管理者</option>
                            <option value="2" {{ $user_info[0]["role"] == 2 ? "selected" : "" }}>ウェブ管理者</option>
                            <option value="3" {{ $user_info[0]["role"] == 3 ? "selected" : "" }}>スタッフ</option>
                          </select>-->
                          @elseif($user['role']==2)
                          ウェブ管理者
                          @elseif($user['role']==3)
                          スタッフ
                          @elseif($user['role']==null ||$user['role'] == 0 )
                            未選択
                          @endif
                        </td>
                    </tr>
                    <tr>
                        <th>氏名</th>
                        <td>
                            @include('admin.objects.components.input', ['name' => 'last_name', 'class' => 'w200', 'placeholder' => '名字', 'value' => $user_detail['last_name']])
                            @include('admin.objects.components.input', ['name' => 'first_name', 'class' => 'w200', 'placeholder' => '名前', 'value' => $user_detail['first_name']])
                        </td>
                    </tr>
                    <tr>
                        <th>氏名(フリガナ)</th>
                        <td>
                        @include('admin.objects.components.input', ['name' => 'last_name_kana', 'class' => 'w200', 'placeholder' => '名字（フリガナ）', 'value' => $user_detail['last_name_kana']])
                            @include('admin.objects.components.input', ['name' => 'first_name_kana', 'class' => 'w200', 'placeholder' => '名字（フリガナ）', 'value' => $user_detail['first_name_kana']])
                        </td>
                    </tr>
                    <tr>
                        <th>メールアドレス</th>
                        <td>
                            @include('admin.objects.components.input', ['name' => 'email', 'class' => 'w200', 'placeholder' => 'メールアドレス', 'value' => $user_info[0]['email']])
                        </td>
                    </tr>
                    @if(empty($user_info[0]['password']))
                        <tr style="display: table-row" id="password">
                            <th>パスワード</th>
                            <td>
                                <input type="password" name="password"  class="w200" placeholder="******" >
                            </td>
                        </tr>
                        <tr style="display: table-row" id="password_confirmation">
                            <th>パスワード（確認用）</th>
                            <td>
                                <input type="password" name="password_confirmation"  class="w200" placeholder="******" >
                            </td>
                        </tr>
                        <tr style="display: none" id="changePassword">
                            <th>パスワード</th>
                            <td>
                                <div>
                                    <h5 style="color: #3490dc;text-decoration: underline; cursor: pointer;">パスワード変更</h5>
                                </div>
                            </td>
                        </tr>
                    @else
                        <tr style="display: none" id="password">
                            <th>パスワード</th>
                            <td>
                                <input type="password" name="password"  class="w200" placeholder="******" >
                            </td>
                        </tr>
                        <tr style="display: none" id="password_confirmation">
                            <th>パスワード（確認用）</th>
                            <td>
                                <input type="password" name="password_confirmation"  class="w200" placeholder="******" >
                            </td>
                        </tr>
                        <tr style="display: table-row" id="changePassword">
                            <th>パスワード</th>
                            <td>
                                <div  id="changePasswordDiv" style="display: inline-block">
                                    <h5 style="color: #3490dc;
                                            cursor: pointer;
                                            margin: 0;
                                            padding: 3px;
                                            font-size: 15px;
                                            ">
                                        パスワード変更
                                    </h5>
                                </div>
                            </td>
                        </tr>
                    @endif
                    <tr>
                        <th>店舗カテゴリ</th>
                        <td>
                        @include('admin.objects.components.selectbox', ['name' => 'store', 'class' => 'mb-2', 'options' => $store, 'selected' => $user_detail['store']])
                        </td>
                    </tr>
                    <tr>
                        <th>部署</th>
                        <td>
                            @include('admin.objects.components.input', ['name' => 'department', 'class' => 'w200', 'placeholder' => '部署', 'value' => $user_detail['department']])
                        </td>
                    </tr>
                    <tr>
                        <th>役職</th>
                        <td>
                            @include('admin.objects.components.input', ['name' => 'position', 'class' => 'w200', 'placeholder' => '役職', 'value' => $user_detail['position']])
                        </td>
                    </tr>
                    <tr>
                        <th>誕生日</th>
                        <td>
                        @include('admin.objects.components.selectbox', ['name' => 'birth_month', 'class' => 'mb-2', 'options' => $birth_month, 'selected' => $user_detail['birth_month']])月
                        @include('admin.objects.components.selectbox', ['name' => 'birth_day', 'class' => 'mb-2', 'options' => $birth_day, 'selected' => $user_detail['birth_day']])日
                        </td>
                    </tr>
                    <tr>
                        <th>血液型</th>
                        <td>
                        @include('admin.objects.components.selectbox', ['name' => 'blood', 'class' => 'mb-2', 'options' => $blood, 'selected' => $user_detail['blood_type']])
                        </td>
                    </tr>
                    @if(auth()->user()->company_id === 3)
                        <tr>
                            <th>資格</th>
                            <td>
                                @include('admin.objects.components.input', ['name' => 'certification', 'class' => 'w500', 'value' => $user_detail['certification'], 'placeholder' => '例：宅地建物取引士、３級ファイナンシャルプラナー技能士など'])
                            </td>
                        </tr>
                        <tr>
                            <th>出身大学</th>
                            <td>
                                @include('admin.objects.components.input', ['name' => 'college', 'class' => 'w500','value' => $user_detail['college'], 'placeholder' => '出身大学を入力してください。'])
                            </td>
                        </tr>
                        <tr>
                            <th>住まい</th>
                            <td>
                                @include('admin.objects.components.input', ['name' => 'residence', 'class' => 'w500', 'value' => $user_detail['residence'], 'placeholder' => 'OO市'])
                            </td>
                        </tr>
                    @endif

                    <tr>
                        <th>顔写真</th>
                        <td class="d-flex">
                            <label class="p-imgupload__area flex-center" for="fileSingleInput">
                                @if(isset($user_detail->file_path) && $user_detail->file_path !== '')
                                    <img src="{{ $user_detail->file_path . '?v=' . time() }}" width="200" />
                                @endif
                                <canvas style="display: none;" name="canvas_floor" width="0" height="0"></canvas>
                                <p class="p-imgupload__text">クリックまたは<br>ドラッグ&amp;ドロップ</p>
                                <input id="fileSingleInput" type="file" name="file_single_input" style="display:none;">
                                <input type="hidden" name="file_path" value="{{$file_path??''}}">
                            </label>
                            <div class="ml10">
                            @include('admin.objects.components.hidden', ['name' => 'del_photo'])
                            @include('admin.objects.components.btn', ['name' => 'del_staff_photo', 'class' => '', 'title' => '削除', 'type' => 'button'])
                            </div>
                        </td>
                    </tr>
@foreach($customs as $custom)
    @if(isset($custom->name))
                    <tr>
                        <th>{{sprintf("%02d", $loop->iteration)}}<br>{{$custom->name}}</th>
                        <td>
{{--                        @include('admin.objects.components.textarea', ['name' => 'custom'.$loop->iteration, 'class' => 'w500 h150', 'placeholder' => '2０0文字以内で入力してください', 'count' => 200, 'value' => $custom->ans])                        </td>--}}
                        <div class="d-flex">
                            @include('admin.objects.components.textarea', ['name' => 'custom'.$loop->iteration, 'class' => 'w500 h150', 'placeholder' => '2００文字以内で入力してください', 'value' => $custom->ans])
{{--                            @if(auth()->user()->company_id === 3 || auth()->user()->company_id === 4)--}}
                                <div class="form-upload">
                                    <label id="imageArea{{ $loop->iteration + 1 }}" class="p-imgupload__area1 flex-center ml-2"
                                           for="fileSingleInput{{ $loop->iteration + 1 }}">
                                        @if(!empty($custom->file_path))
                                            <img src="{{$custom->file_path. '?v=' . time() }}" width="200" />
                                        @endif
                                        <canvas style="display: none;" name="canvas_floor{{ $loop->iteration + 1 }}" width="0"
                                                height="0"></canvas>
                                        <p class="p-imgupload__text">クリックまたは<br>ドラッグ&amp;ドロップ</p>
                                        <input class="file" id="fileSingleInput{{ $loop->iteration + 1 }}" type="file"
                                               name="file_single_input{{ $loop->iteration + 1 }}"
                                               style="display:none;">
                                        <input type="hidden" name="file_single_input2" value="{{$file_path??''}}">
                                        <input type="hidden" name="custom_file_path{{ $loop->iteration + 1 }}" value="{{str_replace('/storage', 'public', $custom->file_path??'')}}">
                                    </label>
                                    <div class="ml10 text-center">
                                        @include('admin.objects.components.hidden', ['name' => 'del_photo'.($loop->iteration + 1)])
                                        @include('admin.objects.components.btn', ['name' => 'del_staff_photo_cus', 'dataPhoto' => "del_photo".($loop->iteration + 1), 'class' => 'btn-del', 'title' => '削除', 'type' => 'button'])
                                    </div>
                                </div>

{{--                            @endif--}}
                        </div>

                    </tr>
    @endif
@endforeach
                </table>
            </div>
            <div class="search_vendor__btn">
                @include('admin.objects.components.regist-btn', ['class' => '', 'title' => '登録・保存'])
                <a style="padding:10px;display: inline-block" href="{{ $user->role == 1 ? '/admin/staffList' : '/admin/top' }}" class="site_reference">戻る</a>
            </div>
        </form>

    </div>
</div>
@if (session('message'))
    @include('admin.objects.projects.modal-message')
    <script type="text/javascript">
        window.onload = function(){
            var message = '登録・保存しました';
            $('#saved_message').text(message);
            openMessageModal();
        };
    </script>
@endif
@endsection

@section('footer-script')
@endsection
