<form method="POST" action="{{ route('registImage', ['id' => $article->building_id]) }}" enctype="multipart/form-data">
{{ csrf_field() }}
    @include('admin.objects.components.regist-tab-image', ['title' => $main_title])
    @include('admin.objects.components.hidden', ['name' => 'article_id', 'value' => $article->building_id])
    @include('admin.objects.components.hidden', ['name' => 'referer', 'value' => $referer])
    <?php
    $photos = [];
    foreach($article->listImages as $photo){
        $photos[] = $photo->id;
    }
    $photos = implode(',', $photos);

    $isHouseArticle = [4, 5];
    $isLandArticle = [1, 2, 3];
    $articleProperty = $article->property;
    $defaultFloorFileType = in_array($articleProperty, $isLandArticle) ? '1' : '2';
    $defaultPhotoPropertySub = in_array($articleProperty, $isHouseArticle) ? '7' : (in_array($articleProperty, $isLandArticle) ? '4' : '2');
    ?>
    @include('admin.objects.components.hidden', ['name' => 'saved_photo_id', 'value' => $photos])
    @include('admin.objects.components.hidden', ['name' => 'photo_count', 'value' => count($article->listImages)])
    <div class="mb-3">
        @if($disp_flag == 1)
            <div class="d-flex justify-content-end">
                @if(strstr($_SERVER["REQUEST_URI"],'registImage') and isset($article->building_id))
                    @if($disp_flag == 1)
                        <a href="/business/for-sale/detail/{{$article->building_id}}" class="p-regist__table-link" target="_blank">住まいの情報DB「物件詳細ページ」を見る</a>
                    @elseif($disp_flag == 2)
                        <a href="/business/mansion/parentDetail/{{$article->building_id}}" class="p-regist__table-link" target="_blank">住まいの情報DB「マンション建物ページ」を見る</a>
                    @elseif($disp_flag == 3)
                        <a href="/business/lot/parentDetail/{{$article->building_id}}" class="p-regist__table-link" target="_blank">住まいの情報DB「分譲地ページ」を見る</a>
                    @endif
                @endif
            </div>
        @else
            @include('admin.objects.components.regist-band', ['title' => '画像登録'])
        @endif
    @if($disp_flag == 1)
        <div class="p-regist">
            @include('admin.objects.projects.regist-image-tab-link', ['active' => 'tab-one', 'title' => '区画図・間取り'])
            <table class="p-regist__table">
                <tbody>
                    <tr>
                        <th colspan="2">画像種類</th>
                        <td>
                            <div>
                                @include('admin.objects.components.selectbox', ['name' => 'floor_file_type', 'options' => $image_kind, 'selected' => $article->floor_file_type??$defaultFloorFileType, 'class'  =>  'w200'])
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th colspan="2">
                            <div class="d-flex justify-content-between">
                                <div>区画図・間取り</div><!--<span class="require">メルマガ必須</span>--><br />
                            </div>
{{--                            <div class="mt-2">--}}
{{--                                @if(in_array($article->property, [1,2,3]))--}}
{{--                                    ※区面図が登録済の物件のみ、<br />メルマガ送信条件を満たします。--}}
{{--                                @else--}}
{{--                                    ※間取り図が登録済の物件のみ、<br />メルマガ送信条件を満たします。--}}
{{--                                @endif--}}
{{--                            </div>--}}
                            <span class="alart">※画像推奨サイズ　<br />サイズ／<strong>横1200×縦800px</strong><br />比率／横３：縦２</span>
                        </th>
                        <td>
                            <div class="d-flex">
                                <div class="mr20">
                                    @include('admin.objects.components.add-floor-image', ['id' => 'imageArea'])
                                    <div class="mt10 text-center">
                                        @include('admin.objects.components.btn', ['name' => 'del_article_floor_photo', 'class' => 'w100', 'title' => '削除', 'type' => 'button'])
                                    </div>
                                </div>
                                <div class="w250 mr20">
                                    @include('admin.objects.components.textarea_house', ['name' => 'floor_file_comment', 'class' => 'img_text w-100', 'count' => 100, 'placeholder' => '画像コメント', 'value' => $article->floor_file_comment??''])
                                    <span style="float: right">※at homeは50文字まで</span>
                                </div>
{{--                                <div>--}}
{{--                                    @include('admin.objects.components.selectbox', ['name' => 'floor_file_type', 'options' => $image_kind, 'selected' => $article->floor_file_type??'', 'class'  =>  'w200'])--}}
{{--                                </div>--}}
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th colspan="2"> 物件シート 図面拡大画面<br /><span class="alart">※画像推奨サイズ<br />サイズ／<strong>横800×縦1200px</strong><br />比率／横２：縦３</span></th>
                        <td>
                            <div>
                                @include('admin.objects.components.checkbox', ['name' => 'vertical', 'checked' => $article->vertical ?? 0, 'checkbox' => [['data_show_class' => 'floor-image-content', 'name' => '図面を縦配置にする', 'code' => 1]]])
                            </div>
                            <div class="floor-image-content @if($article->vertical !== 1) {{ 'd-none' }} @endif">
                                <div class="d-flex ">
                                    <div>
                                        @include('admin.objects.components.add-floor-image2', ['id' => 'imageArea4', 'file_path' => $article->file_path2])
                                        <div class="mt10 text-center">
                                            @include('admin.objects.components.btn', ['name' => 'del_article_floor_photo4', 'class' => 'w100', 'title' => '削除', 'type' => 'button'])
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
            @include('admin.objects.components.hidden', ['name' => 'del_photo_id', 'value' => ''])
            @include('admin.objects.projects.regist-image-tab-link', ['active' => 'tab-two', 'title' => '写真画像'])
            <table class="p-regist__table">
                <tbody id="image_lists" class="house_img">
                @include('admin.objects.projects.image-upload-large2', [ 'building_id' => $article->building_id, 'id' => 'iamgeAreaMulti', 'cid' => 'iamgeAreaMultiChild'])
                <tr>
                    <td colspan="8">
                        @include('admin.objects.components.add-photo-template-house')
                        <div id="sortable_article_image" class="p-regist__sorttable sortable-img">
                            <div id="image_list" class="row sortable_group">
                                @foreach($article->listImages as $photo)
                                <div class="col-2 mt10 mb10 sortable_item">
                                    <div class="p-add-photo p-imgupload-single w-100 h100" data-id="{{ $photo->id }}">
                                        <img src="{{$photo->storageLink}}">
                                        <canvas name="canvas" width="0" height="0"></canvas>
                                        <input class="fileSingleInputSingle" type="file" name="photo_images[]" style="display:none;">
                                        @include('admin.objects.components.hidden', ['name' => 'temp_photo_id'.$loop->index, 'class' => 'temp_photo_id'])
                                    </div>
                                    <div class="mt10 w-100">
                                        @include('admin.objects.components.hidden', ['name' => 'article_photo_id'.$loop->index, 'value' => $photo->id, 'class' => 'article_photo_id'])
                                        @include('admin.objects.components.btn', ['name' => 'del_photo_portal', 'class' => 'btn_imagedel w-100', 'title' => '削除', 'type' => 'button'])
                                    </div>

                                    @include('admin.objects.components.selectbox', ['class'  =>  'w-100 mt10', 'name' => 'photo_property_sub'.$loop->index, 'options' => $photo_property, 'selected' => $photo->property_sub])

                                    @include('admin.objects.components.textarea_house', ['name' => 'photo_comment'.$loop->index, 'class' => 'img_text mt10', 'count' => 100, 'site' => 1, 'placeholder' => '自社HP：100文字まで', 'value' => $photo->memo])
                                    <span style="font-size: 11px;float:right">※at homeは50文字まで</span>

                                </div>
                            @endforeach

                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            @if($is_room)
                <table class="p-regist__table">
                    <tbody>
                        <tr>
                            <th colspan="2">マンション物件画像</th>
                            <td colspan="8">
                                <div id="image_list" class="row house_img">
                                @foreach($article->mansion->listImages as $mansionPhoto)
                                    <div class="col-2 mt10 mb10">
                                        <div class="h100 overflow-hidden">
                                            <img src="{{$mansionPhoto->storageLink}}" style="max-height: 100%">
                                        </div>
                                    </div>
                                @endforeach
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            @endif
            @include('admin.objects.projects.regist-image-tab-link', ['active' => 'tab-three', 'title' => '施設写真'])
            @if ($is_room)
                @include('admin.objects.projects.show-facility')
            @else
                @include('admin.objects.projects.edit-facility')
            @endif
            @include('admin.objects.projects.regist-image-tab-link', ['active' => 'tab-four', 'title' => '業者物件シート'])
            <table class="p-regist__table">
                <tbody>
                @include('admin.objects.projects.sheet-disp')
                </tbody>
            </table>


            @include('admin.objects.projects.regist-image-tab-link', ['active' => 'tab-five', 'title' => '広告掲載承諾書'])
            <table class="p-regist__table">
                <tbody>
                @include('admin.objects.projects.ad-consent-form')
                </tbody>
            </table>

