"use client";
import { __awaiter } from '../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
import { jsx } from 'react/jsx-runtime';
import { SignIn } from '@clerk/nextjs';
import { useEffect } from 'react';
import { useFingerprintContextSafe } from './fingerprint/fingerprint-provider.mjs';

/**
 * SignIn component with fingerprint awareness
 * 如果没有FingerprintProvider，会优雅降级为普通SignIn组件
 * 如果有FingerprintProvider，会处理fingerprint相关逻辑
 */
function SignInWithFingerprint() {
    const fingerprintContext = useFingerprintContextSafe();
    // 如果没有fingerprint context，使用默认值
    const { fingerprintId = null, xUser = null, isInitialized = false, initializeAnonymousUser = () => __awaiter(this, void 0, void 0, function* () { }) } = fingerprintContext || {};
    // 准备传递给Clerk的metadata，包含匿名用户信息
    const unsafeMetadata = {
        user_id: (xUser === null || xUser === void 0 ? void 0 : xUser.userId) || null,
        fingerprint_id: fingerprintId || null,
    };
    // 确保匿名用户已初始化
    useEffect(() => {
        if (!isInitialized && fingerprintId) {
            initializeAnonymousUser();
        }
    }, [fingerprintId, isInitialized, initializeAnonymousUser]);
    // 调试日志和处理登录逻辑
    useEffect(() => {
        console.log('SignInWithFingerprint on [redirect] DEBUG:', {
            fingerprintProvider: fingerprintContext ? 'Available' : 'Not found',
            fingerprintId: fingerprintId || 'Not generated',
            xUser: xUser ? 'Initialized' : 'Not initialized',
            clerkMetadata: unsafeMetadata
        });
    }, [xUser, fingerprintId, fingerprintContext, unsafeMetadata]);
    return jsx(SignIn, { unsafeMetadata: unsafeMetadata });
}

export { SignInWithFingerprint };
