/* eslint-disable */
// @ts-nocheck
import { KeycloakDataTable } from "../../../shared/keycloak-ui-shared";
import {
Button,
Modal,
ModalVariant,
Popover,
Text,
TextContent,
TextVariants,
} from "../../../shared/@patternfly/react-core";
import { CheckCircleIcon } from "../../../shared/@patternfly/react-icons";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../../admin-client";
import { fetchUsedBy } from "../../components/role-mapping/resource";
import { useRealm } from "../../context/realm-context/RealmContext";
import useToggle from "../../utils/useToggle";
import { AuthenticationType, REALM_FLOWS } from "../constants";
import style from "./used-by.module.css";
type UsedByProps = {
authType: AuthenticationType;
};
const Label = ({ label }: { label: string }) => (
<>
{label}
>
);
type UsedByModalProps = {
id: string;
onClose: () => void;
isSpecificClient: boolean;
};
const UsedByModal = ({ id, isSpecificClient, onClose }: UsedByModalProps) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const loader = async (
first?: number,
max?: number,
search?: string,
): Promise<{ name: string }[]> => {
const result = await fetchUsedBy(adminClient, {
id,
type: isSpecificClient ? "clients" : "idp",
first: first || 0,
max: max || 10,
search,
});
return result.map((p) => ({ name: p }));
};
return (
{t("flowUsedBy")}
{t("flowUsedByDescription", {
value: isSpecificClient ? t("clients") : t("identiyProviders"),
})}
}
variant={ModalVariant.medium}
isOpen
onClose={onClose}
actions={[
,
]}
>
);
};
export const UsedBy = ({ authType: { id, usedBy } }: UsedByProps) => {
const { t } = useTranslation();
const { realmRepresentation: realm } = useRealm();
const [open, toggle] = useToggle();
const key = Object.entries(realm!).find(
(e) => e[1] === usedBy?.values[0],
)?.[0];
return (
<>
{open && (
)}
{(usedBy?.type === "SPECIFIC_PROVIDERS" ||
usedBy?.type === "SPECIFIC_CLIENTS") &&
(usedBy.values.length <= 8 ? (
{t(
"appliedBy" +
(usedBy.type === "SPECIFIC_CLIENTS"
? "Clients"
: "Providers"),
)}{" "}
{usedBy.values.map((used, index) => (
<>
{used}
{index < usedBy.values.length - 1 ? ", " : ""}
>
))}
}
>
) : (
))}
{usedBy?.type === "DEFAULT" && (
)}
{!usedBy?.type && t("used.notInUse")}
>
);
};