{{--
    文件功能：后台 VIP 支付配置页面
    用于维护聊天室对接 NovaLink 支付中心所需的开关、地址与签名密钥
--}}
@extends('admin.layouts.app')

@section('title', 'VIP 支付配置')

@section('content')
    @php
        $enabled = $params['vip_payment_enabled'] ?? '0';
        $syncReturnUrl = route('vip.payment.return');
        $asyncNotifyUrl = route('vip.payment.notify');
    @endphp

    <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="p-6 border-b border-gray-100 flex justify-between items-center bg-gray-50">
            <div>
                <h2 class="text-lg font-bold text-gray-800">VIP 在线支付配置</h2>
                <p class="text-xs text-gray-500 mt-1">当前仅对接 NovaLink 支付中心，用于聊天室 VIP 会员购买。</p>
            </div>
        </div>

        <div class="p-6">
            <div class="mb-6 bg-indigo-50 border border-indigo-200 rounded-xl p-4 text-sm text-indigo-800">
                <p class="font-bold">接入说明</p>
                <p class="mt-1">请先在 NovaLink 支付系统中创建“接入应用”，再把该应用的地址、App Key 和 App Secret 填入这里。</p>
            </div>

            <form action="{{ route('admin.vip-payment.update') }}" method="POST" class="space-y-6 max-w-3xl">
                @csrf
                @method('PUT')

                <div>
                    <label class="block text-sm font-bold text-gray-700 mb-2">{{ $descriptions['vip_payment_enabled'] }}</label>
                    <div class="flex items-center gap-6 text-sm text-gray-700">
                        <label class="inline-flex items-center gap-2">
                            <input type="radio" name="vip_payment_enabled" value="1" {{ old('vip_payment_enabled', $enabled) === '1' ? 'checked' : '' }}>
                            <span>开启</span>
                        </label>
                        <label class="inline-flex items-center gap-2">
                            <input type="radio" name="vip_payment_enabled" value="0" {{ old('vip_payment_enabled', $enabled) !== '1' ? 'checked' : '' }}>
                            <span>关闭</span>
                        </label>
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-bold text-gray-700 mb-2">{{ $descriptions['vip_payment_base_url'] }}</label>
                    <input type="text" name="vip_payment_base_url"
                        value="{{ old('vip_payment_base_url', $params['vip_payment_base_url'] ?? '') }}"
                        placeholder="https://novalink.test"
                        class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border">
                </div>

                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                        <label class="block text-sm font-bold text-gray-700 mb-2">{{ $descriptions['vip_payment_app_key'] }}</label>
                        <input type="text" name="vip_payment_app_key"
                            value="{{ old('vip_payment_app_key', $params['vip_payment_app_key'] ?? '') }}"
                            class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border">
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-gray-700 mb-2">{{ $descriptions['vip_payment_timeout'] }}</label>
                        <input type="number" name="vip_payment_timeout"
                            value="{{ old('vip_payment_timeout', $params['vip_payment_timeout'] ?? 10) }}"
                            min="3" max="30"
                            class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border">
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-bold text-gray-700 mb-2">{{ $descriptions['vip_payment_app_secret'] }}</label>
                    <input type="password" name="vip_payment_app_secret"
                        value="{{ old('vip_payment_app_secret', $params['vip_payment_app_secret'] ?? '') }}"
                        class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border">
                    <p class="mt-2 text-xs text-gray-500">该密钥仅用于服务器与支付中心之间的签名通信，请勿提供给前端。</p>
                </div>

                <div class="bg-amber-50 border border-amber-200 rounded-xl p-4 text-sm text-amber-900 space-y-4">
                    <div>
                        <p class="font-bold">系统回调说明</p>
                        <p class="mt-1">请把下面两个地址分别填写到 NovaLink 支付系统“编辑应用”的同步返回地址与异步通知地址中。</p>
                    </div>

                    <div>
                        <label class="block text-sm font-bold text-amber-900 mb-2">同步返回地址</label>
                        <input type="text" value="{{ $syncReturnUrl }}" readonly
                            onclick="this.select();"
                            class="w-full border-amber-200 rounded-md shadow-sm p-2.5 bg-white border text-gray-700 font-mono text-sm cursor-pointer">
                    </div>

                    <div>
                        <label class="block text-sm font-bold text-amber-900 mb-2">异步通知地址</label>
                        <input type="text" value="{{ $asyncNotifyUrl }}" readonly
                            onclick="this.select();"
                            class="w-full border-amber-200 rounded-md shadow-sm p-2.5 bg-white border text-gray-700 font-mono text-sm cursor-pointer">
                    </div>
                </div>

                <div class="pt-6 border-t flex gap-3">
                    <button type="submit"
                        class="px-6 py-2 bg-indigo-600 text-white rounded-md font-bold hover:bg-indigo-700 shadow-sm transition">保存配置</button>
                </div>
            </form>
        </div>
    </div>
@endsection
