@php $pageTitle = '会员中心 - '.$siteName; @endphp
@include('partials.head')
<body>
@include('partials.header')
<div class="container main-layout">
    <main class="content">
        <h1 class="list-title">会员中心</h1>
        @auth
            @php $member = app(\Plugins\Neatstudio\Membership\Services\MembershipService::class)->isMember(auth()->user()); @endphp
            @if($member)
                <div class="alert alert-success">你是会员，可阅读全部会员专享内容。</div>
            @else
                <div class="alert alert-error">你还不是会员，开通后可解锁会员专享文章。</div>
            @endif
        @else
            <div class="alert alert-error">请先 <a href="{{ route('login') }}">登录</a> 后购买会员。</div>
        @endauth

        <div class="plans-grid" style="display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:16px;">
            @forelse($plans as $plan)
                <div class="post-card plan-card">
                    <h2 class="post-title">{{ $plan->name }}</h2>
                    <p class="plan-price" style="font-size:26px;font-weight:800;color:#2d6cdf;">¥{{ number_format($plan->price / 100, 2) }}</p>
                    <p style="color:#888;font-size:14px;">有效期 {{ $plan->duration_days }} 天</p>
                    @if($plan->description)<p style="color:#555;font-size:14px;">{{ $plan->description }}</p>@endif
                    @auth
                        <form action="{{ route('membership.subscribe', $plan) }}" method="post" style="margin-top:12px;">
                            @csrf
                            <button type="submit" class="btn btn-primary">立即购买</button>
                        </form>
                    @endauth
                </div>
            @empty
                <div class="empty">暂无上架套餐</div>
            @endforelse
        </div>

        <p style="margin-top:16px;"><a href="{{ route('membership.mine') }}">查看我的订阅</a></p>
    </main>
    @include('partials.sidebar')
</div>
@include('partials.footer')
</body>
</html>
