<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>SaaSShop｜套餐与功能</title>
    <link rel="stylesheet" href="/css/platform.css">
</head>
<body>
<div class="wrap">
    <div class="flex-between flex-wrap gap-10">
        <div>
            <h1 class="h1" style="margin-bottom:6px;">套餐与功能</h1>
            <div class="muted">仅展示「已发布 + 启用中」套餐。开通入口（A：站点开通型）将优先在此页面逐步接入。</div>
        </div>
        <div class="flex gap-10 flex-wrap">
            <a class="btn" href="/platform">返回首页</a>
            <a class="btn" href="/admin/plans">运营管理套餐</a>
        </div>
    </div>

    @if(session('success'))
        <div class="flash">{{ session('success') }}</div>
    @endif

    @if($errors->any())
        <div class="error-box">
            <strong>提交失败：</strong>
            <ul>
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="grid-3">
        @forelse($plans as $p)
            <div class="card">
                <div class="flex-between gap-10">
                    <h3 class="h3" style="margin:0;">{{ $p->name }}</h3>
                    <span class="badge">{{ $p->billing_cycle }}</span>
                </div>
                <div class="muted mt-8">套餐编码：{{ $p->code }}</div>
                <div class="price">¥{{ number_format((float) $p->price, 2) }}</div>
                @if($p->description)
                    <div class="muted mt-8">{{ $p->description }}</div>
                @endif
                <div class="mt-12">
                    <form method="post" action="/platform/leads">
                        @csrf
                        <input type="hidden" name="plan_id" value="{{ $p->id }}">
                        <input type="hidden" name="source" value="platform_plans">

                        <div class="muted">开通意向（A：站点开通型，前期先由运营人工开通）</div>
                        <div class="mt-8">
                            <input class="input" name="name" placeholder="你的姓名" value="{{ old('name') }}" required>
                        </div>
                        <div class="mt-8">
                            <input class="input" name="mobile" placeholder="手机号（可选）" value="{{ old('mobile') }}">
                        </div>
                        <div class="mt-8">
                            <input class="input" name="company" placeholder="公司/团队（可选）" value="{{ old('company') }}">
                        </div>
                        <div class="mt-8">
                            <button type="submit" class="btn btn-primary">提交开通意向</button>
                            @php
                                // 对外页提供“运营手工下单”入口：显式声明 order_type，并带 back 回到套餐页，减少迷路。
                                // 注意：href 使用原样输出（避免 &amp; 影响部分测试/断言），并依赖 BackUrl 安全护栏。
                                $platformPlansBack = \App\Support\BackUrl::sanitizeForLinks('/platform/plans');
                                $createOrderUrl = \App\Support\BackUrl::withBack(
                                    '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query([
                                        'order_type' => 'new_purchase',
                                        'plan_id' => $p->id,
                                    ]),
                                    $platformPlansBack
                                );
                            @endphp
                            <a class="btn" href="{!! $createOrderUrl !!}">运营手工下单入口</a>
                        </div>
                        <div class="muted mt-8">提示：前期先跑通收费闭环与治理；自助开通/自助支付会在后续版本接入。</div>
                    </form>
                </div>
            </div>
        @empty
            <div class="card" style="grid-column: 1 / -1;">
                <div class="muted">当前暂无可对外展示的套餐（需满足：启用中 + 已发布）。</div>
            </div>
        @endforelse
    </div>
</div>
</body>
</html>
