@extends('admin.layouts.base')

@section('contents')
    @include('admin.objects.components.regist-tab-portal', ['title' => $main_title])

    @include('admin.objects.components.hidden', ['name' => 'article_id', 'value' => $article->building_id])
    <div class="mb-3">
        @include('admin.objects.components.regist-band', ['title' => 'ポータル登録'])
        <div class="p-regist">
            <table class="p-regist__table">
                <tbody>
                @if($store->suumo_id !== "" && $store->suumo_pw !== "")
                    <tr>
                        <th colspan="2">SUUMO</th>
                        <td>
                            <div class="d-flex">
                                <div class="ml10">
                                    <form
                                        action="{{ route("admin.portal.update", ["type" => "suumo", "id" => $article->id]) }}"
                                        method="POST">
                                        @csrf
                                        <div class="d-flex align-items-center">
                                            <button type="submit" style="width: 100px"
                                                    class="c-base-tab__draft saved_to_image">入稿
                                            </button>
                                            <p class="m-0">
                                                <?php if(!empty($article->suumo_date)){ $suumo_date = date('Y.m.d', strtotime($article->suumo_date)); } ?>
                                                @if(!empty($article->suumo_date))（前回入稿日：{{$suumo_date}}）@endif※SUUMOに入稿済みの場合、リセットして再入稿されます。
                                            </p>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                @endif
                @if($store->homes_id !== "" && $store->homes_pw !== "")
                    <tr>
                        <th colspan="2">HOMES</th>
                        <td>
                            <div class="d-flex">
                                <div class="ml10">
                                    <form
                                        action="{{ route("admin.portal.update", ["type" => "homes", "id" => $article->id]) }}"
                                        method="POST">
                                        @csrf
                                        <div class="d-flex align-items-center">
                                            <button type="submit" style="width: 100px"
                                                    class="c-base-tab__draft saved_to_image">入稿
                                            </button>
                                            <p class="m-0">
                                                <?php if(!empty($article->homes_date)){ $homes_date=date('Y.m.d', strtotime($article->homes_date)); } ?>
                                                @if(!empty($article->homes_date))（前回入稿日：{{$homes_date}}）@endif※HOMESに入稿済みの場合、リセットして再入稿されます。
                                            </p>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                @endif
                @if($store->athome_id !== "" && $store->athome_pw !== "")
                    <tr>
                        <th colspan="2">at home</th>
                        <td>
                            <div class="d-flex">
                                <div class="ml10">
                                    <form
                                        action="{{ route("admin.portal.update", ["type" => "athome", "id" => $article->id]) }}"
                                        method="POST">
                                        @csrf
                                        <div class="d-flex align-items-center">
                                            <button type="submit" style="width: 100px"
                                                    class="c-base-tab__draft saved_to_image">入稿
                                            </button>
                                            <p class="m-0">
                                                <?php if(!empty($article->athome_date)){ $athome_date=date('Y.m.d', strtotime($article->athome_date)); }?>
                                                @if(!empty($article->athome_date))（前回入稿日：{{$athome_date}}）@endif※at homeに入稿済みの場合、リセットして再入稿されます。
                                            </p>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                @endif
                </tbody>
            </table>
            <span class="portal__acount">※1つの物件を複数の店舗アカウントで入稿することはできません。入稿済みの物件を別の店舗アカウントでも入稿したい場合は、ポータルの管理画面から直接入稿してください。</span>
        </div>
    </div>

    <div class="mt-4 row c-tab d-flex justify-content-center align-items-center">
        @include('admin.objects.components.link-btn', ['url' => $back, 'title' => '戻る', 'class' => 'c-tab__backbtn'])
    </div>
    @if(isset($saved))
        @include('admin.objects.projects.modal-message')
        <script type="text/javascript">
            window.onload = function(){
                var message = '登録・保存しました。';
                $('#saved_message').text(message);
                openMessageModal();
            };
        </script>
    @endif
    @if (session('message_modal') or session('message_ok'))
            @if(session('message_modal'))
                <div id="modal-message-content-portal" class="modal-contents" style="width:600px; min-height:100px;">
                    <div id="modal_open">
                        <main id="modal_main">
                            <span id="saved_message"><?php echo session('message_modal') ?></span>
                        </main>
                    </div>
                    <div class="text-center mt15">
                        <span class="c-linkbtn c-tab__backbtn mr-0 ml-0 btn-close-modal">戻る</span>
                        <a href="{{ $action }}" class="c-base-tab__image saved_to_image un-required">物件詳細ページへ</a>
                    </div>
                </div>
            @else
                <div id="modal-message-content-portal" class="modal-contents" style="width:300px; min-height:100px;">
                    <div id="modal_open">
                        <main id="modal_main" class="text-center">
                            <span id="saved_message"><?php echo session('message_ok') ?></span>
                        </main>
                    </div>
                </div>
            @endif
        <script type="text/javascript">
            function openMessageModalPortal() {
                $(this).blur();  //ボタンからフォーカスを外す
                if ($("#modal-overlay")[0]) return false;       //新しくモーダルウィンドウを起動しない (防止策1)
                $("body").append('<div id="modal-overlay"></div>');
                $("#modal-overlay").fadeIn("slow");
                centeringMessageModalSyncerPoral();
                $("#modal-message-content-portal").fadeIn("slow");
                $("#modal-overlay,#modal-close").unbind().click(function () {
                    $("#modal-message-content-portal,#modal-overlay").fadeOut("slow", function () {
                        $('#modal-overlay').remove();
                    });
                });
            }
            function centeringMessageModalSyncerPoral() {
                var w = $(window).width();
                var h = $(window).height();

                var cw = $("#modal-message-content-portal").outerWidth();
                var ch = $("#modal-message-content-portal").outerHeight();

                $("#modal-message-content-portal").css({"left": ((w - cw) / 2) + "px", "top": ((h - ch) / 2) + "px"});
            }
            window.onload = function() {
                openMessageModalPortal();
                $(".btn-close-modal").click(function () {
                    $("#modal-overlay").remove();
                    $("#modal-message-content").remove();
                    $(".modal-contents").remove();
                });
            };
        </script>
    @endif

@endsection
