@extends('admin.layouts.app')

@section('title', '系统参数配置')

@section('content')
    <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">修改系统运行参数</h2>
                <p class="text-xs text-gray-500 mt-1">保存后会同步更新 Redis 缓存，前台实时生效。</p>
            </div>
        </div>

        <div class="p-6">
            <form action="{{ route('admin.system.update') }}" method="POST">
                @csrf
                @method('PUT')

                <div class="space-y-6 max-w-2xl">
                    @foreach ($params as $alias => $body)
                        <div>
                            <label class="block text-sm font-bold text-gray-700 mb-2">
                                {{ $descriptions[$alias] ?? $alias }}
                                <span class="text-gray-400 font-normal ml-2">[{{ $alias }}]</span>
                            </label>
                            @if (strlen($body) > 50 || str_contains($body, "\n") || str_contains($body, '<'))
                                <textarea name="{{ $alias }}" rows="4"
                                    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 whitespace-pre-wrap">{{ $body }}</textarea>
                            @else
                                <input type="text" name="{{ $alias }}" value="{{ $body }}"
                                    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">
                            @endif
                        </div>
                    @endforeach
                </div>

                <div class="mt-8 pt-6 border-t flex space-x-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
