import AsyncStorage from "@react-native-async-storage/async-storage";
import { createContext, createRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Appearance, Linking, Platform, StyleSheet, View } from "react-native";
import uuid from "react-native-uuid";
import * as Haptics from "expo-haptics";

/*
 *
 * Here you can find all the global variables and functions for the app
 *
 */

export const Constants = {
  defaultLanguage: "de",
  defaultColorSwatchesFavorites: [
    "#2ecc71",
    "#3498db",
    "#9b59b6",
    "#f1c40f",
    "#e67e22",
    "#e74c3c",
    "#fff",
  ],
  languages: [
    {
      name: "de",
      label: "Deutsch",
    },
    {
      name: "en",
      label: "English",
    },
  ],
  actionType: {
    layers: 0,
    ambilight: 1,
    motor: 2,
    wait: 3,
    waitUntilTimeX: 4,
    stop: 5,
    timeControl: 6,
    waitForConfirmationWithKey: 7,
    jumpToScene: 8,
  },
  globals: {
    contact_us_email: "support@shinnex.com",
    max_device_name_length: 20,
    max_scene_name_length: 20,
    faq_max_input_length: 1500,
  },
  defaultAnimationId: "00000000-0000-0000-0000-000000000000", // used id for -> No animation selected
  gradients: {
    orange: ["#fd4f2b", "#f9994d"],
    gray: ["#60696b", "#A9A9A9"],
    red: ["#f71e06", "#fd4b2f"],
  },
};

export const AppStyles = StyleSheet.create({
  typography20: {
    fontSize: 20,
    fontWeight: "bold",
    lineHeight: 24,
  },
  typography16: {
    fontSize: 16,
    lineHeight: 24,
  },
  typography14: {
    fontSize: 14,
    lineHeight: 20,
  },
  typography12: {
    fontSize: 12,
    lineHeight: 16,
  },
  Shadow: {
    elevation: 2, // only android
    shadowColor: "#000", // only ios
    shadowOffset: { width: 0, height: 1 }, // only ios
    shadowOpacity: 0.2, // only ios
    shadowRadius: 1, // only ios
  },
  disabled: {
    opacity: 0.6,
  },
  headerNavigationIcons: {
    padding: 17,
  },
  deviceLivePreview: {
    height: 200,
  },
  appBottom: {
    marginBottom: 40,
  },
  card: {
    borderRadius: 20,
  },
});

const DarkAppTheme = {
  _id: "dark", // needed for status bar
  colors: {
    primary: "#e67e22",
    secondary: "#9b59b6",
    gray: "#b2bec3",
    green: "#2ecc71",
  },
  text: "#fff",
  textSecondary: "#ddd",
  textDisabled: "#b2bec3",
  buttonTextColor: "#fff",
  buttonSecondary: "#818081",
  backgroundColor: "#21252a",
  card: {
    backgroundColor: "#2b3139",
  },
  drawer: {
    backgroundColor: "#2b3139",
    icon: "#fff",
    item: {
      inactiveTintColor: "#fff",
      activeTintColor: "#e67e22",
      iconColor: "#fff",
      activeBackgroundColor: "rgba(0, 0, 0, 0.1)",
    },
  },
  divider: "#434443",
  textInputBottomColor: "#b2b3b3",
  icon: "#ddd",
  iconDisabled: "#b2b3b3",
  switch: {
    trackColorTrue: "#01d064",
    trackColorFalse: "#b2b3b3",
    thumbColorTrue: "#f4f3f4",
    thumbColorFalse: "#f4f3f4",
    ios_backgroundColor: "#3e3e3e",
  },
  slider: {
    minimumTrackTintColor: "#e67e22",
    maximumTrackTintColor: "#fff",
    thumbTintColor: "#e67e22",
  },
  tag: {
    red: {
      backgroundColor: "#3d0801",
      text: "#fe4f50",
      borderColor: "#760b01",
    },
  },
  colorPickerDisabled: "rgba(0, 0, 0, 0.3)",
  modal: {
    transparentBackgroundColor: "rgba(0, 0, 0, 0.4)",
    pressedPickerItemColor: "rgba(0, 0, 0, 0.3)",
  },
  touchableOpacity: {
    activeOpacity: 0.7,
  },
};

