"use strict";
/**
 * CLIProxy OAuth Authentication Operations
 *
 * Handles:
 * - ccs cliproxy list
 * - OAuth status display
 * - Built-in profile authentication status
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleList = void 0;
const auth_handler_1 = require("../../cliproxy/auth/auth-handler");
const services_1 = require("../../cliproxy/services");
const ui_1 = require("../../utils/ui");
async function handleList() {
    await (0, ui_1.initUI)();
    console.log((0, ui_1.header)('CLIProxy Profiles'));
    console.log('');
    // Built-in profiles
    console.log((0, ui_1.subheader)('Built-in Profiles'));
    const authStatuses = (0, auth_handler_1.getAllAuthStatus)();
    for (const status of authStatuses) {
        const oauthConfig = (0, auth_handler_1.getOAuthConfig)(status.provider);
        const icon = status.authenticated ? (0, ui_1.ok)('') : (0, ui_1.warn)('');
        const authLabel = status.authenticated
            ? (0, ui_1.color)('authenticated', 'success')
            : (0, ui_1.dim)('not authenticated');
        const lastAuthStr = status.lastAuth ? (0, ui_1.dim)(` (${status.lastAuth.toLocaleDateString()})`) : '';
        console.log(`  ${icon} ${(0, ui_1.color)(status.provider, 'command').padEnd(18)} ${oauthConfig.displayName.padEnd(16)} ${authLabel}${lastAuthStr}`);
    }
    console.log('');
    console.log((0, ui_1.dim)('  To authenticate: ccs <provider> --auth'));
    console.log((0, ui_1.dim)('  To logout:       ccs <provider> --logout'));
    console.log('');
    // Custom variants
    const variants = (0, services_1.listVariants)();
    const variantNames = Object.keys(variants);
    if (variantNames.length > 0) {
        console.log((0, ui_1.subheader)('Custom Variants'));
        const rows = variantNames.map((name) => {
            const variant = variants[name];
            const providerDisplay = variant.type === 'composite' ? 'composite' : variant.provider;
            const portStr = variant.port ? String(variant.port) : '-';
            return [name, providerDisplay, variant.target || 'claude', portStr, variant.settings || '-'];
        });
        console.log((0, ui_1.table)(rows, {
            head: ['Variant', 'Provider', 'Target', 'Port', 'Settings'],
            colWidths: [15, 12, 10, 8, 24],
        }));
        console.log('');
        console.log((0, ui_1.dim)(`Total: ${variantNames.length} custom variant(s)`));
        console.log('');
    }
    console.log((0, ui_1.dim)('To create a custom variant:'));
    console.log(`  ${(0, ui_1.color)('ccs cliproxy create', 'command')}`);
    console.log('');
}
exports.handleList = handleList;
//# sourceMappingURL=auth-subcommand.js.map