// Metro module 8947 (f8948).
import _slicedToArray from "../../../_bundle/_slicedToArray";
import { useState, useMemo, useEffect, useRef, useCallback } from "react";
import { View } from "react-native";
import defaultImageSrcGenerator from "../../../_bundle/defaultImageSrcGenerator";
import AccessibilityStore from "../../a11y/AccessibilityStore";
import ApplicationRecord from "../../../records/ApplicationRecord";
import ConnectedAccountsStore from "../../../stores/ConnectedAccountsStore";
import UserStore from "../../../stores/UserStore";
import { OAuth2Steps, EMOJI_POINTING_DOWN_CODE_POINT } from "../Constants";
import { Endpoints, AnalyticEvents } from "../../../Constants";
import { jsx } from "react/jsx-runtime";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import { NONE } from "../../../utils/PermissionUtils";
import { useStateFromStores } from "../../../_bundle/Module589";
import { useIsScreenReaderEnabled } from "../../a11y/native/useIsScreenReaderEnabled.native";
import * as _ReanimatedRexport from "../../reanimated/ReanimatedRexport";
import ReanimatedRexport, { useAnimatedStyle } from "../../reanimated/ReanimatedRexport";
import * as _timing from "../../../design/animation/reanimated/timing/timing";
import ApplicationActionCreators from "../../applications/ApplicationActionCreators";
import { filterScopes } from "../Authorize";
import { OrderedAccountScopes, ValidScopes } from "../scopes";
import { deserialize, remove, add, equals } from "../../../_bundle/HighLow";
import SamsungManager_android from "../../samsung/native/SamsungManager.android";
import { getAPIBaseURL } from "../../../_bundle/sendRequest";
import { v4 } from "../../../_bundle/Module514";
import { getDisclosures, ackDisclosures } from "../../applications/disclosures";
import * as _Utils from "../Utils";
import * as _actions from "../actions";
import { startSamsungAuthorization, fetchAuthorization } from "../actions";
import { ApplicationIntegrationType } from "../../../_bundle/Module8028";
import AuthorizedAppsActionCreators from "../AuthorizedAppsActionCreators";
import SentryUtils_native from "../../../utils/SentryUtils.native";
import { convertOAuth2Authorization } from "../convertor";
import { OAuth2Prompts } from "../types";
import { trackWithMetadata } from "../../app_analytics/AppAnalyticsUtils";
import { containsDisallowedPermission } from "../permissions";
import useBackPressHandler from "../../routing/native/useBackPressHandler";
import ErrorResult from "./ErrorResult";
import { Button } from "../../../design/components/Button/native/Button.native";
import { intl, t } from "../../../intl/index.native";
import { ActivityIndicator } from "../../../design/components/ActivityIndicator/native/ActivityIndicator.native";
import Platforms from "../../../lib/Platforms";
import ConnectAccountStep, { ConnectedAccountCard } from "./ConnectAccountStep";
import IntegrationTypeSelector from "./IntegrationTypeSelector";
import { OAuth2Scopes } from "../../../_bundle/Module8174";
import { getIsSocialLayerParentApplication } from "../../applications/useIsSocialLayerParentApplication";
import ApplicationEducation from "./ApplicationEducation";
import AuthorizeScopes from "./AuthorizeScopes";
import { AuthorizeFormSeparator } from "./AuthorizeFormSeparator";
import GuildSelector from "./GuildSelector";
import WebhookGuildChannelSelector from "./WebhookGuildChannelSelector";
import BotPermissions from "./BotPermissions";
import ApplicationDetails from "./ApplicationDetails";
import Header from "./Header";
import Emoji from "../../emojis/native/Emoji";
let env5851 = {};
const useStyles = createStyles({
loading: {
flex: 1,
alignSelf: "center",
justifyContent: "center"
}
});
const c5851_21 = {
code: "function useOAuth2AuthorizeFormTsx1(){const{shouldReduceMotion,withSequence,withTiming,Easing,withRepeat}=this.__closure;const TOTAL=500;if(shouldReduceMotion)return{};return{transform:[{translateY:withSequence(withTiming(-5,{duration:TOTAL/2,easing:Easing.inOut(Easing.quad)}),withRepeat(withTiming(5,{duration:TOTAL,easing:Easing.inOut(Easing.quad)}),-1,true))}]};}"
};
export default function useOAuth2AuthorizeForm(a0) {
let r5, r6, r332, backStep, body, disabled, hasContentBackground, props;
let env16888 = {
$parent: env5851
};
const clientId = a0.clientId;
env16888[0] = clientId;
const responseType = a0.responseType;
env16888[1] = responseType;
let redirectUri = a0.redirectUri;
env16888[2] = redirectUri;
const codeChallenge = a0.codeChallenge;
env16888[3] = codeChallenge;
const codeChallengeMethod = a0.codeChallengeMethod;
env16888[4] = codeChallengeMethod;
const state = a0.state;
env16888[5] = state;
const nonce = a0.nonce;
env16888[6] = nonce;
const prompt = a0.prompt;
env16888[7] = prompt;
const scopes2 = a0.scopes;
env16888[8] = scopes2;
const permissions2 = a0.permissions;
env16888[9] = permissions2;
let guildId = a0.guildId;
let channelId = a0.channelId;
const integrationType2 = a0.integrationType;
env16888[10] = integrationType2;
let disableGuildSelect = a0.disableGuildSelect;
if (disableGuildSelect === void 0) {
disableGuildSelect = false;
}
let isTrustedName = a0.isTrustedName;
if (isTrustedName === void 0) {
isTrustedName = false;
}
const { isEmbeddedFlow = false, withBackPressHandler = true, callback } = a0;
env16888[11] = callback;
const callbackWithoutPost = a0.callbackWithoutPost;
env16888[12] = callbackWithoutPost;
const dismissOAuthModal = a0.dismissOAuthModal;
env16888[13] = dismissOAuthModal;
const disclosures2 = a0.disclosures;
env16888[14] = disclosures2;
const connectedAccountProvider = a0.connectedAccountProvider;
env16888[15] = connectedAccountProvider;
let wasDeepLink = a0.wasDeepLink;
if (wasDeepLink === void 0) {
wasDeepLink = false;
}
env16888[16] = wasDeepLink;
env16888[17] = void 0;
env16888[18] = void 0;
env16888[19] = void 0;
env16888[20] = void 0;
env16888[21] = void 0;
env16888[22] = void 0;
env16888[23] = void 0;
env16888[24] = void 0;
env16888[25] = void 0;
env16888[26] = void 0;
env16888[27] = void 0;
env16888[28] = void 0;
env16888[29] = void 0;
env16888[30] = void 0;
env16888[31] = void 0;
env16888[32] = void 0;
env16888[33] = void 0;
env16888[34] = void 0;
env16888[35] = void 0;
env16888[36] = void 0;
env16888[37] = void 0;
env16888[38] = void 0;
env16888[39] = void 0;
env16888[40] = void 0;
env16888[41] = void 0;
env16888[42] = void 0;
env16888[43] = void 0;
env16888[44] = void 0;
env16888[45] = void 0;
env16888[46] = void 0;
env16888[47] = void 0;
env16888[48] = void 0;
env16888[49] = void 0;
env16888[50] = void 0;
env16888[51] = void 0;
env16888[52] = void 0;
env16888[53] = void 0;
env16888[54] = void 0;
env16888[55] = void 0;
env16888[56] = void 0;
env16888[57] = void 0;
env16888[58] = void 0;
env16888[59] = void 0;
env16888[60] = void 0;
env16888[61] = void 0;
env16888[62] = void 0;
env16888[63] = void 0;
env16888[17] = useStyles();
const r71 = _slicedToArray(useState(null), 2);
const r35 = r71[0];
env16888[18] = r35;
env16888[19] = r71[1];
const r75 = _slicedToArray(useState(null), 2);
const r29 = r75[0];
env16888[20] = r29;
env16888[21] = r75[1];
const r79 = _slicedToArray(useState(null), 2);
const r17 = r79[0];
env16888[22] = r17;
env16888[23] = r79[1];
const r83 = _slicedToArray(useState(false), 2);
const loading = r83[0];
env16888[24] = r83[1];
const guilds = r35?.guilds;
env16888[25] = guilds;
if (guildId == null) {
guildId = null;
}
const r87 = _slicedToArray(useState(guildId), 2);
const selectedGuildId = r87[0];
env16888[26] = selectedGuildId;
const onGuildChange = r87[1];
env16888[27] = onGuildChange;
if (channelId == null) {
channelId = null;
}
const r90 = _slicedToArray(useState(channelId), 2);
const selectedChannelId = r90[0];
env16888[28] = selectedChannelId;
const onChannelChange = r90[1];
env16888[29] = onChannelChange;
const r97 = _slicedToArray(useState(NONE), 2);
const deniedPermissions = r97[0];
env16888[30] = deniedPermissions;
env16888[31] = r97[1];
const stateFromStores3 = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
const nsfwAllowed = stateFromStores3?.nsfwAllowed;
env16888[32] = nsfwAllowed;
const memo = useMemo(() => {
const r4 = env16888[25];
return r4 == null ? void 0 : r4.find((item) => item.id === env16888[26]);
}, [guilds, selectedGuildId]);
env16888[33] = memo;
const stateFromStores = useStateFromStores([ConnectedAccountsStore], () => {
const r1 = env16888[15] == null;
let r6 = null;
if (!r1) {
let r11 = ConnectedAccountsStore.getAccounts().find((item) => item.type === env16888[15]);
if (r11 == null) {
r11 = null;
}
r6 = r11;
}
return r6;
}, [connectedAccountProvider]);
const r7 = connectedAccountProvider == null || stateFromStores != null;
env16888[34] = r7;
const r115 = _slicedToArray(useState(null), 2);
const integrationType3 = r115[0];
env16888[35] = integrationType3;
env16888[36] = r115[1];
const r119 = _slicedToArray(useState(false), 2);
const allContentSeen = r119[0];
env16888[37] = allContentSeen;
const setAllContentSeen = r119[1];
env16888[38] = setAllContentSeen;
const stateFromStores2 = useStateFromStores([AccessibilityStore], () => AccessibilityStore.useReducedMotion);
env16888[39] = stateFromStores2;
const isScreenReaderEnabled = useIsScreenReaderEnabled();
env16888[40] = isScreenReaderEnabled;
const V = function V() {
return env16888[39] ? {} : {
transform: [{
translateY: _ReanimatedRexport.withSequence(_timing.withTiming(-5, {
duration: 250,
easing: _ReanimatedRexport.Easing.inOut(_ReanimatedRexport.Easing.quad)
}), _ReanimatedRexport.withRepeat(_timing.withTiming(5, {
duration: 500,
easing: _ReanimatedRexport.Easing.inOut(_ReanimatedRexport.Easing.quad)
}), -1, true))
}]
};
};
V.__closure = {
shouldReduceMotion: stateFromStores2,
withSequence: _ReanimatedRexport.withSequence,
withTiming: _timing.withTiming,
Easing: _ReanimatedRexport.Easing,
withRepeat: _ReanimatedRexport.withRepeat
};
V.__workletHash = 1476082137097;
V.__initData = c5851_21;
const animatedStyle = useAnimatedStyle(V);
const memo3 = useMemo(() => {
let r1 = env16888[10] == null;
if (r1) {
let r7 = env16888[8]?.length;
if (r7 == null) {
r7 = 0;
}
r1 = r7 === 0;
}
if (r1) {
r1 = env16888[2] == null;
}
return r1;
}, [scopes2?.length, redirectUri, integrationType2]);
env16888[41] = memo3;
const r156 = _slicedToArray(useState(null), 2);
const application = r156[0];
env16888[42] = application;
env16888[43] = r156[1];
useEffect(() => {
if (env16888[41]) {
ApplicationActionCreators.fetchApplication(env16888[0]).then((result) => (0, env16888[43])(ApplicationRecord.createFromServer(result)));
}
}, [clientId, memo3]);
const memo4 = useMemo(() => {
const r6 = env16888[35];
const r1 = r6 == null;
let r3 = null;
if (!r1) {
const r5 = env16888[42];
const r2 = r5 == null;
let r7 = void 0;
if (!r2) {
const integrationTypesConfig = r5.integrationTypesConfig;
r7 = integrationTypesConfig == null ? void 0 : integrationTypesConfig[r6]?.oauth2InstallParams;
}
r3 = r7;
}
return r3;
}, [application?.integrationTypesConfig, integrationType3]);
env16888[44] = memo4;
const memo5 = useMemo(() => {
let r7 = env16888[41] ? env16888[44]?.scopes : env16888[8];
if (r7 == null) {
r7 = [];
}
const requestedScopes = filterScopes(r7);
let c26320_0 = requestedScopes;
return {
requestedScopes,
accountScopes: OrderedAccountScopes.filter((orderedAccountScope) => c26320_0.includes(orderedAccountScope))
};
}, [memo4?.scopes, scopes2, memo3]);
const requestedScopes = memo5.requestedScopes;
env16888[45] = requestedScopes;
const accountScopes = memo5.accountScopes;
const memo2 = useMemo(() => {
let r9;
if (env16888[41]) {
let r14 = env16888[44]?.permissions;
if (r14 == null) {
r14 = 0;
}
r9 = deserialize(r14);
} else {
r9 = env16888[9];
}
if (r9 == null) {
r9 = NONE;
}
return r9;
}, [memo4?.permissions, permissions2, memo3]);
env16888[46] = memo2;
const r182 = _slicedToArray(useState(false), 2);
const r60 = r182[0];
env16888[47] = r60;
env16888[48] = r182[1];
useEffect(() => {
SamsungManager_android.checkIfOAuthRequest(env16888[0]).then(env16888[48]);
}, [clientId]);
const [state2, setState] = useState(null);
let r193 = state;
if (r60) {
const r202 = getAPIBaseURL(false) + "/v6" + Endpoints.OAUTH2_AUTHORIZE_SAMSUNG_CALLBACK;
env16888[2] = r202;
if (state == null && state2 == null) {
setState(v4());
}
let r208 = state;
if (state2 != null) {
const r209 = state == null ? "SA" + state2 : state;
env16888[5] = r209;
r208 = r209;
}
r193 = r208;
redirectUri = r202;
}
env16888[49] = useRef(false);
let r214 = disclosures2;
if (r214 == null) {
r214 = [];
}
const r216 = _slicedToArray(useState(r214), 2);
const disclosures3 = r216[0];
env16888[50] = disclosures3;
const r218 = r216[1];
env16888[51] = r218;
const r222 = _slicedToArray(useState(disclosures2 != null), 2);
const r223 = r222[0];
env16888[52] = r223;
const r224 = r222[1];
env16888[53] = r224;
useEffect(() => {
let _doGetDisclosures2 = function _doGetDisclosures() {
const r9 = async () => {
let c31482_2;
let c31482_3 = 0;
let c31984_0, c31984_1, c31984_2, c31984_3;
L10: {
try {
c31984_0 = void 0;
c31984_1 = void 0;
c31984_2 = void 0;
c31984_3 = void 0;
env16888[49].current = true;
c31482_3 = 2;
c31984_0 = await getDisclosures(env16888[0]);
c31984_1 = c31984_0.disclosures;
c31984_2 = c31984_0.allAcked;
(0, env16888[53])(!c31984_2);
(0, env16888[51])(c31984_1);
c31482_3 = 1;
c31482_3 = 0;
env16888[49].current = false;
} catch ($e) {
const r35 = $e;
let r7 = r35;
c31482_2 = r35;
let r36 = c31482_3;
if (r36 !== 0) {
while (true) {
if (r36 === 1) {
try {
const r124 = c31482_2;
c31482_3 = 0;
env16888[49].current = false;
throw r124;
} catch (r122) {
r7 = r122;
c31482_2 = r122;
r36 = c31482_3;
if (r36 === 0) {
break;
}
}
} else {
try {
const r90 = c31482_2;
c31482_3 = 1;
c31984_3 = r90.body;
env16888[23](new Error(c31984_3.message != null ? c31984_3.message : `${Object.keys(c31984_3)[0]}: ${Object.values(c31984_3)[0]}`));
c31482_3 = 0;
env16888[49].current = false;
break L10;
} catch (r87) {
r7 = r87;
c31482_2 = r87;
r36 = c31482_3;
if (r36 === 0) {
break;
}
}
}
}
}
throw r7;
}
}
};
_doGetDisclosures2 = r9;
return r9.apply(this, arguments);
};
if (!env16888[49].current && env16888[14] == null) {
(function doGetDisclosures() {
return _doGetDisclosures2.apply(this, arguments);
})();
}
}, [clientId, disclosures2, r218, r224]);
let r230 = r35 == null ? void 0 : r35.application.content_classification;
if (r230 == null) {
r230 = application?.contentClassification;
}
const isContentClassificationRestricted = _Utils.isContentClassificationRestricted(r230, nsfwAllowed);
let c16889_0 = async (c30005_0) => {
let c30005_1, c30005_2, c30005_3;
let c30005_4 = 0;
const r19 = void 0;
L39: {
L14: {
try {
let env31483;
c30005_2 = r19;
const r46 = env31483 = {};
c30005_1 = r46;
env31483[0] = void 0;
env31483[1] = void 0;
env31483[2] = void 0;
env31483[0] = c30005_0.isAuthorized;
env31483[1] = c30005_0.overrideSuccessCallback;
env31483[2] = c30005_0.canceled;
env31483[3] = void 0;
env31483[4] = void 0;
await void 0;
if (c30005_2.$parent[12] != null) {
const r78 = c30005_2.$parent;
(0, r78[24])(true);
(0, r78[12])(env31483[0]);
const r84 = r78[13];
if (r84 == null) {
break L39;
}
r84();
break L39;
}
if (c30005_2.$parent[35] != null) {
const r90 = c30005_2;
c30005_4 = 2;
const r25 = r90.$parent;
(0, r25[24])(true);
const r99 = {
authorize: env31483[0],
clientId: r25[0],
scopes: r25[45],
responseType: r25[1],
redirectUri: r25[2],
codeChallenge: r25[3],
codeChallengeMethod: r25[4],
state: r25[5],
nonce: r25[6],
permissions: remove(r25[46], r25[30]),
guildId: null,
channelId: null,
integrationType: null,
connectedAccountProvider: null
};
const guildId = r25[35] === ApplicationIntegrationType.GUILD_INSTALL ? c30005_2.$parent[26] != null ? c30005_2.$parent[26] : void 0 : void 0;
const r130 = c30005_2;
r99.guildId = guildId;
const channelId = r130.$parent[35] === ApplicationIntegrationType.GUILD_INSTALL ? c30005_2.$parent[28] != null ? c30005_2.$parent[28] : void 0 : void 0;
const r147 = c30005_2;
r99.channelId = channelId;
const r148 = r147.$parent;
r99.integrationType = r148[35];
r99.connectedAccountProvider = r148[15];
env31483[3] = await _actions.authorize(r99);
if (env31483[0]) {
const r184 = c30005_2;
AuthorizedAppsActionCreators.fetch();
const r197 = r184.$parent;
await ackDisclosures(r197[0], r197[50]);
}
if (env31483[1] != null) {
(0, env31483[1])(env31483[3].location);
} else {
const r211 = c30005_2.$parent[13];
if (r211 != null) {
r211();
}
await new Promise((resolve) => setTimeout(resolve, 100));
const r245 = c30005_2.$parent[11];
if (r245 != null) {
const application = c30005_2.$parent[18]?.application;
const r257 = c30005_2.$parent;
r245({
...env31483[3],
canceled: env31483[2],
application,
guild: r257[33],
wasDeepLink: r257[16]
});
}
}
c30005_4 = 1;
c30005_4 = 0;
(0, c30005_2.$parent[24])(false);
} else {
(0, c30005_2.$parent[23])(new Error("No integration type was selected."));
}
} catch ($e) {
const r44 = $e;
let r7 = r44;
c30005_3 = r44;
let r45 = c30005_4;
if (r45 !== 0) {
while (true) {
if (r45 === 1) {
try {
const r341 = c30005_2;
const r342 = c30005_3;
c30005_4 = 0;
(0, r341.$parent[24])(false);
throw r342;
} catch (r340) {
r7 = r340;
c30005_3 = r340;
r45 = c30005_4;
if (r45 === 0) {
break;
}
}
} else {
try {
const r296 = c30005_3;
c30005_4 = 1;
env31483[4] = r296.body;
if (env31483[4]?.message != null && env31483[4].message !== "") {
const r318 = c30005_2.$parent;
(0, r318[23])(new Error(env31483[4].message));
(0, r318[21])(OAuth2Steps.AUTHORIZE_SCOPES);
} else {
const r304 = c30005_2.$parent;
(0, r304[23])(env31483[4]);
(0, r304[21])(OAuth2Steps.AUTHORIZE_SCOPES);
}
c30005_4 = 0;
(0, c30005_2.$parent[24])(false);
break L14;
} catch (r294) {
r7 = r294;
c30005_3 = r294;
r45 = c30005_4;
if (r45 === 0) {
break;
}
}
}
}
}
throw r7;
}
}
return void 0;
}
};
const callback2 = useCallback(function(a0) {
return c16889_0.apply(this, arguments);
}, [integrationType3, callbackWithoutPost, clientId, requestedScopes, responseType, redirectUri, codeChallenge, codeChallengeMethod, r193, nonce, memo2, deniedPermissions, selectedGuildId, selectedChannelId, disclosures3, dismissOAuthModal, callback, wasDeepLink, r35?.application, memo, connectedAccountProvider]);
env16888[54] = callback2;
const callback3 = useCallback((isAuthorized) => new Promise((c30006_0) => (0, env16888[54])({
isAuthorized,
overrideSuccessCallback: (a0) => {
c30006_0(a0);
}
})), [callback2]);
env16888[55] = callback3;
env16888[56] = useCallback((a0) => {
if (env16888[47]) {
SamsungManager_android.showConnectionDisclaimer().then(() => SamsungManager_android.getAccountUrlAndAuthCode()).then((result) => {
const [r12, r7] = result;
return Promise.all([r7, startSamsungAuthorization(env16888[0], env16888[45], env16888[1], r12, env16888[5])]);
}).then((result) => {
const [r7, , ] = result;
return Promise.all([r7, (0, env16888[55])(a0)]);
}).then((result) => {
const [r7, r24] = result;
return SamsungManager_android.finishSamsungAuthorization(r7, r24, env16888[5]);
}).then(() => {
const r3 = env16888[13];
return r3 == null ? void 0 : r3();
}).catch((error) => {
SentryUtils_native.captureException(error);
});
} else {
(0, env16888[54])({
isAuthorized: a0
});
}
}, [clientId, r60, responseType, callback2, callback3, r193, dismissOAuthModal, requestedScopes]);
env16888[57] = useRef(false);
const callback4 = useCallback(async () => {
let c30007_0, c30007_1, c30007_2, c30007_3;
let integrationType, c26324_3;
let c26324_4 = 0;
L24: {
L23: {
try {
c30007_0 = void 0;
c30007_1 = void 0;
c30007_2 = void 0;
c30007_3 = void 0;
if (env16888[57].current) {
break L24;
}
env16888[57].current = true;
c26324_4 = 2;
integrationType = env16888[35];
if (integrationType == null) {
integrationType = void 0;
}
c30007_0 = await fetchAuthorization({
clientId: env16888[0],
scopes: env16888[45],
responseType: env16888[1],
redirectUri: env16888[2],
codeChallenge: env16888[3],
codeChallengeMethod: env16888[4],
state: env16888[5],
integrationType,
connectedAccountProvider: env16888[15]
});
c30007_1 = convertOAuth2Authorization(c30007_0);
(0, env16888[19])(c30007_1);
c30007_2 = _Utils.isContentClassificationRestricted(c30007_1.application.content_classification, env16888[32]);
if (!(env16888[7] !== OAuth2Prompts.NONE || !c30007_0.authorized || env16888[52] || c30007_2)) {
(0, env16888[54])({
isAuthorized: true
});
}
trackWithMetadata(AnalyticEvents.OAUTH2_AUTHORIZE_VIEWED, {
application_id: c30007_0.application.id
});
c26324_4 = 1;
c26324_4 = 0;
env16888[57].current = false;
} catch ($e) {
const r34 = $e;
let r7 = r34;
c26324_3 = r34;
let r35 = c26324_4;
if (r35 !== 0) {
while (true) {
if (r35 === 1) {
try {
const r172 = c26324_3;
c26324_4 = 0;
env16888[57].current = false;
throw r172;
} catch (r170) {
r7 = r170;
c26324_3 = r170;
r35 = c26324_4;
if (r35 === 0) {
break;
}
}
} else {
try {
const r138 = c26324_3;
c26324_4 = 1;
c30007_3 = r138.body;
env16888[23](new Error(c30007_3.message != null ? c30007_3.message : `${Object.keys(c30007_3)[0]}: ${Object.values(c30007_3)[0]}`));
c26324_4 = 0;
env16888[57].current = false;
break L23;
} catch (r135) {
r7 = r135;
c26324_3 = r135;
r35 = c26324_4;
if (r35 === 0) {
break;
}
}
}
}
}
throw r7;
}
}
return void 0;
}
}, [clientId, requestedScopes, responseType, redirectUri, codeChallenge, codeChallengeMethod, r193, integrationType3, connectedAccountProvider, prompt, callback2, r223, nsfwAllowed]);
env16888[58] = callback4;
const memo6 = useMemo(() => {
let r6;
const r2 = env16888[42];
if (r2 != null && env16888[41]) {
const r4 = Object;
let integrationTypesConfig = r2.integrationTypesConfig;
if (integrationTypesConfig == null) {
integrationTypesConfig = {};
}
r6 = r4.entries(integrationTypesConfig).filter((item) => {
const [, r13] = item;
return r13.oauth2InstallParams != null;
}).map((item) => {
const [r21, , ] = item;
return Number(r21);
});
} else {
r6 = [];
}
return r6;
}, [application, memo3]);
env16888[59] = memo6;
env16888[60] = useRef(null);
useEffect(() => {
const current = env16888[20];
const r1 = env16888[60];
if (current !== r1.current) {
r1.current = current;
trackWithMetadata(AnalyticEvents.OAUTH2_AUTHORIZE_STEP_VIEWED, {
step: current,
application_id: env16888[0],
integration_type: env16888[35],
scopes: env16888[45],
permissions: env16888[46].toString()
});
}
}, [clientId, integrationType3, memo2, requestedScopes, r29]);
useEffect(() => {
const r10 = env16888[20] != null || env16888[41] && env16888[42] == null;
L15: {
if (!r10) {
if (env16888[15] != null && !env16888[34]) {
(0, env16888[21])(OAuth2Steps.CONNECT_ACCOUNT);
break L15;
}
const r18 = env16888[59];
if (r18.length > 1) {
(0, env16888[21])(OAuth2Steps.SELECT_INSTALL_TYPE);
} else if (r18.length === 1) {
(0, env16888[36])(r18[0]);
(0, env16888[21])(OAuth2Steps.AUTHORIZE_SCOPES);
} else {
const r21 = env16888[10];
if (r21 != null) {
(0, env16888[36])(r21);
(0, env16888[21])(OAuth2Steps.AUTHORIZE_SCOPES);
} else {
(0, env16888[36])(ApplicationIntegrationType.GUILD_INSTALL);
(0, env16888[21])(OAuth2Steps.AUTHORIZE_SCOPES);
}
}
}
}
}, [memo6, application, memo3, integrationType2, r29, connectedAccountProvider, r7]);
useEffect(() => {
if (env16888[20] === OAuth2Steps.CONNECT_ACCOUNT && env16888[34]) {
const r8 = env16888[36];
let r9 = env16888[10];
if (r9 == null) {
r9 = ApplicationIntegrationType.USER_INSTALL;
}
r8(r9);
(0, env16888[21])(OAuth2Steps.AUTHORIZE_SCOPES);
}
}, [r29, r7, integrationType2]);
useEffect(() => {
const r8 = env16888[35];
if (r8 != null && env16888[18] == null && env16888[22] == null) {
if (r8 === ApplicationIntegrationType.USER_INSTALL) {
(0, env16888[27])(null);
(0, env16888[29])(null);
}
const r20 = env16888[45];
const r23 = r20.filter((item) => !ValidScopes.includes(item));
if (r20.length === 0) {
(0, env16888[23])(new Error("No scopes were provided."));
} else if (r23.length > 0) {
env16888[23](new Error(`Invalid scope: ${r23[0]}`));
} else if (containsDisallowedPermission(env16888[46])) {
(0, env16888[23])(new Error("Invalid permission(s) provided."));
} else {
(0, env16888[58])();
}
}
}, [callback4, requestedScopes, memo2, integrationType3, r35, r17]);
const callback5 = useCallback(() => {
if (env16888[40] && !env16888[37]) {
(0, env16888[38])(true);
}
}, [isScreenReaderEnabled, allContentSeen]);
if (r29 === OAuth2Steps.AUTHORIZE_SCOPES && memo6.length > 1) {
const SELECT_INSTALL_TYPE = OAuth2Steps.SELECT_INSTALL_TYPE;
env16888[61] = SELECT_INSTALL_TYPE;
backStep = SELECT_INSTALL_TYPE;
} else {
const AUTHORIZE_BOT_PERMISSIONS = OAuth2Steps.AUTHORIZE_BOT_PERMISSIONS;
backStep = void 0;
if (r29 === AUTHORIZE_BOT_PERMISSIONS) {
const AUTHORIZE_SCOPES = OAuth2Steps.AUTHORIZE_SCOPES;
env16888[61] = AUTHORIZE_SCOPES;
backStep = AUTHORIZE_SCOPES;
}
}
const callback6 = useCallback(() => {
const r3 = env16888[61];
if (r3 != null) {
(0, env16888[21])(r3);
} else {
(0, env16888[54])({
isAuthorized: false,
canceled: true
});
const r7 = env16888[13];
if (r7 != null) {
r7();
}
}
return true;
}, [backStep, dismissOAuthModal, callback2]);
env16888[62] = callback6;
useBackPressHandler(callback6, withBackPressHandler);
const callback7 = useCallback((a0) => {
(0, env16888[36])(a0);
(0, env16888[19])(null);
(0, env16888[21])(OAuth2Steps.AUTHORIZE_SCOPES);
}, []);
const callback8 = useCallback((c26325_0, c26325_1) => {
(0, env16888[31])((a0) => c26325_0 ? remove(a0, c26325_1) : add(a0, c26325_1));
}, []);
if (r17 instanceof Error) {
return {
body: ,
goBackOrCancel: callback6,
footer: