@extends('layouts.admin', ['heading' => 'Settings', 'subheading' => 'System configuration'])

@section('content')
    <form method="POST" action="{{ route('admin.settings.update') }}" enctype="multipart/form-data" class="space-y-6">
        @csrf

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">Company Profile</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
                <div>
                    <label class="mb-1 block text-sm font-medium">Company Name</label>
                    <input name="company_name" value="{{ setting('company_name') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Company Email</label>
                    <input name="company_email" value="{{ setting('company_email') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Company Phone</label>
                    <input name="company_phone" value="{{ setting('company_phone') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Company Address</label>
                    <input name="company_address" value="{{ setting('company_address') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Currency</label>
                    <input name="currency" value="{{ setting('currency') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Timezone</label>
                    <input name="timezone" value="{{ setting('timezone', 'Asia/Kolkata') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Language</label>
                    <input name="language" value="{{ setting('language', 'en') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Company Logo</label>
                    <input type="file" name="company_logo" class="w-full rounded border p-2" />
                    @if(setting('company_logo'))
                        <div class="mt-2 text-xs text-slate-500">Current: {{ setting('company_logo') }}</div>
                    @endif
                </div>
            </div>
        </div>

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">Admin Controls</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
            <div>
                <label class="mb-1 block text-sm font-medium">Admin Secret Slug</label>
                <input name="admin_slug" value="{{ setting('admin_slug', 'admin') }}" class="w-full rounded border p-2" />
                <div class="mt-1 text-xs text-slate-500">Admin login URL: {{ url('/'.setting('admin_slug', 'admin')) }}</div>
            </div>
            <div>
                <label class="mb-1 block text-sm font-medium">Root User ID</label>
                <input name="company_root_user_id" value="{{ setting('company_root_user_id') }}" class="w-full rounded border p-2" />
                <div class="mt-1 text-xs text-slate-500">Dashboard left/right metrics start from this user.</div>
            </div>
            <div>
                <label class="mb-1 block text-sm font-medium">KYC Required</label>
                <select name="kyc_required" class="w-full rounded border p-2">
                    <option value="1" @selected(setting('kyc_required', '1') == '1')>Enabled</option>
                    <option value="0" @selected(setting('kyc_required', '1') == '0')>Disabled</option>
                </select>
            </div>
            </div>
        </div>

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">Matching & Capping</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-3">
                <div>
                    <label class="mb-1 block text-sm font-medium">Joining Pair Value</label>
                    <input name="joining_pair_value" value="{{ setting('joining_pair_value') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Pair Rate</label>
                    <input name="pair_rate" value="{{ setting('pair_rate') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Daily Capping</label>
                    <input name="daily_capping" value="{{ setting('daily_capping') }}" class="w-full rounded border p-2" />
                </div>
            </div>
        </div>

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">Withdrawal Rules</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-4">
                <div>
                    <label class="mb-1 block text-sm font-medium">Withdrawal Min</label>
                    <input name="withdrawal_min" value="{{ setting('withdrawal_min') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Daily Limit</label>
                    <input name="withdrawal_daily_limit" value="{{ setting('withdrawal_daily_limit') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Weekly Limit</label>
                    <input name="withdrawal_weekly_limit" value="{{ setting('withdrawal_weekly_limit') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Fixed Charge</label>
                    <input name="withdrawal_charge_fixed" value="{{ setting('withdrawal_charge_fixed') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">TDS Percent</label>
                    <input name="tds_percent" value="{{ setting('tds_percent') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Charge Percent</label>
                    <input name="charge_percent" value="{{ setting('charge_percent') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Hold Days</label>
                    <input name="hold_days" value="{{ setting('hold_days') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Auto Approve</label>
                    <select name="withdrawal_auto_approve" class="w-full rounded border p-2">
                        <option value="0" @selected(setting('withdrawal_auto_approve', '0') == '0')>Manual</option>
                        <option value="1" @selected(setting('withdrawal_auto_approve', '0') == '1')>Auto</option>
                    </select>
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Payout Gateway</label>
                    <input name="payout_gateway" value="{{ setting('payout_gateway', 'manual') }}" class="w-full rounded border p-2" />
                </div>
            </div>
        </div>

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">Identity & UPI Controls</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-4">
                <div>
                    <label class="mb-1 block text-sm font-medium">Max IDs per Mobile</label>
                    <input name="max_ids_mobile" value="{{ setting('max_ids_mobile') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Max IDs per Email</label>
                    <input name="max_ids_email" value="{{ setting('max_ids_email') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Max IDs per PAN</label>
                    <input name="max_ids_pan" value="{{ setting('max_ids_pan') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Max IDs per Bank</label>
                    <input name="max_ids_bank" value="{{ setting('max_ids_bank') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">UPI Amount Tolerance</label>
                    <input name="upi_amount_tolerance" value="{{ setting('upi_amount_tolerance') }}" class="w-full rounded border p-2" />
                </div>
            </div>
        </div>

        <div class="admin-card p-5">
            <div class="mb-4 text-sm font-semibold text-slate-700">API & Notifications</div>
            <div class="grid grid-cols-1 gap-4 md:grid-cols-3">
                <div>
                    <label class="mb-1 block text-sm font-medium">API Rate Limit / Minute</label>
                    <input name="api_rate_limit_per_minute" value="{{ setting('api_rate_limit_per_minute') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">API Rate Limit / Day</label>
                    <input name="api_rate_limit_per_day" value="{{ setting('api_rate_limit_per_day') }}" class="w-full rounded border p-2" />
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">SMS Notifications</label>
                    <select name="notification_sms_enabled" class="w-full rounded border p-2">
                        <option value="1" @selected(setting('notification_sms_enabled', '1') == '1')>Enabled</option>
                        <option value="0" @selected(setting('notification_sms_enabled', '1') == '0')>Disabled</option>
                    </select>
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Email Notifications</label>
                    <select name="notification_email_enabled" class="w-full rounded border p-2">
                        <option value="1" @selected(setting('notification_email_enabled', '1') == '1')>Enabled</option>
                        <option value="0" @selected(setting('notification_email_enabled', '1') == '0')>Disabled</option>
                    </select>
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">WhatsApp Notifications</label>
                    <select name="notification_whatsapp_enabled" class="w-full rounded border p-2">
                        <option value="1" @selected(setting('notification_whatsapp_enabled', '0') == '1')>Enabled</option>
                        <option value="0" @selected(setting('notification_whatsapp_enabled', '0') == '0')>Disabled</option>
                    </select>
                </div>
                <div>
                    <label class="mb-1 block text-sm font-medium">Push Notifications</label>
                    <select name="notification_push_enabled" class="w-full rounded border p-2">
                        <option value="1" @selected(setting('notification_push_enabled', '1') == '1')>Enabled</option>
                        <option value="0" @selected(setting('notification_push_enabled', '1') == '0')>Disabled</option>
                    </select>
                </div>
            </div>
        </div>

        <button class="rounded bg-emerald-600 px-4 py-2 font-semibold text-white">Save Settings</button>
    </form>
@endsection
