<form role="form" id="form-edit-hostel">
    <div class="form-body">
        <div class="row">
            <div class="col-md-8">
                <div class="form-group">
                    <label>Tên nhà <span class="required" aria-required="true"> (*) </span></label>
                    <input type="text" class="form-control" placeholder="" name="name" value="{{ $hostel->name }}">
                </div>
            </div>
            <div class="col-md-4">

                <div class="form-group">
                    <label>Loại nhà <span class="required" aria-required="true"> (*) </span></label>
                    @php $hostelTypes = \App\Models\HostelType::all(); @endphp
                    <select class="form-control" name="type">
                        @foreach($hostelTypes as $hostelType)
                            <option @if($hostel->type == $hostelType->id) selected=""
                                    @endif value="{{ $hostelType->id }}">{{ $hostelType->name }}</option>
                        @endforeach

                    </select>
                </div>

            </div>
        </div>
        <div class="row">
            <div class="col-md-8">
                <div class="form-group">
                    <label>Địa chỉ <span class="required" aria-required="true"> (*) </span></label>
                    <input type="text" class="form-control" name="address" value="{{ $hostel->address }}">
                    <span class="help-block"> (Không nhập địa chỉ Phường, Xã, Tỉnh, Thành phố) </span>
                </div>
            </div>
            <div class="col-md-4">

                <div class="form-group">
                    <label>Hình thức cho thuê <span class="required" aria-required="true"> (*) </span>
                        <a href="#explain-type-rent" data-toggle="modal"><span
                                    class="glyphicon glyphicon-question-sign"></span></a></label>
                    <select class="form-control" name="type_rent" disabled>

                        <option @if($hostel->type_rent == \App\Models\Hostel::TYPE_RENT_ALL) selected
                                @endif value="{{ \App\Models\Hostel::TYPE_RENT_ALL }}">Bao phòng
                        </option>
                        <option @if($hostel->type_rent == \App\Models\Hostel::TYPE_RENT_EVERY) selected
                                @endif value="{{ \App\Models\Hostel::TYPE_RENT_EVERY }}">Ký túc xá
                        </option>

                    </select>
                </div>
            </div>
        </div>
        <div class="row">

            <div class="col-md-4">

                <div class="form-group">
                    <label>Tỉnh / TP <span class="required" aria-required="true"> (*) </span></label>
                    <select class="form-control select2" name="province_id" id="province_id">
                        @foreach($provinces as $province)
                            <option @if($province->provinceid == $hostel->province_id) selected @endif
                            value="{{ $province->provinceid }}">{{ $province->name }}</option>
                        @endforeach

                    </select>
                </div>
            </div>
            <div class="col-md-4">

                <div class="form-group">
                    <label>Quận / Huyện <span class="required" aria-required="true"> (*) </span></label>
                    <select class="form-control select2" name="district_id" id="district_id">

                        @php if(!empty($hostel->province_id)) {
                            $districts = DB::table('district')->where('provinceid', $hostel->province_id)->get();
                        } else {
                            $districts = null;
                        }@endphp

                        @if(!empty($districts))
                            <option value="" selected disabled>Quận / Huyện</option>
                            @foreach($districts as $district)
                                <option @if($district->districtid == $hostel->district_id) selected=""
                                        @endif value="{{ $district->districtid }}">{{ $district->name }}</option>
                            @endforeach
                        @else
                            <option value="" selected disabled>Quận / Huyện</option>
                        @endif

                    </select>
                </div>
            </div>
            <div class="col-md-4">

                <div class="form-group">
                    <label>Phường / Xã <span class="required" aria-required="true"> (*) </span></label>
                    <select class="form-control select2" name="ward_id" id="ward_id">
                        @php if(!empty($hostel->district_id)) {
                            $wards = DB::table('ward')->where('districtid', $hostel->district_id)->get();
                        } else {
                            $wards = null;
                        }@endphp

                        @if(!empty($wards))

                            <option value="" selected disabled>Xã / Phường</option>
                            @foreach($wards as $ward)
                                <option @if($ward->wardid == $hostel->ward_id) selected=""
                                        @endif value="{{ $ward->wardid }}">{{ $ward->name }}</option>
                            @endforeach
                        @else
                            <option value="" selected disabled>Xã / Phường</option>
                        @endif
                    </select>
                </div>
            </div>
        </div>
        {{--<div class="row">--}}
            {{--<div class="col-md-4">--}}

                {{--<div class="form-group">--}}
                    {{--<label>Chủ sở hữu <span class="required" aria-required="true"> (*) </span></label>--}}
                    {{--<input type="text" class="form-control" name="owner_name" value="{{ $hostel->owner_name }}">--}}
                {{--</div>--}}
            {{--</div>--}}
            {{--<div class="col-md-4">--}}

                {{--<div class="form-group">--}}
                    {{--<label>Số CMTND <span class="required" aria-required="true"> (*) </span></label>--}}
                    {{--<input type="text" class="form-control" name="owner_id_number"--}}
                           {{--value="{{ $hostel->owner_id_number }}">--}}
                {{--</div>--}}
            {{--</div>--}}
            {{--<div class="col-md-4">--}}

                {{--<div class="form-group">--}}
                    {{--<label>Số điện thoại <span class="required" aria-required="true"> (*) </span></label>--}}
                    {{--<input type="text" class="form-control" name="owner_phone" value="{{ $hostel->owner_phone }}">--}}
                {{--</div>--}}
            {{--</div>--}}
        {{--</div>--}}
        <div class="row">

            <div class="col-md-12">
                <div class="row">
                    {{--<div class="col-md-4">--}}

                        {{--<div class="form-group">--}}
                            {{--<label>Email</label>--}}
                            {{--<input type="text" class="form-control" name="owner_email"--}}
                                   {{--value="{{ $hostel->owner_email }}">--}}
                        {{--</div>--}}
                    {{--</div>--}}
                    <div class="col-md-6">

                        <div class="form-group">
                            <label>Ngày ghi chỉ số điện nước <span class="required" aria-required="true"> (*) </span>

                                <a href="#explain-date-ew" data-toggle="modal"><span
                                            class="glyphicon glyphicon-question-sign"></span></a>
                            </label>
                            <select class="form-control select2" name="date_ew" id="edit-hostel-date-ew">
                                @for($i = 1; $i <= 31; $i++)
                                    <option @if($hostel->date_ew == $i) selected
                                            @endif value="{{ $i }}"> {{ $i }}</option>
                                @endfor
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">

                        <div class="form-group">
                            <label>Ngày chốt sổ - tính phí <span class="required" aria-required="true"> (*) </span>

                                <a href="#explain-date-money" data-toggle="modal"><span
                                            class="glyphicon glyphicon-question-sign"></span></a>
                            </label>
                            <select class="form-control select2" name="date_money">
                                @for($i = 1; $i <= 31; $i++)
                                    <option @if($hostel->date_money == $i) selected
                                            @endif value="{{ $i }}"> {{ $i }}</option>
                                @endfor
                            </select>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        @if(request()->input('type') == 'verify')
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">

                        <div class="mt-checkbox-list">
                            <label class="mt-checkbox">
                                <input type="checkbox" name="status_confirm" @if($hostel->status_confirm == 1) checked @endif> Đã được xác thực
                                <span></span>
                            </label>
                        </div>

                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label>Ghi chú</label>
                        <textarea class="form-control" name="note"></textarea>

                    </div>
                </div>
            </div>
        @endif
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">

                    <div class="mt-checkbox-list">
                        <label class="mt-checkbox">
                            <input type="checkbox" name="is_display" @if($hostel->is_display) checked @endif> Hiển thị
                            trên cổng thông tin itro
                            <span></span>
                        </label>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <ul class="nav nav-tabs">
        <li class="active">
            <a href="#edit_tab_1_1" data-toggle="tab" aria-expanded="true"> Tiện ích </a>
        </li>
        <li>
            <a href="#edit_tab_1_2" data-toggle="tab" aria-expanded="false"> Nội quy </a>
        </li>
        <li>
            <a href="#edit_tab_1_3" data-toggle="tab" aria-expanded="false"> Vị trí trên bản đồ </a>
        </li>
        <li>
            <a href="#edit_tab_1_4" data-toggle="tab" aria-expanded="false"> Hình ảnh </a>
        </li>
        <li>
            <a href="#edit_tab_1_5" data-toggle="tab" aria-expanded="false"> Mô tả chi tiết </a>
        </li>

    </ul>
    <div class="tab-content">
        <div class="tab-pane fade in active" id="edit_tab_1_1">
            <div class="row">

                @php $hostelAmenities = $hostel->amenities2->pluck('id')->toArray();@endphp

                @foreach($amenities as $amenity)
                    <div class="col-md-3">

                        <label class="mt-checkbox mt-checkbox-outline ws-nr">
                            <input type="checkbox" @if(in_array($amenity->id, $hostelAmenities)) checked=""
                                   @endif name="amenities[]" value="{{ $amenity->id }}">
                            @if(!empty($amenity->web_image))
                                <img src="/files/{{ $amenity->web_image }}" class="svg"
                                     style="max-height: 18px; max-width: 18px; margin-right: 3px">
                            @else
                                <img src="/frontend3/amenity.svg" class="svg"
                                     style="max-height: 18px; max-width: 18px; margin-right: 3px">
                            @endif
                            {{ $amenity->name }}
                            <span></span>
                        </label>

                    </div>
                @endforeach

                <div class="col-md-12 text-center">
                    <hr style="border-top: 1px dashed">
                    <p>Nếu nhà của bạn có tiện ích không xuất hiện trong danh sách. Hãy ấn nút "Bổ sung tiện ích" để
                        thêm</p>
                    <button class="btn btn-success" id="btn-add-amenity-edit-hostel">Bổ sung tiện ích</button>
                </div>

                <div class="col-md-12">
                    <div class="row" id="user_edit_amenities">

                    </div>
                </div>


            </div>
        </div>
        <div class="tab-pane fade" id="edit_tab_1_2">
            <div class="row">

                @php $hostelPolicies = $hostel->policies->pluck('id')->toArray();@endphp
                @foreach($policies as $policy)
                    <div class="col-md-4">

                        <label class="mt-checkbox mt-checkbox-outline ws-nr">
                            <input type="checkbox" @if(in_array($policy->id, $hostelPolicies)) checked
                                   @endif name="policies[]" value="{{ $policy->id }}">

                            @if(!empty($policy->web_image))
                                <img src="/files/{{ $policy->web_image }}" class="svg"
                                     style="max-height: 18px; max-width: 18px; margin-right: 3px">
                            @else
                                <img src="/frontend3/policy.svg" class="svg"
                                     style="max-height: 18px; max-width: 18px; margin-right: 3px">
                            @endif

                            {{ $policy->name }}
                            <span></span>
                        </label>

                    </div>
                @endforeach
                <div class="col-md-12 text-center">
                    <hr style="border-top: 1px dashed">
                    <p>Nếu nhà của bạn có nội quy không xuất hiện trong danh sách. Hãy ấn nút "Bổ sung nội quy" để
                        thêm</p>
                    <button class="btn btn-success" id="btn-add-policy-edit-hostel">Bổ sung nội quy</button>
                </div>
                <div class="col-md-12">
                    <div class="row" id="user_policies">

                    </div>
                </div>

            </div>
        </div>
        <div class="tab-pane fade" id="edit_tab_1_3">
            <button class="btn btn-success" type="button" id="btn-get-current-position-edit"
                    style="margin-top: 10px; margin-bottom: 10px">Lấy tọa độ hiện tại
            </button>
            <label class="control-label" style="display: inline-block; margin-left: 15px; margin-right: 15px">Hoặc nhập
                vị trí tương đối xung quanh</label>
            <div class="form-group" style="display: inline-block; width: 300px">
                <input type="text" class="form-control" id="query_place_edit">
            </div>
            <div id="map_edit">

            </div>
            <input type="hidden" name="lat" id="lat-e" value="{{ $hostel->lat }}">
            <input type="hidden" name="lng" id="lng-e" value="{{ $hostel->lng }}">
        </div>
        <div class="tab-pane fade" id="edit_tab_1_4">
            <div class="center text-center" style="margin-top: 15px">

                <p>Hãy chọn ít nhất 1 hình ảnh thật về nhà của bạn để tin đăng hấp dẫn hơn và và giúp khách thuê thấy được ảnh nhà của bạn</p>
                <button class="btn btn-success" id="btn-add-edit-image-hostel">Thêm ảnh nhà</button>
                <hr style="border-top: 1px dashed">
            </div>
            @php
                $images = DB::table('hostel_images')->where('hostel_id', $hostel->id)->get(); @endphp

            <div class="row">
                <div class="col-md-12">
                    <div class="row" id="hostel_images_list">

                        @if($images->count() > 0)
                            @foreach($images as $image)
                                <div class="col-sm-6 col-md-3" style="margin-top: 15px">
                                    <i class="fa fa-trash btn-delete-hostel-image" data-id="{{ $image->id }}" style="position: absolute; top: 0px; right: 0px; padding: 10px 10px;
    font-size: 18px; margin-right: 15px;
    background: red; color: white"></i>
                                    <a href="javascript:;" class="thumbnail"
                                       style="width: 100%; height: 179px; background-image: url('/files/{{ $image->image }}');
                                               background-size: contain; background-repeat: no-repeat">
                                        {{--<img src="/files/{{ $image->image }}"--}}
                                        {{--alt="100%x180" style="height: 180px; width: 100%; display: block;"--}}
                                        {{-->--}}
                                    </a>
                                    <select class="form-control" name="image-types[{{ $image->id }}][]">

                                        <option @if($image->type == \App\Models\Room::IMAGE_LIVING_ROOM) selected
                                                @endif value="{{ \App\Models\Room::IMAGE_LIVING_ROOM }}">Ảnh phòng
                                            khách
                                        </option>
                                        <option @if($image->type == \App\Models\Room::IMAGE_BED_ROOM) selected
                                                @endif value="{{ \App\Models\Room::IMAGE_BED_ROOM }}">Ảnh phòng ngủ
                                        </option>
                                        <option @if($image->type == \App\Models\Room::IMAGE_KITCHEN) selected
                                                @endif value="{{ \App\Models\Room::IMAGE_KITCHEN }}">Ảnh nhà bếp
                                        </option>
                                        <option @if($image->type == \App\Models\Room::IMAGE_OTHER) selected
                                                @endif value="{{ \App\Models\Room::IMAGE_OTHER }}">Vị trí khác
                                        </option>
                                    </select>
                                </div>
                            @endforeach
                        @endif
                    </div>

                </div>
            </div>


            <div class="row">
                <div class="col-md-12">
                    <div class="row" id="hostel_images">
                    </div>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="edit_tab_1_5">
            <textarea class="form-control ckeditor" name="desc" rows="6">{!!  $hostel->desc !!}</textarea>
        </div>
    </div>

</form>