const LightAppTheme = {
  _id: "light", // needed for status bar
  colors: {
    primary: "#e67e22",
    secondary: "#9b59b6",
    gray: "#636e72",
    green: "#2ecc71",
  },
  text: "#000",
  textSecondary: "#555",
  textDisabled: "#636e72",
  buttonTextColor: "#fff",
  buttonSecondary: "#aaa69d",
  backgroundColor: "#f7f7f7",
  card: {
    backgroundColor: "#fff",
  },
  drawer: {
    backgroundColor: "#fff",
    item: {
      inactiveTintColor: "#000",
      activeTintColor: "#e67e22",
      iconColor: "#000",
      activeBackgroundColor: "rgba(0, 0, 0, 0.05)",
    },
  },
  divider: "#ddd",
  textInputBottomColor: "#b2b3b3",
  icon: "#000",
  iconDisabled: "#b2b3b3",
  switch: {
    trackColorTrue: "#01d064",
    trackColorFalse: "#b2b3b3",
    thumbColorTrue: "#f4f3f4",
    thumbColorFalse: "#f4f3f4",
    ios_backgroundColor: "#3e3e3e",
  },
  slider: {
    minimumTrackTintColor: "#e67e22",
    maximumTrackTintColor: "#555",
    thumbTintColor: "#e67e22",
  },
  tag: {
    red: {
      backgroundColor: "#fff3f1",
      text: "#ff6060",
      borderColor: "#fecdc7",
    },
  },
  colorPickerDisabled: "rgba(0, 0, 0, 0.3)",
  modal: {
    transparentBackgroundColor: "rgba(0, 0, 0, 0.3)",
    pressedPickerItemColor: "rgba(0, 0, 0, 0.1)",
  },
  touchableOpacity: {
    activeOpacity: 0.5,
  },
};

