'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../../_virtual/_tslib.cjs');
var React = require('react');
var utils = require('@dynamic-labs/utils');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
require('../../../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
var useInternalDynamicContext = require('../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
var user = require('../../../../data/api/user/user.cjs');
var client = require('../../../../client/client.cjs');
var primaryWalletId = require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');

const useUnlinkUserEmail = () => {
    const { environmentId } = useInternalDynamicContext.useInternalDynamicContext();
    const unlinkUserEmail = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ verifiedCredentialId }) {
        var _b;
        const user$1 = (_b = client.getDynamicClient()) === null || _b === void 0 ? void 0 : _b.user;
        const primaryWalletId$1 = primaryWalletId.getPrimaryWalletId();
        if (!primaryWalletId$1) {
            throw new utils.DynamicError('Primary wallet not found', 'primary_wallet_not_found');
        }
        const verifiedCredential = user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials.find((credential) => credential.id === verifiedCredentialId);
        if (!verifiedCredential) {
            throw new utils.DynamicError('Verified credential not found', 'verified_credential_not_found');
        }
        if (verifiedCredential.format !== sdkApiCore.JwtVerifiedCredentialFormatEnum.Email) {
            throw new utils.DynamicError('Verified credential is not an email', 'verified_credential_is_not_an_email');
        }
        return user.unlinkEmail({
            environmentId,
            primaryWalletId: primaryWalletId$1,
            verifiedCredentialId,
        });
    }), [environmentId]);
    return unlinkUserEmail;
};

exports.useUnlinkUserEmail = useUnlinkUserEmail;
