<div class="max-w-2xl mx-auto">
    <div class="flex items-center gap-3 mb-6"><a href="?page=integrations" class="text-gray-400 hover:text-gray-600"><svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg></a><h1 class="text-2xl font-bold text-gray-900">Configure <?= ucwords(str_replace('_',' ',$provider)) ?></h1></div>
    <?php $settings = $integration ? json_decode($integration['settings'] ?? '{}', true) : []; ?>
    <form method="POST" action="?page=integrations&action=save" class="space-y-6"><?= CSRF::field() ?>
        <input type="hidden" name="provider" value="<?= htmlspecialchars($provider) ?>">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <div class="space-y-4">
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                    <select name="status" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"><option value="active" <?= ($integration['status'] ?? '') === 'active' ? 'selected' : '' ?>>Active</option><option value="inactive" <?= ($integration['status'] ?? 'inactive') === 'inactive' ? 'selected' : '' ?>>Inactive</option></select></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">API Key</label><input type="text" name="settings[api_key]" value="<?= htmlspecialchars($settings['api_key'] ?? '') ?>" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500" placeholder="Enter API key"></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">API Secret</label><input type="password" name="settings[api_secret]" value="<?= htmlspecialchars($settings['api_secret'] ?? '') ?>" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500" placeholder="Enter API secret"></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Webhook URL</label><input type="text" name="settings[webhook_url]" value="<?= htmlspecialchars($settings['webhook_url'] ?? '') ?>" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500 bg-gray-50" placeholder="Auto-generated" readonly></div>
                <div><label class="flex items-center gap-2"><input type="checkbox" name="settings[test_mode]" value="1" <?= !empty($settings['test_mode']) ? 'checked' : '' ?> class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"><span class="text-sm text-gray-700">Test/Sandbox Mode</span></label></div>
            </div>
        </div>
        <div class="flex justify-between">
            <button type="button" class="px-4 py-2 border border-gray-300 text-gray-500 rounded-lg text-sm" disabled>Test Connection</button>
            <div class="flex gap-3"><a href="?page=integrations" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium">Cancel</a><button type="submit" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 text-sm font-medium">Save</button></div>
        </div>
    </form>
</div>
