@php
    $pageTitle = '공지사항';
    $pageDesc  = '서비스 운영 및 결제/발송 관련 안내를 확인하세요.';

    $breadcrumbs = [
      ['label' => '홈', 'url' => url('/')],
      ['label' => '고객센터', 'url' => url('/cs')],
      ['label' => '공지사항', 'url' => url('/cs/notice')],
      ['label' => $notice->subject, 'url' => url()->current()],
    ];

    $csActive = 'notice';
    $dt = $notice->regdateCarbon();

    // 첨부파일명 추출(경로/URL 모두 대응)
    $file1 = $notice->file_01 ? basename(parse_url($notice->file_01, PHP_URL_PATH) ?? $notice->file_01) : null;
    $file2 = $notice->file_02 ? basename(parse_url($notice->file_02, PHP_URL_PATH) ?? $notice->file_02) : null;
@endphp

@extends('web.layouts.subpage')

@section('title', e($notice->subject) . ' | 공지사항 | PIN FOR YOU')
@section('meta_description', 'PIN FOR YOU 공지사항 상세 페이지입니다.')
@section('canonical', url('/cs/notice/'.$notice->seq))

@push('styles')
    <link rel="stylesheet" href="{{ asset('assets/css/cs-notice.css') }}">
@endpush

@section('subcontent')
    <div class="notice-view">

        {{-- 상단: 목록보기 버튼 --}}
        <div class="nv-top">
            <a class="nv-btn nv-btn--ghost"
               href="{{ route('web.cs.notice.index', request()->only('q','page')) }}">
                목록보기
            </a>
        </div>

        <article class="nv-card">
            <header class="nv-head">
                <h2 class="nv-title nv-title--sm">{{ $notice->subject }}</h2>
                <div class="nv-meta">
                    <time>{{ $dt ? $dt->format('Y.m.d H:i') : '-' }}</time>
                    <span class="nv-dot">·</span>
                    <span>조회 {{ number_format((int)$notice->hit) }}</span>
                </div>
            </header>

            {{-- ✅ 내용 박스 라인 + 내부 패딩 --}}
            <div class="nv-content-box">
                <div class="nv-body editor-content">
                    {!! $notice->content !!}
                </div>

                {{-- 첨부/링크 --}}
                @php
                    $link1 = $notice->safeLink($notice->link_01);
                    $link2 = $notice->safeLink($notice->link_02);
                @endphp

                @if($link1 || $link2 || $notice->file_01 || $notice->file_02)
                    <section class="nv-resources" aria-label="첨부 및 관련 링크">
                        <div class="nv-resources__head">
                            <div class="nv-resources__title">첨부 / 링크</div>
                            <div class="nv-resources__desc">필요한 자료를 빠르게 열어보세요.</div>
                        </div>

                        <div class="nv-resources__grid">

                            @if($notice->file_01)
                                <a class="nv-attach-item"
                                   href="{{ route('web.cs.notice.file', ['seq' => $notice->seq, 'slot' => 1]) }}">
                                    <span class="nv-attach-name">{{ $file1 }}</span>
                                    <span class="nv-attach-action">다운로드</span>
                                </a>
                            @endif

                            @if($notice->file_02)
                                <a class="nv-attach-item"
                                   href="{{ route('web.cs.notice.file', ['seq' => $notice->seq, 'slot' => 2]) }}">
                                    <span class="nv-attach-name">{{ $file2 }}</span>
                                    <span class="nv-attach-action">다운로드</span>
                                </a>
                            @endif

                            @if($link1)
                                <a class="nv-item" href="{{ $link1 }}" target="_blank" rel="noopener">
                                    <div class="nv-item__left">
                                        <span class="nv-badge nv-badge--link">LINK</span>
                                        <span class="nv-item__name">관련 링크 1</span>
                                    </div>
                                    <span class="nv-item__right">열기 →</span>
                                </a>
                            @endif

                            @if($link2)
                                <a class="nv-item" href="{{ $link2 }}" target="_blank" rel="noopener">
                                    <div class="nv-item__left">
                                        <span class="nv-badge nv-badge--link">LINK</span>
                                        <span class="nv-item__name">관련 링크 2</span>
                                    </div>
                                    <span class="nv-item__right">열기 →</span>
                                </a>
                            @endif

                        </div>
                    </section>
                @endif

                {{--  박스 안에서 하단 네비(이전/다음/목록) --}}
                <nav class="nv-actions nv-actions--webonly" aria-label="공지 네비게이션">
                    @if($prev)
                        <a class="nv-action nv-action--prev"
                           href="{{ route('web.cs.notice.show', ['seq' => $prev->seq]) }}">
                            <div class="nv-action-top">이전</div>
                            <div class="nv-action-title">{{ $prev->subject }}</div>
                        </a>
                    @else
                        <div class="nv-action nv-action--disabled" aria-disabled="true">
                            <div class="nv-action-top">이전</div>
                            <div class="nv-action-title">없음</div>
                        </div>
                    @endif

                    @if($next)
                        <a class="nv-action nv-action--next"
                           href="{{ route('web.cs.notice.show', ['seq' => $next->seq]) }}">
                            <div class="nv-action-top">다음</div>
                            <div class="nv-action-title">{{ $next->subject }}</div>
                        </a>
                    @else
                        <div class="nv-action nv-action--disabled" aria-disabled="true">
                            <div class="nv-action-top">다음</div>
                            <div class="nv-action-title">없음</div>
                        </div>
                    @endif

                </nav>

            </div>
        </article>

    </div>

    @include('web.partials.cs-quick-actions')
@endsection

