"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.submitModalWithRetry = void 0;
const test_1 = require("@playwright/test");
// The orchestration-cluster backend intermittently returns a 500
// ("Failed to convert from type [java.lang.Object] to type [byte[]] for value
// [io.camunda.security.api.model.CamundaAuthentication]") on role and
// authorization creation. The modal stays open with an inline error banner and
// the form fields remain valid, so re-submitting recovers from the transient
// blip. A persistent failure exhausts the retries and is surfaced to the caller.
const submitModalWithRetry = async (submitButton, modal, options) => {
    const { maxRetries = 3, closeTimeout = 20000 } = options || {};
    let lastError;
    for (let attempt = 1; attempt <= maxRetries; attempt++) {
        await submitButton.click();
        try {
            await (0, test_1.expect)(modal).not.toBeVisible({ timeout: closeTimeout });
            return;
        }
        catch (error) {
            lastError = error;
            if (attempt < maxRetries) {
                console.warn(`submitModalWithRetry: modal still open after attempt ${attempt}, retrying submit...`);
            }
        }
    }
    throw lastError;
};
exports.submitModalWithRetry = submitModalWithRetry;
