@extends('admin.layouts.app')

@section('title', '渠道配置')
@section('page_title', '渠道配置')

@section('content')
<div class="page-header mb-20" data-page="admin.settings.channels">
    <div class="page-header-main">
        <div>
            <div class="page-header-title">渠道配置</div>
            <div class="page-header-subtitle">用于承接多端渠道与平台支付能力基线（数据库读取）；当前已支持基础编辑与保存。</div>
        </div>
        <div class="page-header-actions">
            <a class="btn btn-secondary" href="/admin/settings/system">系统配置</a>
        </div>
    </div>

    <div class="page-header-meta">
        <div>当前渠道与支付配置概览已接入缓存读取</div>
        <div>当前平台商家数：{{ $merchantCount }}</div>
    </div>
</div>

<div class="card list-card mb-20">
    <div class="list-card-header">
        <div>
            <h3 class="list-card-title">渠道基线</h3>
        </div>
    </div>
    <div class="list-card-body">
        <table class="list-card-table">
            <thead>
            <tr>
                <th>渠道编码</th>
                <th>渠道名称</th>
                <th>类型</th>
                <th>状态</th>
                <th>入口</th>
                <th>登录</th>
                <th>支付</th>
                <th>分享</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($channels as $channel)
                <tr>
                    <form method="post" action="/admin/settings/channels/{{ $channel->id }}">
                        @csrf
                        <td>{{ $channel->channel_code }}</td>
                        <td><input name="channel_name" value="{{ old('channel_name', $channel->channel_name) }}"></td>
                        <td><input name="channel_type" value="{{ old('channel_type', $channel->channel_type) }}"></td>
                        <td>
                            <select name="status">
                                @foreach(['enabled', 'disabled', 'reserved'] as $status)
                                    <option value="{{ $status }}" @selected(old('status', $channel->status) === $status)>{{ $status }}</option>
                                @endforeach
                            </select>
                        </td>
                        <td><input name="entry_path" value="{{ old('entry_path', $channel->entry_path) }}"></td>
                        <td><label><input type="checkbox" name="supports_login" value="1" @checked((bool) old('supports_login', $channel->supports_login))> yes</label></td>
                        <td><label><input type="checkbox" name="supports_payment" value="1" @checked((bool) old('supports_payment', $channel->supports_payment))> yes</label></td>
                        <td><label><input type="checkbox" name="supports_share" value="1" @checked((bool) old('supports_share', $channel->supports_share))> yes</label></td>
                        <td><textarea name="remark" rows="2" class="w-full">{{ old('remark', $channel->remark) }}</textarea></td>
                        <td><button type="submit" class="btn btn-sm">保存</button></td>
                    </form>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>

<div class="card list-card">
    <div class="list-card-header">
        <div>
            <h3 class="list-card-title">支付配置基线</h3>
        </div>
    </div>
    <div class="list-card-body">
        <table class="list-card-table">
            <thead>
            <tr>
                <th>支付编码</th>
                <th>支付名称</th>
                <th>提供方</th>
                <th>状态</th>
                <th>沙箱</th>
                <th>退款</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($paymentConfigs as $payment)
                <tr>
                    <form method="post" action="/admin/settings/payments/{{ $payment->id }}">
                        @csrf
                        <td>{{ $payment->payment_code }}</td>
                        <td><input name="payment_name" value="{{ old('payment_name', $payment->payment_name) }}"></td>
                        <td><input name="provider" value="{{ old('provider', $payment->provider) }}"></td>
                        <td>
                            <select name="status">
                                @foreach(['enabled', 'disabled', 'reserved'] as $status)
                                    <option value="{{ $status }}" @selected(old('status', $payment->status) === $status)>{{ $status }}</option>
                                @endforeach
                            </select>
                        </td>
                        <td><label><input type="checkbox" name="is_sandbox" value="1" @checked((bool) old('is_sandbox', $payment->is_sandbox))> yes</label></td>
                        <td><label><input type="checkbox" name="supports_refund" value="1" @checked((bool) old('supports_refund', $payment->supports_refund))> yes</label></td>
                        <td><textarea name="remark" rows="2" class="w-full">{{ old('remark', $payment->remark) }}</textarea></td>
                        <td><button type="submit" class="btn btn-sm">保存</button></td>
                    </form>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection
