<form role="form" id="form-edit-spend">
    {!! csrf_field() !!}
    <div class="form-body">
        <input type="hidden" name="id" value="{{ $item->id }}">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label>Chọn nhà <span class="required" aria-required="true"> (*) </span></label>
                    <select class="form-control" name="hostel_id" id="hostel_id">
                        @php
                        
                            $hostelArrs = \App\Models\Hostel::where('owner_id', auth('backend')->user()->id)->pluck('id')->toArray();
                            if (auth('backend')->user()->type == \App\User::STAFF) {
                                $hostelArrs = \App\Components\Functions::getHostelArrStaff();
                            }
                            $hostels = \App\Models\Hostel::whereIn('id', $hostelArrs)->get();

                        @endphp

                        <option value="">Vui lòng chọn</option>
                        @foreach($hostels as $hostel)
                            <option @if($hostel->id == $item->hostel_id) selected
                                    @endif  value="{{ $hostel->id }}"> {{ $hostel->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label>Chọn phòng</label>
                    <select class="form-control" name="room_id" id="room_id">
                        @php
                            $hostelArrs = \App\Models\Hostel::where('owner_id', auth('backend')->user()->id)->pluck('id')->toArray();
                            if (auth('backend')->user()->type == \App\User::STAFF) {
                                $hostelArrs = \App\Components\Functions::getHostelArrStaff();
                            }
                            $rooms = \App\Models\Room::whereIn('hostel_id', $hostelArrs)->get()->sortBy(function($item) {
                            return $item->name;
                            });

                        @endphp

                        <option value="">Vui lòng chọn (nếu chi cho phòng)</option>
                        @foreach($rooms as $room)
                            <option @if($room->id == $item->room_id) selected
                                    @endif  value="{{ $room->id }}"> {{ $room->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </div>
        <div class="row">

            <div class="col-md-6">
                <div class="form-group">
                    @if($item->type == \App\Models\CollectSpend::COLLECT)
                        <label>Lý do thu <span class="required" aria-required="true"> (*) </span></label>
                    @else
                        <label>Lý do chi <span class="required" aria-required="true"> (*) </span></label>
                    @endif
                    <input class="form-control" name="name" type="text" value="{{ $item->name }}">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    @if($item->type == \App\Models\CollectSpend::COLLECT)
                        <label>Ngày thu <span class="required" aria-required="true"> (*) </span></label>
                    @else
                        <label>Ngày chi <span class="required" aria-required="true"> (*) </span></label>
                    @endif
                    <input class="form-control datepicker" name="date_action" type="text"
                           value="{{ empty($item->date_action) ? '' : \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $item->date_action)->format('d/m/Y')  }}">
                </div>
            </div>
        </div>
        <div class="row">

            <div class="col-md-6">
                <div class="form-group">
                    <label>Số tiền <span class="required" aria-required="true"> (*) </span></label>
                    <input class="form-control price-r" name="amount" type="text"
                           value="{{ number_format($item->amount, 0, '.', '.') }}">
                </div>
            </div>
            @if($item->type == \App\Models\CollectSpend::SPEND)
                <div class="col-md-6">
                    <div class="form-group">
                        <label>Người nhận <span class="required" aria-required="true"> (*) </span></label>
                        <input class="form-control" name="receiver" type="text" id="receiver"
                               value="{{ $item->receiver }}">
                    </div>
                </div>
            @else
                <div class="col-md-6">
                    <div class="form-group">
                        <label>Người thu <span class="required" aria-required="true"> (*) </span></label>
                        <input class="form-control" name="receiver" type="text" id="receiver"
                               value="{{ $item->receiver }}">
                    </div>
                </div>
            @endif

        </div>
        @if($item->type == \App\Models\CollectSpend::COLLECT)
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label>Người  nộp tiền <span class="required" aria-required="true"> (*) </span></label>
                    <input class="form-control" name="payer" type="text" value="{{ $item->payer }}">
                </div>
            </div>

        </div>
        @endif

        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    @if($item->type == \App\Models\CollectSpend::COLLECT)
                        <label>Hình thức thu <span class="required" aria-required="true"> (*) </span></label>
                    @else
                        <label>Hình thức chi <span class="required" aria-required="true"> (*) </span></label>
                    @endif
                    <select class="form-control" name="payment_method">

                        <option @if($item->payment_method == \App\Models\CollectSpend::MONEY) selected
                                @endif value="{{ \App\Models\CollectSpend::MONEY }}">Tiền mặt
                        </option>
                        <option @if($item->payment_method == \App\Models\CollectSpend::BANK) selected
                                @endif value="{{ \App\Models\CollectSpend::SPEND }}">Chuyển khoản
                        </option>
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label>Ghi chú</label>
                    <input class="form-control" name="note" type="text" value="{{ $item->note }}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label>Loại phiếu thu</label>
                    <select class="form-control" name="type_collect_id">
                        <option value="">Vui lòng chọn</option>
                        @foreach($types as $type)
                            <option @if($type->id == $item->type_collect_id)  selected @endif value="{{ $type->id }}"> {{ $type->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label>Đính kèm file</label>
                    <input type="file" multiple name="files[]">
                </div>
            </div>
        </div>
        @if($item->files->count())
            <div class="row">
                <div class="col-md-12">
                    <label>File đã có</label>
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th> Tên file</th>
                            <th> Hành động</th>
                            {{--<th width="25%"> Ghi chú</th>--}}
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($item->files as $file)
                            <tr>
                                <td><a href="{{ $file->file }}" target="_blank">{{ $file->name }}</a></td>
                                <td>
                                    <button data-id="{{ $file->id }}" class="btn btn-danger btn-delete-cp-file">Xóa</button>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        @endif
    </div>
</form>