import { jwtDecode } from "jwt-decode";
import { request } from "./api";
const decodeJWT = (userToken) => {
    let decodedToken = {};
    try {
        decodedToken = jwtDecode(userToken);
    }
    catch (_) {
        // do nothing
    }
    return decodedToken;
};
export const getUserTheme = (userToken) => {
    return userToken
        ? decodeJWT(userToken)["https://camunda.com/settings"]?.theme || null
        : null;
};
export const updateTheme = async ({ endpoints, stage, userToken, getNewUserToken, theme, }) => {
    await request({
        method: "patch",
        base: "accounts",
        stage,
        endpoints,
        camundaAuth: { token: userToken, refreshTokenMethod: getNewUserToken },
        url: `external/user/theme`,
        body: { theme },
        responseType: "text",
    });
};
export const getOrgs = async (stage, accessToken) => {
    return await request({
        url: `https://accounts.${stage}/external/organizations/my`,
        camundaAuth: { token: accessToken },
        type: "json",
    });
};
export const getClusters = async (stage, accessToken, orgId) => {
    return await request({
        url: `https://console.${stage}/external/organizations/${orgId}/clusters`,
        camundaAuth: { token: accessToken },
        type: "json",
    });
};
