@php
    $service = app(\Plugins\Neatstudio\Membership\Services\MembershipService::class);
    $user = auth()->user();
    $isMember = $user && $service->isMember($user);
    $price = (int) ($post->meta['price'] ?? 0);
    $plansExist = \Plugins\Neatstudio\Membership\Models\MembershipPlan::query()->where('active', true)->exists();
@endphp

<div class="paywall" role="note" aria-label="付费内容">
    @if($cover = $post->getFirstMedia('cover'))
        <div class="paywall-cover">
            <img src="{{ $cover->getUrl('card') ?: $cover->getUrl() }}" alt="{{ $post->title }}">
        </div>
    @endif

    <div class="paywall-body">
        <h2 class="paywall-title">{{ $post->title }}</h2>
        @if($post->excerpt_or_fallback)
            <p class="paywall-excerpt">{{ $post->excerpt_or_fallback }}</p>
        @endif

        @if($price > 0)
            <p class="paywall-price">单篇解锁 ¥{{ number_format($price / 100, 2) }}</p>
        @endif

        <p class="paywall-hint">
            @if($isMember)
                你是会员，本文可直接阅读。
            @else
                本文为{{ $price > 0 ? '付费内容' : '会员专享内容' }}，解锁或开通会员后可阅读全文。
            @endif
        </p>

        <div class="paywall-actions">
            @auth
                @if(! $isMember)
                    @if($price > 0)
                        <form action="{{ route('posts.unlock', $post) }}" method="post" style="display:inline">
                            @csrf
                            <button type="submit" class="btn btn-primary">单篇解锁</button>
                        </form>
                    @endif
                    @if($plansExist)
                        <a href="{{ route('membership.index') }}" class="btn">开通会员</a>
                    @endif
                @endif
            @else
                <a href="{{ route('login') }}" class="btn btn-primary">登录后解锁</a>
            @endauth
        </div>
    </div>
</div>
