import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { executeTransactionOperation } from '../deployCreate2.js';
import { useOperation } from '../../../stores/operationStore.js';
import { Spinner, Badge } from '@inkjs/ui';
import { useWaitForTransactionReceipt } from 'wagmi';
import { getBlockExplorerAddressLink } from '../../../util/blockExplorer.js';
import { Text, Box } from 'ink';
export const PrivateKeyExecution = ({ chain, initCode, baseSalt, deterministicAddress, }) => {
    const { status, data: transactionHash, error, } = useOperation(executeTransactionOperation({
        chainId: chain.id,
        deterministicAddress,
        initCode,
        baseSalt,
    }));
    const { isLoading: isReceiptLoading } = useWaitForTransactionReceipt({
        hash: transactionHash,
        chainId: chain.id,
    });
    if (status === 'pending') {
        return _jsx(Spinner, { label: "Deploying contract" });
    }
    if (error) {
        return (_jsxs(Text, { children: ["Error deploying contract: ", error.shortMessage || error.message] }));
    }
    if (isReceiptLoading) {
        return _jsx(Spinner, { label: "Waiting for receipt" });
    }
    return (_jsxs(Box, { gap: 1, children: [_jsx(Badge, { color: "green", children: "Deployed" }), _jsx(Text, { children: "Contract successfully deployed" }), _jsx(Text, { children: getBlockExplorerAddressLink(chain, deterministicAddress) })] }));
};
