import { expect } from "@playwright/test";
async function createUserViaUi(page, input) {
  const role = input.role ?? "employee";
  await page.goto("/backend/users/create");
  await expect(page.getByText("Create User")).toBeVisible();
  const emailInput = page.locator('[data-crud-field-id="email"] input').first();
  const nameInput = page.locator('[data-crud-field-id="name"] input').first();
  const passwordInput = page.locator('[data-crud-field-id="password"] input').first();
  await expect(emailInput).toBeVisible();
  await emailInput.fill(input.email);
  if (await nameInput.count()) {
    await nameInput.fill("");
  }
  await expect(passwordInput).toBeVisible();
  await passwordInput.fill(input.password);
  const orgSelect = page.locator("main").locator("select").first();
  await expect(orgSelect).toBeEnabled();
  const orgValue = await orgSelect.evaluate((element) => {
    const select = element;
    for (const option of Array.from(select.options)) {
      if (option.value && option.value.trim().length > 0) return option.value;
    }
    return "";
  });
  if (orgValue) {
    await orgSelect.selectOption(orgValue);
  }
  const rolesInput = page.getByRole("textbox", { name: /add tag and press enter/i });
  await rolesInput.fill(role);
  await rolesInput.press("Enter");
  await page.getByRole("button", { name: "Create" }).first().click();
  await expect(page).toHaveURL(/\/backend\/users(?:\?.*)?$/);
  await page.getByRole("searchbox", { name: "Search", exact: true }).fill(input.email);
  await expect(page.getByRole("row", { name: new RegExp(input.email, "i") })).toBeVisible();
}
export {
  createUserViaUi
};
//# sourceMappingURL=authUi.js.map