{{--            footer--}}
            <div class="regist__div position-fixed">
                <div class="l-contents__disp">
                    <button class="c-linkbtn c-base-link__portal saved_to_portal_image">保存してポータル情報登録ページ</button>
                    @include('admin.objects.components.regist-btn', ['class' => '', 'title' => '登録・保存'])
                    <div class="portal__info float-right position-absolute ">
                        <p>画像制限枚数</p>
                        <div class="row">
                            <div class="col-5"><strong class="text-success">SUUMO</strong></div>
                            <div class="col-2"><strong style="color:#fab81e">HOME'S</strong></div>
                            <div class="col-5"><strong class="text-danger">at home</strong></div>
                        </div>
                        <div class="row portal__info__text">
                            <div class="col-5">物件: <strong>20枚</strong> 周辺: <strong>9枚</strong></div>
                            <div class="col-2"><strong>30枚</strong></div>
                            <div class="col-5">物件: <strong>40枚</strong> 周辺: <strong>8枚</strong></div>
                        </div>
                    </div>
                </div>
            </div>
{{--            end of footer--}}
        </div>
    @elseif($disp_flag == 2)
        <div class="p-regist">
            @include('admin.objects.components.hidden', ['name' => 'del_photo_id', 'value' => ''])
            <table class="p-regist__table mt10">
                <tbody id="image_lists" class="mansion_img">
                @include('admin.objects.projects.image-upload-large2', ['id' => 'iamgeAreaMulti', 'cid' => 'iamgeAreaMultiChild'])
                <tr>
                    <td colspan="8" class="alart">※一番上の写真が、マンション（建物）物件シートに反映されます</td>
                </tr>
                <tr>
                    <td colspan="8">
                        @include('admin.objects.components.add-photo-template-house')
                        <div id="sortable_article_image" class="p-regist__sorttable sortable-img">
                            <div id="image_list" class="row sortable_group">
                                @foreach($article->listImages as $photo)
                                    <div class="col-2 mt10 mb10 sortable_item">
                                        <div class="p-add-photo p-imgupload-single w-100 h100" data-id="{{ $photo->id }}">
                                            <img src="{{$photo->storageLink}}">
                                            <canvas name="canvas" width="0" height="0"></canvas>
                                            <input class="fileSingleInputSingle" type="file" name="photo_images[]" style="display:none;">
                                            @include('admin.objects.components.hidden', ['name' => 'temp_photo_id'.$loop->index, 'class' => 'temp_photo_id'])
                                        </div>
                                        <div class="mt10 w-100">
                                            @include('admin.objects.components.hidden', ['name' => 'article_photo_id'.$loop->index, 'value' => $photo->id, 'class' => 'article_photo_id'])
                                            @include('admin.objects.components.btn', ['name' => 'del_photo_portal', 'class' => 'btn_imagedel', 'title' => '削除', 'type' => 'button'])
                                        </div>

                                        @include('admin.objects.components.selectbox', ['name' => 'photo_property_sub'.$loop->index, 'options' => $photo_property, 'selected' => $photo->property_sub])

                                        @include('admin.objects.components.textarea_house', ['name' => 'photo_comment'.$loop->index, 'class' => 'img_text', 'count' => 100, 'placeholder' => '自社HP：100文字まで', 'value' => $photo->memo])
                                        <span style="font-size: 11px;float:right">※at homeは50文字まで</span>

                                    </div>
                                @endforeach

                            </div>
                        </div>
                    </td>
                </tr>

                </tbody>
            </table>
            @include('admin.objects.projects.edit-facility')
            <div class="regist__div">
                @include('admin.objects.components.regist-btn', ['class' => '', 'title' => '登録・保存'])
            </div>
        </div>
    @elseif($disp_flag == 3)
        <div class="p-regist">
            <table class="p-regist__table">
                <tbody>
                    <tr>
                        <th colspan="2">全体区画図</th>
                        <td>
                            <div class="d-flex">
                                @include('admin.objects.components.add-floor-image', ['id' => 'imageArea'])
                                <div class="ml10">
                                    画像種類
                                    @include('admin.objects.components.radio', ['name' => 'floor_file_type', 'radio' => $image_kind, 'checked' => $article->floor_file_type])
                                    <div class="mt10">
                                        @include('admin.objects.components.btn', ['name' => 'del_article_floor_photo', 'class' => '', 'title' => '削除', 'type' => 'button'])
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="regist__div">
                @include('admin.objects.components.regist-btn', ['class' => '', 'title' => '登録・保存'])
            </div>
        </div>
    @endif
    </div>
</form>
@include('admin.objects.projects.modal-message')
<script type="text/javascript">
    window.onload = function(){
        var message = '登録・保存しました。';
        $('#saved_message').text(message);
        openMessageModal();
    };

</script>
@if($saved == 1)
@include('admin.objects.projects.modal-message')
<script type="text/javascript">
    window.onload = function(){
        var message = '登録・保存しました。';
        $('#saved_message').text(message);
        openMessageModal();
    };

</script>
@endif
<script>
    const URL_GET_NEAR_FACILITY = "{{ route("admin.facility.near") }}";
    const BUILDING_ID = "{{ $article->building_id }}";
</script>
<script src="{{ asset("admin/js/image_facility.js") }}"></script>
