{% extends 'base.html' %}

{% block content %}
        <div class="container__post">
            <div class="content">
                <div class="content__info">
                    <p class="content__category">{{ post.category }}</p>
                    <div class="title__div">
                        <h3 class="content__title">{{ post.title }}</h3>
                        <p class="content__date"><span>{{ post.mb_id }}</span> {{ post.add_date }}</p>
                    </div>
                    <div class="content__desc">
                        {{ post.contents | safe }}
                    </div>
                </div>
                <div class="etc__list">
                    <div class="other__list">
                        <ul>
                        {% if prev_post is not none %}
                            <li>
                                <p class="other__list__way">이전</p>
                                <p class="other__list__title">
                                    <a href="{{ url_for('post', post_id=prev_post.id) }}">{{ prev_post.title }}</a>
                                </p>
                                <p class="other__list__date">
                                    <span>{{ prev_post.mb_id }}</span> {{ prev_post.add_date }}
                                </p>
                            </li>
                        {% else %}
                            <li>
                                <p class="other__list__way">이전</p>
                                <p class="other__list__title">
                                    이전 글이 없습니다.
                                </p>
                            </li>
                        {% endif %}
                        {% if next_post is not none %}
                            <li>
                                <p class="other__list__way">다음</p>
                                <p class="other__list__title">
                                    <a href="{{ url_for('post', post_id=next_post.id) }}">{{ next_post.title }}</a>
                                </p>
                                <p class="other__list__date">
                                    <span>{{ next_post.mb_id }}</span> {{ next_post.add_date }}
                                </p>
                            </li>
                        {% else %}
                            <li>
                                <p class="other__list__way">다음</p>
                                <p class="other__list__title">
                                    다음 글이 없습니다.
                                </p>
                            </li>
                        {% endif %}
                        </ul>
                    </div>
                    <div class="btn__area">
                    {% if g.is_login and (g.user_info.mb_id == post.mb_id or g.user_info.mb_id in ['admin', 'wixon']) %}
                        <a href="{{ url_for('edit_post', post_id=post.id) }}" class="btn__edit">수정</a>
                        <a class="btn__delete" href="javascript:blogDelete('{{ post.id }}');">삭제</a>
                    {% endif %}
                        <a href="{{ url_for('index') }}" class="btn__lists">목록</a>
                    </div>
                </div>
            </div>
        </div>
        <footer>
                <div class="footer__inner">
                    <div class="footer__info">
                        <p class="footer__tel">
                            TEL 02-3141-1305  / 1306    E-mail  cser@wixon.co.kr  /  기업부설연구소 제 2021154317호
                        </p>
                        <address>
                            서울시 마포구 동교로 215-1 한사 스튜디오 406 (주)윅슨어소시에이츠 / #406 , HANSA Studio, 215-1, Donggyo-ro, Mapo-gu, Seoul,  Korea
                        </address>
                        <p class="copywriter">
                            &copy; wixon associates Inc. 2022
                        </p>
                        <p class="slogan">
                            wixon. Who Invariable eXistence On the New era " wixon associates Inc. "
                        </p>
                        <ul>
                            <li><a href="/"><img src="/static/images/opusclam.png" alt="WIXON" /></a></li>
                            <li><a href="/"><img src="/static/images/lpstock.png" alt="WIXON" /></a></li>
                        </ul>
                    </div>
                    <h2 class="footer__logo">
                        <a href="/"><img src="/static/images/logo.png" alt="WIXON" /></a>
                    </h2>
                </div>
            </footer>
    </div>
    <script>
        function blogDelete(id) {
            Swal.fire({
                title: '정말로 삭제하시겠습니까?',
                text: "이 작업은 되돌릴 수 없습니다!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '네, 삭제합니다!'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajax({
                        url: "/blog/" + id,
                        type: "DELETE",
                        success: function (result) {
                            Swal.fire(
                                '삭제 완료!',
                                '포스트가 성공적으로 삭제되었습니다.',
                                'success'
                            );
                            // 포스트를 UI에서 삭제하거나 페이지를 다시 로드합니다.
                            location.href = '/';
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            Swal.fire(
                                '오류!',
                                '문제가 발생했습니다: ' + textStatus,
                                'error'
                            );
                        }
                    });
                }
            });
        }
        $(document).ready(function(){
            var cheack_li = $(".other__list li").length;
            if(cheack_li>1){
                $(".other__list li:first-child").css("borderBottom","1px solid #d2d2d2");
            }
        })
    </script>
{% endblock %}
</body>
</html>

