{{-- 並び替え --}}
<style type="text/css">
table.mansion{
    background:#ecf3ff;
}
</style>
<div class="p-results-noimage articles-list-custom">
  @foreach($data as $item)
@php
$bukken_url = '';
if(is_null($item->property)) {
    $bukken_url = '/admin/editRoom/'.$item->mansion_id.'/'.$item->building_id;
} elseif($item->property < 4) {
    $bukken_url = '/admin/editLand/'.$item->building_id;
} elseif($item->property < 6) {
    $bukken_url = '/admin/editHouse/'.$item->building_id;
} elseif($item->property < 8) {
    $bukken_url = '/admin/editMansion/'.$item->building_id;
}
@endphp
  <div @if(isset($portal_name)) id="{{ $portal_name }}"@endif class="mb-3 row-house">
    <div class="clearfix">
        <ul class="p-results-noimage__btns d-flex justify-content-center list-unstyled float-right">
            @if($item->property == 6 or $item->property == 7)
            @else
            <li>
                <a href="javascript:void(0);" name="c-circle-btn__check"><img src="/admin/img/icon_check.png"></a>
            </li>
            @endif
            <li>
                @php
                $url = $item->getEditUrl();
                if(isset($searchArt)){
                    $url .= '?back=false';
                }
                @endphp
                <a @php if(isset($searchArt)){ echo 'target="_blank"';}@endphp href="{{$url}}"><img src="/business/img/toroku.png"></a>
            </li>
            <li>
              <img src="/business/img/icon_camera.png" alt="写真">
              @if($item->mansion_id)
                  外{{$item->mansion_file_count??'0'}}/内{{$item->file_count}}
              @elseif($item->property == 4 || $item->property == 5)
                    外{{$item->mansion_file_count??'0'}}/内{{$item->file_count}}
              @else
                  {{$item->file_count}}
              @endif
            </li>
        </ul>
        @if(isset($bar_public) && !empty($item->public_portal[0]))
        <div class="portal-public-info d-flex float-right justify-content-center mr-1">
            <label class="label-public">ポータル掲載情報（{{ $item->public_portal[0]->created_at ? date( 'Y.m.d H:i', strtotime($item->public_portal[0]->created_at)) : '' }}）</label>
            <ul>
                @php
                    $pl_suumo = $pl_homes = $pl_athome = '';
                    foreach($item->public_portal as $pl){
                        if($pl->type == 1){
                            $pl_suumo = $pl;
                        }
                        if($pl->type == 2){
                            $pl_homes = $pl;
                        }
                        if($pl->type == 3){
                            $pl_athome = $pl;
                        }
                    }
                    $suumo_text = $homes_text = $athome_text = '';
                    if(!empty($pl_suumo)){
                        $suumo_text = '非掲載';
                        if($pl_suumo->status == 1){
                            $suumo_text = 'ネットコマ';
                        }
                        if($pl_suumo->status == 2){
                            $suumo_text = 'レポート';
                        }
                    }
                    if(!empty($pl_homes)){
                        $homes_text = "非掲載";
                        if($pl_homes->status == 1){
                            $homes_text = "掲載";
                        }
                    }
                    if(!empty($pl_athome)){
                        $athome_text = '非公開';
                        if($pl_athome->status == 1){
                            $athome_text = '会員間';
                        }
                        if($pl_athome->status == 2){
                            $athome_text = '会員一般向';
                        }
                        if($pl_athome->status == 3){
                            $athome_text = '一般向';
                        }
                    }
                @endphp
                @if(!empty($shop_user->suumo_id) && !empty($shop_user->suumo_pw))
                    <li class="suumo_color">@if($suumo_text != '')
                            @if(!empty($pl_suumo) && $pl_suumo->status == 0)
                                <img src="/admin/img/suumo-icon-o8.png" width="18" alt="">
                            @else
                                <img src="/admin/img/suumo-icon.png" width="18" alt="">
                            @endif @php echo $suumo_text == '非掲載' ? '<span class="text-gray">'.$suumo_text.'</span>' : $suumo_text @endphp @endif</li>
                @endif
                @if(!empty($shop_user->homes_id) && !empty($shop_user->homes_pw))
                    <li class="homes_color">@if($homes_text != '')
                        @if(!empty($pl_homes) && $pl_homes->status == 0)
                            <img src="/admin/img/homes-icon-o8.png" width="18" alt="">
                        @else
                            <img src="/admin/img/homes-icon.png" width="18" alt="">
                        @endif @php echo $homes_text == '非掲載' ? '<span class="text-gray">'.$homes_text.'</span>' : $homes_text @endphp @endif</li>
                @endif
                @if(!empty($shop_user->athome_id) && !empty($shop_user->athome_pw))
                    <li class="athome_color">@if($athome_text != '')
                        @if(!empty($pl_athome) && $pl_athome->status == 0)
                            <img src="/admin/img/athome-icon-o8.png" width="18" alt="">
                        @else
                            <img src="/admin/img/athome-icon.png" width="18" alt="">
                        @endif @php echo $athome_text == '非公開' ? '<span class="text-gray">'.$athome_text.'</span>' : $athome_text @endphp @endif</li>
                @endif
            </ul>
        </div>
        @endif
    </div>
    <table class="p-results-noimage__tbl@php if(isset($searchArt) && ($item->property == 6 || $item->property == 7)){ echo ' mansion"';} @endphp">
        <tr>
            <td rowspan="3" class="p-results-noimage__tbl-num-date">
              @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
                <p><span class="p-results-noimage__tbl-number">@php if(isset($searchArt) && ($item->property == 6 || $item->property == 7)){ echo 'マンションID';}else{ echo '物件番号';} @endphp</span>
                @if(isset($searchArt))
                    @include('business.objects.components.link', ['url' => $bukken_url.'?back=false', 'blank' => '_blank', 'title' => $item->building_id, 'class' => 'p-form-check__tbl-link-id'])
                @else
                    @include('business.objects.components.link', ['url' => $bukken_url, 'title' => $item->building_id, 'class' => 'p-form-check__tbl-link-id'])
                @endif
                </p>
                <p class="mt-1 p-results-noimage__tbl-date"><span class="p-results-noimage__tbl-date">物件登録日</span><br>{{ !empty($item->created_at) ? $item->created_at->format('Y/m/d') : "" }}</p>
            </td>
            <th>物件名</th>
            <td>
                <div class="d-flex justify-content-between">
                    <p>{{ $item->getNameWithGouchi() }}</p>
                    @if(!is_null($item->mansion_id))
                        @if(!empty($item->getMansion()))
                            <a target="_blank" href="/admin/editMansion/{{$item->mansion_id}}?back=false" class="p-results-noimage__tbl-link-mansion"><img src="/business/img/toroku.png"></a>
                        @endif
                    @endif
                </div>
            </td>

            <th>所在地</th>
                <td class="p-results-noimage__tbl-address">
                    @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>価格</th><td class="p-results-noimage__tbl-price">
                @if(!isset($searchArt) || ($item->property != 6 && $item->property != 7))
                  @if($item->status == 4)
                  <p>最終：<span>@if($item->price){{number_format($item->price, 0, ",", ",")}}@else-@endif</span>万円</p>
                  <p>成約：<span id="item-price-{{ $item->building_id }}">@if($item->price_closing){{number_format($item->price_closing, 0, ",", ",")}}@else-@endif</span>万円{{$item->close_date ? '（'.$item->close_date.'）' :'' }}</p>
                  @if($item->tax==2)<!--<p>（税込）</p>-->@endif
                  @else
    {{--              <span>sdfsf{{number_format($item->price, 0, ",", ",")}}</span>万円@if($item->tax==2)<!--（税込）-->@endif--}}
                        <span id="item-price-{{ $item->building_id }}">
                            {{number_format($item->price, 0, ",", ",")}}
                        </span>万円@if($item->tax==2)<!--（税込）-->@endif
                  @endif
                @else
                    -万円
                @endif
            </td>
            <th>土地</th><td class="p-results-noimage__tbl-area">@if(!isset($searchArt) || ($item->property != 6 && $item->property != 7)){{$item->land_area_val?? "-"}}m&sup2;@else -m&sup2; @endif</td>
        </tr>
        <tr>
            <th>種別</th><td>{{$item->property_name?? "-"}}</td>
            <th rowspan="2">交通</th><td rowspan="2">
            @php
                if ($item->getMansion())
                    $traffic = $item->getMansion();
                else
                    $traffic = $item;
            @endphp
            @include("admin.objects.components.for-sale-traffic", ["item" => $traffic])
            </td>
            <th>築年月</th><td>{{$item->age_year?? "-"}}年{{$item->age_month?? "-"}}月</td>
            <th>延床</th><td>{{$item->total_area_val?? "-"}}m&sup2;</td>
        </tr>
        <tr>
          <th>校区</th><td class="p-results-noimage__tbl-school">
                @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>
            @if($item->property==1 || $item->property==2 || $item->property==3)
            -
            @elseif($item->property==4 || $item->property==5)
                @if($item->underground)
                    地上{{$item->floor}}階・地下{{$item->underground}}階建
                @else
                    {{$item->floor?? "-"}}階建
                @endif
            @else
                @if($item->maisonette==1)
                  {{$item->maisonette_from ? $item->maisonette_from : ''}}〜{{$item->maisonette_to ? $item->maisonette_to : ''}}
                @else
                  {{$item->whereabouts?? "-"}}
                @endif
                階/
                @if($item->underground)
                    地上{{$item->floor}}階・地下{{$item->underground}}階建
                @else
                    {{$item->floor?? "-"}}階建
                @endif
            @endif
          </td>
          <th>間取り</th><td>{{$item->floor_plan_text?? "-"}}</td>
        </tr>
    </table>
    {{-- 確認ボタンクリック時に表示する --}}
    @if($item->property == 6 or $item->property == 7)
    @else
    @include('admin.objects.projects.form-check', [
        'data_num' => $loop->iteration+count($data),
        'history_count' => count($item->history),
        'isShowOwnCompany' => $isShowOwnCompany ?? false,
    ])
    @include('admin.objects.projects.modal-history', ['history' => $item->history, 'data_num' => $loop->iteration+count($data)])
    @endif
  </div>


  @endforeach
</div>
