<div class="p-results-sort">
    <p class="p-results-sort__title">並び替え</p>
    <ul class="p-results-sort__sort">
        @include('business.pages.buyer.partials.sort-link', ['name' => 'price', 'label' => '価格が安い順'])
        @include('business.pages.buyer.partials.sort-link', ['name' => 'created_at', 'label' => '保存日が新しい順'])
    </ul>
</div>
@if(!$article_list->isEmpty())
    <ul class="p-results-image list-unstyled tab-pane active" style="background: transparent">
        @include('business.pages.buyer.partials.form-delete-article')
        @foreach($article_list as $key => $item)
            @if($item != null)
            <li class="p-results-image__li row-house">
                <div class="p-results-image__li-head d-flex justify-content-between">
                    <div>
                        <div class="d-flex p-results-image__title">
                            <label for="cb-{{$key}}" class="label-buyer u-checkbox mb-0" style="background: #ededed">
                                <input type="checkbox" name="" value="{{ $item->building_id }}" id="cb-{{$key}}" class="u-checkbox__obj checkbox-buyer">
                                <span class="u-checkbox__text"></span>
                            </label>
                            <div>
                                <div class="d-flex align-items-center justify-content-between">
                                    <ul class="d-flex list-unstyled">
                                        @if($item->status == 2)
                                            <p class="mt-1 p-results-noimage__tbl-statusbox"><span class="p-results-noimage__tbl-status">商談中</span></p>
                                        @elseif($item->status == 3)
                                            <p class="mt-1 p-results-noimage__tbl-statusbox"><span class="p-results-noimage__tbl-status">契約予定</span></p>
                                        @elseif($item->status == 4)
                                            <p class="mt-1 p-results-noimage__tbl-statusbox"><span class="p-results-noimage__tbl-status">契約済</span></p>
                                        @elseif($item->status == 5)
                                            <p class="mt-1 p-results-noimage__tbl-statusbox"><span class="p-results-noimage__tbl-status">売りやめ</span></p>
                                        @elseif($item->status == 6)
                                            <p class="mt-1 p-results-noimage__tbl-statusbox"><span class="p-results-noimage__tbl-status">保留</span></p>
                                        @endif
                                        @if($item->property==1 or $item->property==2 or $item->property==3)
                                            <li class="p-results-image__mark--land">土地</li>
                                        @elseif($item->property==4 or $item->property==5)
                                            @php
                                                $item->property_name=str_replace('戸建','一戸建て',$item->property_name)
                                            @endphp
                                            @if($item->property_sub==1)
                                                <li class="p-results-image__mark--nhouse">{{$item->property_name}}</li>
                                            @else
                                                <li class="p-results-image__mark--uhouse">{{$item->property_name}}</li>
                                            @endif
                                        @else
                                            <li class="p-results-image__mark--mansion">{{$item->property_name}}</li>
                                        @endif
                                        @if($item->new)
                                            <li class="p-results-image__mark--new">NEW</li>@endif
                                        @if($item->exterior == 2 || $item->interior == 2)
                                            <li class="p-results-image__mark--reform">リフォーム済</li>@endif
                                    </ul>
                                    <p class="p-results-image__li-name">{{$item->name}}<!--（{{$item->main_traffic_station}}）--></p>
                                </div>
                                <div>保存日: {{ $item->created_at->format('Y/m/d H:i') }}</div>
                            </div>
                            @if($item->property == null)<a href="javascript:void(0);"
                                                           class="c-circle-btn__building c-circle-btn"
                                                           id="btnParentDetail{{$item->mansion_id}}"><p>建物</p><img
                                    src="{{ asset('business/img/icon_building.png') }}"></a>@endif
                        </div>
                    </div>
                    <ul class="p-results-image__li-btns d-flex justify-content-end list-unstyled">
                        <li>
                            @include('business.objects.components.circle-btn',
                                ['id' => 'btnCheck', 'class' => 'c-circle-btn__check', 'linkUrl' => '#',
                                'img' => asset('business/img/icon_check.png'), 'title' => '確認'])
                        </li>
                        <li>
                            @include('business.objects.components.circle-btn',
                                ['id' => 'bttnDetail'.$item->building_id, 'class' => 'c-circle-btn__detail', 'linkUrl' => 'javascript:void(0);',
                                'img' => asset('business/img/icon_detail.png'), 'title' => '詳細'])
                        </li>
                    </ul>
                </div>
                @if($item->event_category)
                    <div class="p-results-image__event">
                        @if($item->event_category==1)
                            【現地見学会】
                        @elseif($item->event_category==2)
                            【現地案内会】
                        @elseif($item->event_category==3)
                            【現地販売会】
                        @elseif($item->event_category==4)
                            【オープンハウス】
                        @elseif($item->event_category==5)
                            【オープンルーム】
                        @endif
                        @if($item->event_schedule==1)
                            毎週土日祝
                        @elseif($item->event_schedule==2)
                            毎週土日
                        @elseif($item->event_schedule==3)
                            {{date('n/j', strtotime($item->event_day))}}
                        @elseif($item->event_schedule==4)
                            {{date('n/j', strtotime($item->from_event))}}〜{{date('n/j', strtotime($item->to_event))}}
                        @elseif($item->event_schedule==5)
                            公開中
                        @endif
                        @if($item->from_hour or $item->to_hour)
                            @if($item->from_hour){{$item->from_hour}}:{{sprintf('%02d', $item->from_minute)}}@endif
                            〜@if($item->to_hour){{$item->to_hour}}:{{sprintf('%02d', $item->to_minute)}}@endif
                        @endif
                        @if($item->reservation==1)
                            ＜完全予約制＞
                        @endif
                    </div>
                @endif
                <div class="p-results-image__image-area d-flex">
                    <div class="p-results-image__image d-flex">
                        @if(!empty($item->mansion_id))
                            @if(!empty(optional($item)->image_mansion))
                                <div class="p-results-image__image-box"><img
                                        src="{{ str_replace('public', '/storage', optional($item)->image_mansion->file_path) }}"/></div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                            @if(!empty($item->floor_file_path))
                                <div class="p-results-image__image-box"><img src="{{$item->floor_file_path}}"/></div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                        @else
                            @if(!empty($item->top_file_path))
                                <div class="p-results-image__image-box"><img src="{{$item->top_file_path}}"/></div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif

                            @if(!empty($item->floor_file_path))
                                <div class="p-results-image__image-box"><img src="{{$item->floor_file_path}}"/></div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                        @endif

                    </div>
                    <table class="p-results-image__main-info">
                        <tr>
                            @if($item->status == 4)
                                <th class="p-results-image__main-info-price_closing_title">物件価格</th>
                                <td class="p-results-image__main-info-price_closing" colspan="5">
                                    <span>最終：</span>@if($item->price){{number_format($item->price, 0, ",", ",")}}
                                    @else-@endif<span>万円</span>
                                    <span>成約：</span>@if($item->price_closing){{number_format($item->price_closing, 0, ",", ",")}}
                                    @else-@endif<span>万円{{$item->close_date ? '（'.date("Y.m.d" ,strtotime($item->close_date)).'）' :'' }}</span>
                                    @if($item->tax==2)<!--<span>（税込）</span>-->@endif
                                </td>
                            @else
                                <th class="p-results-image__main-info-price_title">物件価格</th>
                                <td class="p-results-image__main-info-price" colspan="5">
                                    {{number_format($item->price, 0, ",", ",")}}
                                    <span>万円@if($item->tax==2)<!--（税込）-->@endif</span>
                                </td>
                            @endif
                        </tr>
                        <tr>
                            <th class="p-results-image__main-info-address">所在地</th>
                            <td colspan="3">{{$item->address}}</td>
                            <th style="width:16%;">物件番号</th>
                            <td colspan="2">{{$item->building_id}}</td>
                        </tr>
                        <tr class="p-results-image__main-info-access">
                            <th>交通</th>
                            <td colspan="5">
                                @include('business.objects.projects.traffic-info', ['article' => $item])
                            </td>
                        </tr>
                        <tr>
                            @if($item->age_year == null && $item->age_month == null && $item->completed_contract_month != null)
                                <th style="width:12%;">完成予定</th>
                                <td style="width:15%;">契約後{{$item->completed_contract_month}}ヶ月</td>
                            @elseif($item->age_year > date("Y") || ($item->age_year == date("Y") && $item->age_month >= date("m") ))
                                <th style="width:12%;">完成予定</th>
                                <td style="width:15%;">{{$item->age_year?? "-"}}年{{$item->age_month?? "-"}}月</td>
                            @else
                                <th style="width:12%;">築年月</th>
                                <td style="width:15%;">{{$item->age_year?? "-"}}年{{$item->age_month?? "-"}}月</td>
                        @endif

                        <!--<th style="width:12%;">築年数</th>
                            <td style="width:12%;">{{$item->age?? "-"}}年</td>-->
                            <th style="width:15%;">間取り・階数</th>
                            <td>
                                {{$item->floor_plan_text?? "-"}}・
                                @if($item->whereabouts or $item->maisonette==1)
                                    @if($item->maisonette==1)
                                        {{$item->maisonette_from ? $item->maisonette_from : ''}}
                                        〜{{$item->maisonette_to ? $item->maisonette_to : ''}}階
                                    @elseif($item->whereabouts)
                                        {{$item->whereabouts?? "-"}}階
                                    @else
                                        -
                                    @endif
                                @endif
                                @if($item->floor)
                                    @if(!empty($item->mansion_id))
                                        @if(optional($item->getMansion())->underground)
                                            /地上{{optional($item->getMansion())->floor}}階 地下{{ optional($item->getMansion())->underground }}階建
                                        @elseif(optional($item->getMansion())->floor)
                                            /{{optional($item->getMansion())->floor}}階建
                                        @endif
                                    @else
                                        @if(optional($item)->underground)
                                            /地上{{optional($item)->floor}}階 地下{{ optional($item)->underground }}階建
                                        @elseif(optional($item)->floor)
                                            /{{optional($item)->floor}}階建
                                        @endif
                                    @endif
                                @endif
                                @if(!$item->whereabouts and $item->maisonette!=1 and !$item->floor)
                                    -
                                @endif
                            </td>
                            <th style="width:12%;">延床面積</th>
                            <td style="width:12%;">{{$item->total_area_val?? "-"}}m&sup2;</td>
                        </tr>
                        <tr>
                            <th>現況</th>
                            <td>
                                @if($item->status == 4)
                                    契約済<!-- / {{number_format($item->price_closing, 0, ",", ",")}}万円{{$item->close_date ? '（'.$item->close_date.'）' :'' }}-->
                                @elseif($item->status == 5)
                                    売りやめ
                                @else
                                    {{$item->current_status??"-"}}
                                @endif
                            </td>
                            <th>学校区</th>
                            <td>{{$item->primary_school_name?? "-"}}/{{$item->secondary_school_name?? "-"}}</td>
                            <th>土地面積</th>
                            <td>{{$item->land_area_val?? "-"}}m&sup2;</td>
                        </tr>
                    </table>
                    <p class="p-results-image__info-photo align-self-end">
                        @php
                            $isMansion = [6,7];
                            $isHouse = [4,5];
                        @endphp
                        <img src="{{ asset('business/img/icon_camera.png') }}" alt="写真">
                        @if(empty($item->property) && is_numeric($item->mansion_file_count))
                            外{{$item->mansion_file_count}}/内{{$item->file_count}}
                        @elseif (in_array($item->property, $isMansion))
                            外{{$item->mansion_file_count}}
                        @elseif (in_array($item->property, $isHouse))
                            外{{$item->mansion_file_count}}/内{{$item->file_count}}
                        @else
                            {{$item->file_count}}
                        @endif
                    </p>
                </div>
                @php
                    $uuid = \Ramsey\Uuid\Uuid::uuid4();
                @endphp
                {{-- 確認ボタンクリック時に表示する --}}
                @include('business.objects.projects.form-check', ['data_num' => $uuid, 'history_count' => count($item->history)])
                @include('business.objects.projects.modal-history', ['history' => $item->history, 'data_num' => $uuid])
            </li>
            @endif
        @endforeach
        @include('business.pages.buyer.partials.form-delete-article')
    </ul>
@endif