export const AppUsedOpenSourceLicences = [
  {
    name: "@miblanchard/react-native-slider",
    url: "https://github.com/miblanchard/react-native-slider/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2019-present Michael Blanchard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "@react-native-async-storage/async-storage",
    url: "https://github.com/react-native-async-storage/async-storage/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2015-present, Facebook, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "@react-native-community/slider",
    url: "https://github.com/callstack/react-native-slider/blob/main/LICENSE.md",
    licenseInfo: `MIT License

Copyright (c) 2019 react-native-community

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`,
  },
  {
    name: "@react-navigation/drawer",
    url: "https://github.com/react-navigation/react-navigation/blob/main/packages/drawer/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2017 React Navigation Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "@react-navigation/native",
    url: "https://github.com/react-navigation/react-navigation/blob/main/packages/native/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2017 React Navigation Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "@react-navigation/stack",
    url: "https://github.com/react-navigation/react-navigation/blob/main/packages/stack/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2017 React Navigation Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "expo, expo-haptics, expo-linear-gradient, expo-status-bar",
    url: "https://github.com/expo/expo/blob/main/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "i18next",
    url: "https://github.com/i18next/i18next/blob/master/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2023 i18next

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "i18next-browser-languagedetector",
    url: "https://github.com/i18next/i18next-browser-languageDetector/blob/master/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2023 i18next

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react",
    url: "https://github.com/facebook/react/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) Meta Platforms, Inc. and affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-i18next",
    url: "https://github.com/i18next/react-i18next/blob/master/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2023 i18next

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-native",
    url: "https://github.com/facebook/react-native/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) Meta Platforms, Inc. and affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
`,
  },
  {
    name: "react-native-draggable-flatlist",
    url: "https://github.com/computerjazz/react-native-draggable-flatlist/blob/main/LICENSE.txt",
    licenseInfo: `MIT License

Copyright (c) 2019 computerjazz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-native-gesture-handler",
    url: "https://github.com/software-mansion/react-native-gesture-handler/blob/main/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2016 Software Mansion <swmansion.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  /*{
    name: "react-native-pager-view",
    url: "https://github.com/callstack/react-native-pager-view/blob/master/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2021 Callstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },*/
  {
    name: "react-native-reanimated",
    url: "https://github.com/software-mansion/react-native-reanimated/blob/main/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2016 Software Mansion <swmansion.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-native-safe-area-context",
    url: "https://github.com/th3rdwave/react-native-safe-area-context/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2019 Th3rd Wave

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-native-screens",
    url: "https://github.com/software-mansion/react-native-screens/blob/main/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2018 Software Mansion <swmansion.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  /* {
    name: "react-native-tab-view",
    url: "https://github.com/react-navigation/react-navigation/blob/main/packages/react-native-tab-view/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2017 React Native Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  }, */
  {
    name: "react-native-uuid",
    url: "https://github.com/eugenehp/react-native-uuid/blob/master/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2016-2021 Eugene Hauptmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
  {
    name: "react-native-zeroconf",
    url: "https://github.com/balthazar/react-native-zeroconf/blob/master/LICENSE",
    licenseInfo: `The MIT License (MIT)

Copyright (c) 2016 Balthazar Gronon

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`,
  },
  {
    name: "reanimated-color-picker",
    url: "https://github.com/alabsi91/reanimated-color-picker/blob/main/LICENSE",
    licenseInfo: `MIT License

Copyright (c) 2022 Ahmed Alabsi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
  },
];

export const HelpCenterDeQuestionsAnswers = [
  {
    topicText: "Allgemeine Fragen",
    question:
      "Was ist die grundlegende Funktionalität der Handy-App zur Gerätesteuerung?",
    answer:
      "Die Handy-App ermöglicht es Ihnen, kompatible Geräte über Ihr Smartphone oder Tablet zu steuern. Sie können verschiedene Funktionen aktivieren, Einstellungen ändern und Aktionen aus der Ferne ausführen.",
  },
  {
    question: "Welche Arten von Geräten können über die App gesteuert werden?",
    answer:
      "Unsere App unterstützt eine Vielzahl von Geräten, darunter Smart-Home-Geräte, Unterhaltungselektronik, Haushaltsgeräte und mehr.",
  },
  {
    question: "Ist die App für Android- und iOS-Geräte verfügbar?",
    answer:
      "Ja, die App ist sowohl für Android- als auch für iOS-Geräte verfügbar. Sie können sie im Google Play Store bzw. im Apple App Store herunterladen.",
  },
  {
    question: "Wo kann ich die App herunterladen?",
    answer:
      "Sie können die App direkt aus dem Google Play Store (für Android) oder dem Apple App Store (für iOS) herunterladen und installieren.",
  },
  {
    question:
      "Benötige ich eine Internetverbindung, um das Gerät über die App zu steuern?",
    answer:
      "Ja, eine aktive Internetverbindung (Wi-Fi oder mobile Daten) ist erforderlich, um die App mit dem Gerät zu verbinden und die Steuerungsfunktionen zu nutzen.",
  },
  {
    question: "Unterstützt die App mehrere Geräte gleichzeitig?",
    answer:
      "Ja, die App ermöglicht es Ihnen, mehrere kompatible Geräte gleichzeitig zu steuern und zwischen ihnen zu wechseln.",
  },
  {
    topicText: "Einrichtung und Verbindung",
    question:
      "Wie richte ich die Verbindung zwischen der App und meinem Gerät ein?",
    answer:
      "Die genaue Einrichtung kann je nach Gerät variieren, aber normalerweise müssen Sie die App öffnen, das Gerät auswählen und den Anweisungen auf dem Bildschirm folgen, um die Verbindung herzustellen.",
  },
  {
    question:
      "Welche Schritte sind erforderlich, um das Gerät zum ersten Mal mit der App zu verbinden?",
    answer:
      "Starten Sie die App, erstellen Sie ein Konto (falls erforderlich), fügen Sie das Gerät hinzu, indem Sie es aus der Liste der verfügbaren Geräte auswählen, und folgen Sie den Anweisungen zur Verbindungsherstellung.",
  },
  {
    question:
      "Benötige ich spezielle Einstellungen am Gerät, um die Verbindung herzustellen?",
    answer:
      "Ja, in den meisten Fällen müssen Sie sicherstellen, dass das Gerät eingeschaltet und im Verbindungsmodus ist, bevor Sie versuchen, es über die App zu verbinden.",
  },
  {
    question:
      "Welche Arten von Verbindungsmethoden werden von der App unterstützt (z. B. Bluetooth, WLAN, etc.)?",
    answer:
      "Unsere App unterstützt in der Regel WLAN-Verbindungen, um eine stabile und zuverlässige Steuerung über größere Entfernungen zu ermöglichen.",
  },
  {
    question:
      "Was sollte ich tun, wenn die Verbindung zwischen der App und dem Gerät verloren geht?",
    answer:
      "Überprüfen Sie zuerst Ihre Internetverbindung. Wenn das Problem weiterhin besteht, können Sie versuchen, das Gerät aus der App zu entfernen und erneut hinzuzufügen. Gegebenenfalls kann ein Neustart des Geräts helfen.",
  },
];

export const HelpCenterEnQuestionsAnswers = [
  {
    topicText: "General Questions",
    question:
      "What is the basic functionality of the mobile app for device control?",
    answer:
      "The mobile app allows you to control compatible devices using your smartphone or tablet. You can activate various functions, change settings, and perform actions remotely.",
  },
  {
    question: "What types of devices can be controlled through the app?",
    answer:
      "Our app supports a variety of devices, including smart home devices, entertainment electronics, household appliances, and more.",
  },
  {
    question: "Is the app available for both Android and iOS devices?",
    answer:
      "Yes, the app is available for both Android and iOS devices. You can download it from the Google Play Store or the Apple App Store.",
  },
  {
    question: "Where can I download the app?",
    answer:
      "You can download and install the app directly from the Google Play Store (for Android) or the Apple App Store (for iOS).",
  },
  {
    question:
      "Do I need an internet connection to control the device through the app?",
    answer:
      "Yes, an active internet connection (Wi-Fi or mobile data) is required to connect the app to the device and use the control functions.",
  },
  {
    question: "Does the app support multiple devices simultaneously?",
    answer:
      "Yes, the app allows you to control multiple compatible devices simultaneously and switch between them.",
  },
  {
    topicText: "Setup and Connection",
    question: "How do I set up the connection between the app and my device?",
    answer:
      "The exact setup process may vary depending on the device, but typically, you need to open the app, select the device, and follow the on-screen instructions to establish the connection.",
  },
  {
    question:
      "What steps are required to initially connect the device to the app?",
    answer:
      "Launch the app, create an account (if required), add the device by selecting it from the list of available devices, and follow the instructions for establishing the connection.",
  },
  {
    question:
      "Do I need specific settings on the device to establish the connection?",
    answer:
      "Yes, in most cases, you need to ensure that the device is powered on and in pairing mode before attempting to connect it through the app.",
  },
  {
    question:
      "What types of connection methods are supported by the app (e.g., Bluetooth, Wi-Fi, etc.)?",
    answer:
      "Our app typically supports Wi-Fi connections to enable stable and reliable control over longer distances.",
  },
  {
    question:
      "What should I do if the connection between the app and the device is lost?",
    answer:
      "First, check your internet connection. If the issue persists, you can try removing and re-adding the device from the app. If necessary, restarting the device might help.",
  },
];

/*
 *
 * Do not change code below this line if you don't know what you are doing
 *
 */

export async function StoreData(key, value) {
  try {
    const jsonValue = JSON.stringify(value);
    await AsyncStorage.setItem(key, jsonValue);
  } catch (e) {
    console.log("err", e);
  }
}

export async function GetData(key) {
  try {
    const jsonValue = await AsyncStorage.getItem(key);
    return jsonValue != null ? JSON.parse(jsonValue) : null;
  } catch (e) {
    console.log("err", e);
  }
}

export async function GetMultipleData(keys) {
  try {
    const data = await AsyncStorage.multiGet(keys);
    const retrievedData = data.map(([key, value]) => [key, JSON.parse(value)]);
    return retrievedData;
  } catch (e) {
    console.log("err", e);
  }
}

export function GetDataFromList(list, key) {
  return list.find((v) => v[0] === key)[1];
}

export function GetUuid() {
  return uuid.v4();
}

// data set in the app by default or provided by our servers on firmware update
const devDevicesFirmwareModes = {
  lightModes: [
    {
      id: "6138e651-54c5-4fd4-8f40-3364f4e9dfe2",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Einfarbig",
        en: "Solid",
      },
      defaults: ["red"],
      adjustments: [],
    },
    {
      id: "c7097a60-faa9-4928-a531-0a8ecbc115d9",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Zufällig",
        en: "Random",
      },
      defaults: ["red", "orange", "blue"],
      adjustments: [
        {
          type: "slider",
          variableName: "colorSwitching",
          iconName: "fan",
          name: {
            de: "Wechsel der Farben",
            en: "Color changing",
          },
          min: 0,
          max: 6,
          defaultValue: 2,
          unitOfMeasurement: {
            de: "s",
            en: "s",
          },
        },
      ],
    },
    {
      id: "b42c665a-c2ab-4029-9162-2280caae3274",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Regenbogen",
        en: "Rainbow",
      },
      defaults: [],
      adjustments: [
        {
          type: "slider",
          variableName: "modeSpeed",
          iconName: "fan",
          name: {
            de: "Schnelligkeit des Modus",
            en: "Speed of the mode",
          },
          min: 0,
          max: 10,
          defaultValue: 5,
          unitOfMeasurement: {
            de: "s",
            en: "s",
          },
        },
        {
          type: "slider",
          variableName: "repeatingInterval",
          iconName: "repeat-variant",
          name: {
            de: "Wiederholungsinterval",
            en: "Repeating interval",
          },
          min: 1,
          max: 10,
          defaultValue: 8,
          unitOfMeasurement: {
            de: "s",
            en: "s",
          },
        },
      ],
    },
  ],
  lightAnimationsIn: [
    {
      id: Constants.defaultAnimationId,
      supportedFirmwareVersions: ["*"],
      name: {
        de: "Keine",
        en: "None",
      },
      adjustment: {},
    },
    {
      id: "6c5570da-ec53-4788-a8cd-03c724eb81b8",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Aufblenden",
        en: "Fade in",
      },
      adjustment: {
        type: "slider",
        variableName: "duration",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        iconName: "repeat-variant",
        min: 1,
        max: 6,
        defaultValue: 4,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
  ],
  lightAnimationsOut: [
    {
      id: Constants.defaultAnimationId,
      supportedFirmwareVersions: ["*"],
      name: {
        de: "Keine",
        en: "None",
      },
      adjustment: {},
    },
    {
      id: "cb5b791e-213c-4684-9585-b0c42cbfafb5",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Ausblenden",
        en: "Fade out",
      },
      adjustment: {
        type: "slider",
        variableName: "duration",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        iconName: "repeat-variant",
        min: 1,
        max: 6,
        defaultValue: 2,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
  ],
  motorModes: [
    {
      id: "41de8c57-fc99-40a4-b6eb-a8d0d4569bc8",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Hin und her",
        en: "Back and forth",
      },
      defaults: [],
      adjustments: [
        {
          type: "slider",
          variableName: "duration",
          iconName: "repeat-variant",
          name: {
            de: "Dauer",
            en: "Duration",
          },
          min: 1,
          max: 6,
          defaultValue: 2,
          unitOfMeasurement: {
            de: "s",
            en: "s",
          },
        },
      ],
    },
  ],
  motorAnimationsIn: [
    {
      id: "b27003a7-447d-4b2b-b89a-5780b91f6614",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Ruckartig in",
        en: "Jerking in",
      },
      defaults: [],
      adjustment: {
        type: "slider",
        variableName: "duration",
        iconName: "repeat-variant",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        min: 1,
        max: 3,
        defaultValue: 2,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
    {
      id: "13096781-92d7-4694-a8b8-b3a92399b922",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Glatt in",
        en: "Smooth in",
      },
      defaults: [],
      adjustment: {
        type: "slider",
        variableName: "duration",
        iconName: "repeat-variant",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        min: 1,
        max: 8,
        defaultValue: 4,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
  ],
  motorAnimationsOut: [
    {
      id: "b27003a7-447d-4b2b-b89a-5780b91f6614",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Ruckartig out",
        en: "Jerking out",
      },
      defaults: [],
      adjustment: {
        type: "slider",
        variableName: "duration",
        iconName: "repeat-variant",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        min: 1,
        max: 3,
        defaultValue: 2,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
    {
      id: "13096781-92d7-4694-a8b8-b3a92399b922",
      supportedFirmwareVersions: ["1.0.1"],
      name: {
        de: "Glatt out",
        en: "Smooth out",
      },
      defaults: [],
      adjustment: {
        type: "slider",
        variableName: "duration",
        iconName: "repeat-variant",
        name: {
          de: "Dauer",
          en: "Duration",
        },
        min: 1,
        max: 8,
        defaultValue: 4,
        unitOfMeasurement: {
          de: "s",
          en: "s",
        },
      },
    },
  ],
};

// this data is transmitted from the device to the user app
const devDevices = [
  {
    id: "1f21a12a-0bec-4336-99bb-df3f9fc9f537", // deviceId
    displayName: "Turtle",
    deviceModel: "Aurora",
    deviceMacAddress: "12:34:56:78:9A:BC",
    deviceIp: "127.0.0.1",
    firmware: {
      version: "1.0.1",
      lastUpdated: "11.07.2023 um 20:33 Uhr",
    },
    selectedScene: "",
  },
  {
    id: "5b331a12a-0bec-4336-99bb-df3f9fc9f537", // deviceId
    displayName: "Elona",
    deviceModel: "Aurora",
    deviceMacAddress: "AB:CD:EF:12:34:56",
    deviceIp: "192.168.0.1",
    firmware: {
      version: "1.0.1",
      lastUpdated: "11.07.2023 um 20:33 Uhr",
    },
    selectedScene: "",
  },
];

export function AddNewDevice(displayName, deviceModel, deviceIp) {
  return {
    id: GetUuid(),
    displayName: displayName,
    deviceModel: deviceModel,
    deviceIp: deviceIp,
    firmware: {
      version: "1.0.1",
      lastUpdated: "11.07.2023 um 20:33 Uhr",
    },
    selectedScene: "",
  };
}

// preview
const devDeviceScenes = [
  {
    sceneId: "", // sceneId
    deviceId: "",
    name: "",
  },
];

export function NewDeviceScene(name) {
  return {
    sceneId: GetUuid(),
    deviceId: AppSelectedUserDevice.current.id,
    name: name,
  };
}

// preview
const devDeviceSceneActions = [
  {
    actionId: "", // random id
    sceneId: "",
    type: "", // layers, ambilight, motor
    modeId: "",
    // affected layers, animation speed...
    modeAdjustments: {
      layers: [0, 1],
      colors: ["#fff", "#000"],
    },
    animationInId: "",
    animationOutId: "",
    animationInAdjustment: {
      duration: 32,
    },
    animationOutAdjustment: {
      duration: 32,
    },
  },
];

export function NewAction(sceneId, actionType, modeAdjustments) {
  return {
    actionId: GetUuid(),
    sceneId: sceneId,
    type: actionType, // layers, ambilight, motor
    modeId: "",
    modeAdjustments: modeAdjustments,
    animationInId: Constants.defaultAnimationId, // default animation id for -> No animation selected
    animationInAdjustment: {},
    animationOutId: Constants.defaultAnimationId, // default animation id for -> No animation selected
    animationOutAdjustment: {},
  };
}

export function GetDevice(devices) {
  return devices.find((d) => d.id === AppSelectedUserDevice.current.id);
}

const appContextPreview = {
  appColorScheme: "",
  appLanguage: "",
  isUserExpertModeEnabled: "",
  isUserDeveloperModeEnabled: "",
  appTheme: DarkAppTheme,
  devices: [],
  deviceScenes: [],
  deviceSceneActions: [],
  deviceFirmwareModes: [],
  userColorSwatchesFavorites: [],
};

export const AppSelectedUserDeviceDefaultData = { id: "", routeName: "" };

export const AppSelectedUserDevice = createRef(
  AppSelectedUserDeviceDefaultData
);

export const AppContext = createContext(appContextPreview);

export function AppProvider({ children }) {
  const [appLanguage, setAppLanguage] = useState("de");
  const [appColorScheme, setAppColorScheme] = useState("light");
  const [appTheme, setAppTheme] = useState(DarkAppTheme);
  const [isUserExpertModeEnabled, setIsUserExpertModeEnabled] = useState(false);
  const [devices, setDevices] = useState(devDevices);
  const [deviceScenes, setDeviceScenes] = useState([]);
  const [deviceSceneActions, setDeviceSceneActions] = useState([]);
  const [deviceFirmwareModes, setDeviceFirmwareModes] = useState(
    devDevicesFirmwareModes
  );
  const [userColorSwatchesFavorites, setUserColorSwatchesFavorites] = useState(
    []
  );
  const { i18n } = useTranslation();

  // TODO: only while development
  const [isUserDeveloperModeEnabled, setIsUserDeveloperModeEnabled] =
    useState(false);

  const saveAppColorScheme = async (value) => {
    StoreData("appColorScheme", value);
    setAppColorScheme(value);

    let colorScheme;

    colorScheme = value === "auto" ? Appearance.getColorScheme() : value;

    setAppTheme(colorScheme === "light" ? LightAppTheme : DarkAppTheme);
  };

  const saveAppLanguage = async (value) => {
    StoreData("appLanguage", value);
    setAppLanguage(value);
    i18n.changeLanguage(value);
  };

  const saveUserExpertMode = async (value) => {
    StoreData("userExpertMode", value);
    setIsUserExpertModeEnabled(value);
  };

  // TODO: only while development
  const saveUserDeveloperMode = async (value) => {
    StoreData("userDeveloperMode", value);
    setIsUserDeveloperModeEnabled(value);
  };

  const saveUserColorSwatchesFavorites = async (value) => {
    StoreData("userColorSwatchesFavorites", value);
    setUserColorSwatchesFavorites(value);
  };

  return (
    <AppContext.Provider
      value={{
        appLanguage: appLanguage,
        setAppLanguage: saveAppLanguage,
        appColorScheme: appColorScheme,
        setAppColorScheme: saveAppColorScheme,
        appTheme: appTheme,
        isUserExpertModeEnabled: isUserExpertModeEnabled,
        setIsUserExpertModeEnabled: saveUserExpertMode,
        devices: devices,
        setDevices: setDevices,
        deviceScenes: deviceScenes,
        setDeviceScenes: setDeviceScenes,
        deviceSceneActions: deviceSceneActions,
        setDeviceSceneActions: setDeviceSceneActions,
        deviceFirmwareModes: deviceFirmwareModes,
        setDeviceFirmwareModes: setDeviceFirmwareModes,
        userColorSwatchesFavorites: userColorSwatchesFavorites,
        setUserColorSwatchesFavorites: saveUserColorSwatchesFavorites,
        isUserDeveloperModeEnabled: isUserDeveloperModeEnabled,
        setUserIsDeveloperModeEnabled: saveUserDeveloperMode,
      }}
    >
      {children}
    </AppContext.Provider>
  );
}

export function IsPlatformIos() {
  return Platform.OS === "ios";
}

export function VibrateShort() {
  //Vibration.vibrate(50);
  Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
}

export function ModalContainer({ children, withoutPadding }) {
  return (
    <View style={[{ flex: 1 }, !withoutPadding && { padding: 10 }]}>
      {children}
    </View>
  );
}

export function OpenUrl(url) {
  Linking.openURL(url).catch((err) =>
    console.error("An error occurred while opening the url", err)
  );
}
