import { chainIds as e } from "../../constants/chains.constants.mjs";
import { defaultSignatureData as t, zeroAddress as ee } from "../../constants/protocol.constants.mjs";
import { defaultHinkalLogicArgs as n } from "../../types/hinkal.types.mjs";
import { poseidonFunction as r } from "../../crypto/poseidon.mjs";
import { defaultHookData as te } from "../../types/circom-data.types.mjs";
import { ExternalActionId as ne } from "../../types/external-action.types.mjs";
import { randomBigInt as i } from "../web3/etherFunctions.mjs";
import { getCurrentTimeInSeconds as a } from "../utils/time.utils.mjs";
import { Utxo as re } from "../../data-structures/utxo/Utxo.mjs";
import { buildOutCommitments as o, calcAmountChanges as s, calcEncryptedOutputs as c, calcPublicSignalCount as l, calcStealthAddressStructure as u, createCallDataHash as ie, getSlippageValues as ae } from "./common.snarkjs.mjs";
import { generateCircomData as oe } from "./generateCircomData.mjs";
import { generateZkProof as se } from "./generateZkProof.mjs";
import { generateFeeStructure as ce } from "../utils/fees.utils.mjs";
import { AccountActions as le } from "../../data-structures/AccountActions/AccountActions.mjs";
import { createHinkalHelperFromData as d, hinkalCheckTokenRegistry as ue } from "../../data-structures/Hinkal/hinkalCheckTokenRegistry.mjs";
import { getDataFromWorkers as de } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
import { encodeEmporiumMetadata as fe, getAuthorizationDataIfNeeded as pe } from "../private-wallet/emporium.helpers.mjs";
import "../../crypto/index.mjs";
//#region libs/shared/common/src/functions/snarkjs/constructEmporiumProof.ts
var f = async (f, p, m, h, g, _, v, me, he, y, ge, _e, b = ee, x = e.localhost, S = g.map(() => !1), C = g.map(() => 0n), w, T = !1, E, D = void 0, O, k = t, A) => {
	let j = s(g, _), M = c(_), N = v.getShieldedPrivateKey(), P = re.findCorrectRandomization(i(31), N), F = await ue(O ?? d(x), m, s(g, _, !0)), { inCommitmentSiblings: I, inCommitmentSiblingSides: L, accessTokenSiblings: R, accessTokenSiblingSides: z, rootHashHinkal: B, rootHashAccessToken: V, inNullifiers: H } = await de(x, f, p, v, g.map((e) => e.map((e) => e.getConstructableParams())), T, F), U = o(_), W = A ?? i(31), ve = r(W), G = {
		rootHashHinkal: B,
		erc20TokenAddresses: m,
		tokenIds: h,
		inNullifiers: H,
		outTimeStamp: _.length > 0 ? BigInt(_[0][0].timeStamp) : a(),
		extraRandomization: P,
		amountChanges: j,
		outCommitments: U,
		rootHashAccessToken: V,
		calldataHash: 0n,
		shieldedPrivateKey: N,
		accessTokenSiblings: R,
		accessTokenSiblingSides: z,
		outAmounts: _.map((e) => e.map((e) => e.amount)),
		outPublicKeys: _.map((e) => e.map((e) => e.getStealthAddress())),
		inAmounts: g.map((e) => e.map((e) => e.amount.toString())),
		inTimeStamps: g.map((e) => e.map((e) => e.timeStamp)),
		inRandomizations: g.map((e) => e.map((e) => e.randomization)),
		inCommitmentSiblings: I,
		inCommitmentSiblingSides: L,
		messageSeed: W
	}, ye = w ? le.getSignerAddressFromPrivateKey(x, w) : void 0, K = y, q = ne.Emporium, J = await fe(x, y, w, ge, ve, ye), Y = _.length === 0 ? "swapperMWMin0" : `swapperMW${me}x${he}x${_[0].length}`, X = l(Y, G.erc20TokenAddresses, G.amountChanges, G.inNullifiers, G.outCommitments, h.length), Z = n(j.length, v);
	G.interactionAddress = Z.interactionAddress, G.externalApprovalAddresses = Z?.useApprovalUtxoData?.map(({ externalApprovalAddresses: e }) => e), D ||= ce(C, m);
	let Q = s(g, _, !0);
	E ||= ae(Q), G.calldataHash = ie(X, b, K, q, J, M, C, void 0, E, S, Z, D, k);
	let $ = {
		outTimeStamp: a(),
		rootHashAccessToken: V,
		calldataHash: G.calldataHash,
		shieldedPrivateKey: N,
		accessTokenSiblings: R,
		accessTokenSiblingSides: z,
		messageSeed: W
	}, [{ zkCallData: be }, xe] = await Promise.all([se(x, Y, Y === "swapperMWMin0" ? $ : G, _e), pe(x, w)]), Se = u(P, N);
	return {
		zkCallData: be,
		circomData: oe(U, H, B, V, Q, m, _, M, X, q, K, J, b, G.calldataHash, h, Se, S, te, Y === "swapperMWMin0" ? $.outTimeStamp : G.outTimeStamp, Z, E, D, k),
		dimData: {
			tokenNumber: g.length,
			nullifierAmount: g.length > 0 ? g[0].length : 0,
			outputAmount: _.length > 0 ? _[0].length : 0
		},
		encryptedOutputs: M,
		authorizationData: xe
	};
};
//#endregion
export { f as constructEmporiumProof };
