import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { View, Pressable, Switch, StyleSheet, ScrollView, DeviceEventEmitter } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { DispatchAction } from '../contexts/reducers/store';
import { useStore } from '../contexts/store';
import { useTheme } from '../contexts/theme';
import { testIdWithKey } from '../utils/testable';
import { ThemedText } from '../components/texts/ThemedText';
import Button, { ButtonType } from '../components/buttons/Button';
import { useNavigation } from '@react-navigation/native';
import { Screens, Stacks } from '../types/navigators';
import { EventTypes } from '../constants';
const Developer = () => {
  const [store, dispatch] = useStore();
  const {
    t
  } = useTranslation();
  const {
    ColorPalette
  } = useTheme();
  const [useVerifierCapability, setUseVerifierCapability] = useState(!!store.preferences.useVerifierCapability);
  const [useConnectionInviterCapability, setConnectionInviterCapability] = useState(!!store.preferences.useConnectionInviterCapability);
  const [acceptDevCredentials, setAcceptDevCredentials] = useState(!!store.preferences.acceptDevCredentials);
  const [useDevVerifierTemplates, setDevVerifierTemplates] = useState(!!store.preferences.useDevVerifierTemplates);
  const [enableWalletNaming, setEnableWalletNaming] = useState(!!store.preferences.enableWalletNaming);
  const [enableShareableLink, setEnableShareableLink] = useState(!!store.preferences.enableShareableLink);
  const [preventAutoLock, setPreventAutoLock] = useState(!!store.preferences.preventAutoLock);
  const navigation = useNavigation();
  const styles = StyleSheet.create({
    container: {
      flex: 1,
      paddingTop: 10,
      paddingHorizontal: 10
    },
    settingContainer: {
      flexDirection: 'row',
      marginVertical: 10,
      marginHorizontal: 10,
      justifyContent: 'space-between',
      alignItems: 'center'
    },
    settingLabelText: {
      marginRight: 10,
      textAlign: 'left'
    },
    settingSwitchContainer: {
      justifyContent: 'center'
    }
  });
  const toggleVerifierCapabilitySwitch = () => {
    // if verifier feature is switched off then also turn off the dev templates
    if (useVerifierCapability) {
      dispatch({
        type: DispatchAction.USE_DEV_VERIFIER_TEMPLATES,
        payload: [false]
      });
      setDevVerifierTemplates(false);
    }
    dispatch({
      type: DispatchAction.USE_VERIFIER_CAPABILITY,
      payload: [!useVerifierCapability]
    });
    setUseVerifierCapability(previousState => !previousState);
  };
  const toggleAcceptDevCredentialsSwitch = () => {
    dispatch({
      type: DispatchAction.ACCEPT_DEV_CREDENTIALS,
      payload: [!acceptDevCredentials]
    });
    setAcceptDevCredentials(previousState => !previousState);
  };
  const toggleConnectionInviterCapabilitySwitch = () => {
    dispatch({
      type: DispatchAction.USE_CONNECTION_INVITER_CAPABILITY,
      payload: [!useConnectionInviterCapability]
    });
    setConnectionInviterCapability(previousState => !previousState);
  };
  const toggleDevVerifierTemplatesSwitch = () => {
    // if we switch on dev templates we can assume the user also wants to enable the verifier capability
    if (!useDevVerifierTemplates) {
      dispatch({
        type: DispatchAction.USE_VERIFIER_CAPABILITY,
        payload: [true]
      });
      setUseVerifierCapability(true);
    }
    dispatch({
      type: DispatchAction.USE_DEV_VERIFIER_TEMPLATES,
      payload: [!useDevVerifierTemplates]
    });
    setDevVerifierTemplates(previousState => !previousState);
  };
  const toggleWalletNamingSwitch = () => {
    dispatch({
      type: DispatchAction.ENABLE_WALLET_NAMING,
      payload: [!enableWalletNaming]
    });
    setEnableWalletNaming(previousState => !previousState);
  };
  const togglePreventAutoLockSwitch = () => {
    dispatch({
      type: DispatchAction.PREVENT_AUTO_LOCK,
      payload: [!preventAutoLock]
    });
    setPreventAutoLock(previousState => !previousState);
  };
  const toggleShareableLinkSwitch = () => {
    dispatch({
      type: DispatchAction.USE_SHAREABLE_LINK,
      payload: [!enableShareableLink]
    });
    setEnableShareableLink(previousState => !previousState);
  };
  const onRunRefreshCycleTouched = () => {
    var _navigation$getParent;
    (_navigation$getParent = navigation.getParent()) === null || _navigation$getParent === void 0 || _navigation$getParent.navigate(Stacks.TabStack, {
      screen: Screens.Home
    });
    setTimeout(() => {
      DeviceEventEmitter.emit(EventTypes.OPENID_REFRESH_REQUEST);
    }, 50);
  };
  return /*#__PURE__*/React.createElement(SafeAreaView, {
    style: {
      flex: 1
    },
    edges: ['bottom', 'left', 'right']
  }, /*#__PURE__*/React.createElement(ScrollView, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(ThemedText, {
    style: {
      margin: 10
    }
  }, "Place content here you would like to make available to developers when developer mode is enabled."), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    accessible: false,
    style: styles.settingLabelText
  }, t('Verifier.UseVerifierCapability'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('Verifier.Toggle'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleVerifierCapability')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: useVerifierCapability ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleVerifierCapabilitySwitch,
    testID: testIdWithKey('VerifierCapabilitySwitchElement'),
    value: useVerifierCapability
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    accessible: false,
    style: styles.settingLabelText
  }, t('Verifier.AcceptDevCredentials'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('Verifier.Toggle'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleAcceptDevCredentials')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: acceptDevCredentials ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleAcceptDevCredentialsSwitch,
    testID: testIdWithKey('AcceptDevCredentialsSwitchElement'),
    value: acceptDevCredentials
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    style: styles.settingLabelText
  }, t('Connection.UseConnectionInviterCapability'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('Connection.Toggle'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleConnectionInviterCapabilitySwitch')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: useConnectionInviterCapability ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleConnectionInviterCapabilitySwitch,
    testID: testIdWithKey('ConnectionInviterCapabilitySwitchElement'),
    value: useConnectionInviterCapability
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    style: styles.settingLabelText
  }, t('Verifier.UseDevVerifierTemplates'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('Verifier.ToggleDevTemplates'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleDevVerifierTemplatesSwitch')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: useDevVerifierTemplates ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleDevVerifierTemplatesSwitch,
    testID: testIdWithKey('DevVerifierTemplatesSwitchElement'),
    value: useDevVerifierTemplates
  }))), !store.onboarding.didCreatePIN && /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    style: styles.settingLabelText
  }, t('NameWallet.EnableWalletNaming'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('NameWallet.ToggleWalletNaming'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleEnableWalletNamingSwitch')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: enableWalletNaming ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleWalletNamingSwitch,
    testID: testIdWithKey('EnableWalletNamingSwitchElement'),
    value: enableWalletNaming
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    style: styles.settingLabelText
  }, t('Settings.PreventAutoLock'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('Settings.TogglePreventAutoLock'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('TogglePreventAutoLockSwitch')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: preventAutoLock ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: togglePreventAutoLockSwitch,
    testID: testIdWithKey('PreventAutoLockSwitchElement'),
    value: preventAutoLock
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(ThemedText, {
    variant: "bold",
    style: styles.settingLabelText
  }, t('PasteUrl.UseShareableLink'))), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.settingSwitchContainer,
    accessibilityLabel: t('PasteUrl.UseShareableLink'),
    accessibilityRole: 'switch',
    testID: testIdWithKey('ToggleUseShareableLink')
  }, /*#__PURE__*/React.createElement(Switch, {
    trackColor: {
      false: ColorPalette.grayscale.lightGrey,
      true: ColorPalette.brand.primaryDisabled
    },
    thumbColor: enableShareableLink ? ColorPalette.brand.primary : ColorPalette.grayscale.mediumGrey,
    ios_backgroundColor: ColorPalette.grayscale.lightGrey,
    onValueChange: toggleShareableLinkSwitch,
    testID: testIdWithKey('ShareableLinkSwitchElement'),
    value: enableShareableLink
  }))), /*#__PURE__*/React.createElement(View, {
    style: styles.settingContainer
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(Button, {
    title: t('Global.RefreshCredentials'),
    accessibilityLabel: t('Global.RefreshCredentials'),
    testID: testIdWithKey('Refresh Credentials'),
    onPress: onRunRefreshCycleTouched,
    buttonType: ButtonType.ModalPrimary
  })))));
};
export default Developer;
//# sourceMappingURL=Developer.js.map