@foreach($article_list as $key => $item)
    @if (!in_array($item->building_id, $hide_items))
        <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">
                        @if(strpos(url()->full(), '/for-sale') !== false)
                            <div class="label-buyer-group" data-art="{{ $item->building_id }}">
                                @if(session('buyer_active') && !empty(session('buyer_active')->articles->where('article_id', $item->building_id)->first()))
                                    <label class="label-buyer p-0 mb-0 delete-article">
                                        <div class="w-100 text-center">保存済</div>
                                    </label>
                                @else
                                    <label for="cb-{{$key}}" class="label-buyer u-checkbox pointer p-0 mb-0">
                                        <input type="checkbox" name="" value="{{ $item->building_id }}" id="cb-{{$key}}"
                                               class="u-checkbox__obj checkbox-buyer pointer cb-{{ $item->building_id }}">
                                        <span class="u-checkbox__text"></span>
                                    </label>
                                @endif
                            </div>
                        @endif
                        <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>
                        @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="../../business/img/icon_building.png"></a>
                        @endif
                    </div>
                </div>
                <ul class="p-results-image__li-btns d-flex justify-content-end list-unstyled">
                    @if($flag == 1 || $flag == 2)
                        <li>
                            @include('business.objects.components.circle-btn',
                                ['id' => 'btnCheck', 'class' => 'c-circle-btn__check', 'linkUrl' => '#',
                                'img' => '../../business/img/icon_check.png', 'title' => '確認'])
                        </li>
                    @endif
                    <li>
                        @include('business.objects.components.circle-btn',
                            ['id' => 'bttnDetail'.$item->building_id, 'class' => 'c-circle-btn__detail', 'linkUrl' => 'javascript:void(0);',
                            'img' => '../../business/img/icon_detail.png', 'title' => '詳細'])
                    </li>
                    <li>
                        @include('business.objects.components.circle-btn',
                            ['id' => 'btnDisplay', 'class' => 'c-circle-btn__display', 'linkUrl' => '#',
                            'img' => '../../business/img/icon_display.png', 'title' => '非表示',
                            'attr' => 'data-id='.$item->building_id])
                    </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)
                      @php
                          $eventDay = trim($item->event_day, ' ,');
                          $dates = explode(',', $eventDay);
                          $formattedDates = array_map(function($date) {
                              return date('n/j', strtotime($date));
                          }, $dates);
                          $result = count($formattedDates) > 1 ? implode('・', $formattedDates) : $formattedDates[0];
                      @endphp
                      {{ $result }}
                    @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($item->vertical === 1)
                            @if(!empty($item->file_path2))
                                <div class="p-results-image__image-box popup"><img src="{{$item->file_path2}}"/></div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                        @else
                            @if(!empty($item->floor_file_path))
                                <div class="p-results-image__image-box popup"><img src="{{$item->floor_file_path}}"/></div>
                            @elseif(!empty($item->sheet_file_path3) && $item->sheet_file_type == 1)
                                <div class="p-results-image__image-box popup"><img
                                        src="{{ asset(str_replace('public/', 'storage/', $item->sheet_file_path3)) }}"/>
                                </div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                        @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($item->vertical === 1)
                                @if(!empty($item->file_path2))
                                    <div class="p-results-image__image-box popup"><img src="{{str_replace('public/', 'storage/', url($item->file_path2))}}"/></div>
                                @else
                                    <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                                @endif
                        @else
                            @if(!empty($item->floor_file_path))
                                <div class="p-results-image__image-box popup"><img src="{{$item->floor_file_path}}"/></div>
                            @elseif(!empty($item->sheet_file_path3) && $item->sheet_file_type == 1)
                                <div class="p-results-image__image-box popup"><img
                                        src="{{ asset(str_replace('public/', 'storage/', $item->sheet_file_path3)) }}"/>
                                </div>
                            @else
                                <div class="p-results-image__image-box"><img src="{{root('img/noimage2.jpg')}}"/></div>
                            @endif
                        @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><span
                                    id="item-price-{{ $item->building_id }}">@if($item->price){{number_format($item->price, 0, ",", ",")}}</span>
                                @else-@endif万円
                                <span>成約：</span>@if($item->price_closing)
                                    <span
                                        id="close-price-{{ $item->building_id }}">{{number_format($item->price_closing, 0, ",", ",")}}</span>
                                @else
                                    <span id="close-price-{{ $item->building_id }}">-</span>
                                @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">
                                <span
                                    id="item-price-{{ $item->building_id }}">{{number_format($item->price, 0, ",", ",")}}</span>
                                万円@if($item->tax==2)
                                    <!--（税込）-->
                                @endif
                            </td>
                        @endif
                    </tr>
                    <tr>
                        <th class="p-results-image__main-info-address">所在地</th>
                        <td colspan="3">
                            @php
                                if (!is_null($item->mansion_id) && \App\Models\Article::getDataById($item->mansion_id))
                                    $address = \App\Models\Article::getDataById($item->mansion_id);
                                else
                                    $address = $item;
                            @endphp
                            {{ $address->address_info }}

{{--                            @if(isset($address->pref_name) && isset($address->city_name) && isset($address->town_name))--}}
{{--                                {{$address->pref_name}}{{$address->city_name}}{{$address->town_name}}--}}
{{--                            @else--}}
{{--                                {{$address->other_address ?? '-/-'}}--}}
{{--                            @endif--}}

                        </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-summary', ['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>
                            @if(isset($item->primary_school_name) || isset($item->secondary_school_name))
                                {{$item->primary_school_name?? "-"}}/{{$item->secondary_school_name?? "-"}}
                            @elseif(isset($item->other_primary_school_2) || isset($item->other_secondary_school_2))
                                {{$item->other_primary_school_2 ?? "-"}}/{{$item->other_secondary_school_2 ?? "-"}}
                            @else
                                -/-
                            @endif
                        </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="../../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),
                'isShowOwnCompany' => $isShowOwnCompany ?? false,
            ])
            @include('business.objects.projects.modal-history', ['history' => $item->history, 'data_num' => $uuid])
        </li>
    @endif
@endforeach
