"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDeviceTransactionConfig = void 0;
const react_1 = require("react");
const deviceTransactionConfig_1 = require("../transaction/deviceTransactionConfig");
/**
 * Hook to fetch device transaction configuration fields asynchronously.
 * This anticipates the future async nature of crypto assets store operations.
 */
function useDeviceTransactionConfig({ account, parentAccount, transaction, status, }) {
    const [fields, setFields] = (0, react_1.useState)([]);
    const [loading, setLoading] = (0, react_1.useState)(true);
    (0, react_1.useEffect)(() => {
        let mounted = true;
        async function loadFields() {
            try {
                setLoading(true);
                const result = await (0, deviceTransactionConfig_1.getDeviceTransactionConfig)({
                    account,
                    parentAccount,
                    transaction,
                    status,
                });
                if (mounted) {
                    setFields(result);
                    setLoading(false);
                }
            }
            catch (error) {
                console.error("Failed to load device transaction config:", error);
                if (mounted) {
                    setFields([]);
                    setLoading(false);
                }
            }
        }
        loadFields();
        return () => {
            mounted = false;
        };
    }, [account, parentAccount, transaction, status]);
    return { fields, loading };
}
exports.useDeviceTransactionConfig = useDeviceTransactionConfig;
//# sourceMappingURL=useDeviceTransactionConfig.js.map