import { COLORS, FONT, SIZES, SHADOWS } from './theme';
import ICONS from './icons';
import { CENTER, BTN, Background } from './styles';
import { SATSPERBITCOIN } from './math';
import { Dimensions, Platform } from 'react-native';

const WEBSITE_REGEX =
  /^(https?:\/\/|www\.)[a-z\d]([a-z\d-]*[a-z\d])*(\.[a-z]{2,})+/i;
const hasSpace = /\s/;

const VALID_URL_REGEX =
  /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/;

const IS_BLITZ_URL_REGEX =
  /^(https?:\/\/)?(www\.)?(blitz-wallet\.com|blitzwalletapp\.com|blitzwallet\.app)(\/[^\s]*)?$/;

const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

const VALID_USERNAME_REGEX = /^(?=.*\p{L})[\p{L}\p{N}_]+$/u;
const VALID_NAME_BIO_REGEX = /^[^<>{}`\\]*$/u;

const IS_SPARK_ID =
  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

const IS_SPARK_REQUEST_ID =
  /^SparkLightning(?:Receive|Send)Request:[0-9a-fA-F\-]+$/;
const IS_BITCOIN_REQUEST_ID = /^SparkCoopExitRequest:[0-9a-fA-F\-]+$/;

const GIFT_DEEPLINK_REGEX =
  /^(?:blitz-wallet:\/\/gift\/|https:\/\/(?:blitz-wallet\.com|blitzwalletapp\.com|blitzwallet\.app)\/gift\/)[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}(?:[#\/][A-Za-z0-9_-]+)?$/;

const CONTACT_UNIVERSAL_LINK_REGEX =
  /^https?:\/\/(blitzwalletapp\.com|blitzwallet\.app|blitz-wallet\.com)\/u\/[A-Za-z0-9_-]+\/?$/;

const FLASHNET_ERROR_CODE_REGEX = /\bFSAG-\d{4}(?:T\d+)?\b/;

const FLASHNET_REFUND_REGEX = /via transfer ([\da-fA-F\-]+)/;

const BASIC_ACCOUNT_NAME_REGEX = /^account\s+\d+$/i;

const NOSTR_NAME_REGEX = /^[a-zA-Z0-9]+$/;
const NOSTR_RELAY_URL = 'wss://relay.getalbypro.com/blitz';

const IS_LETTER_REGEX = /^[A-Za-z]$/;
const BITCOIN_SATS_ICON = '\u20BF';
const HIDDEN_BALANCE_TEXT = `E`;
const BITCOIN_SAT_TEXT = 'SAT';
const INFINITY_SYMBOL = '\u221E';
const APPROXIMATE_SYMBOL = '≈';

const ECASH_TX_STORAGE_KEY = 'CASHU_TRANSACTIONS';
const AUTO_CHANNEL_REBALANCE_STORAGE_KEY = 'ACR_STORAGE_KEY';
const ECASH_KEYSET_STORAGE = 'ECASH_KEYSET_STORAGE';
const BREEZ_WORKING_DIR_KEY = 'BREEZ_WORKING_DIR';
const QUICK_PAY_STORAGE_KEY = 'FAST_PAY_SETTINGS';
const SPEND_AND_REPLACE_STORAGE_KEY = 'spendAndReplace';
const LOGIN_SECUITY_MODE_KEY = 'LOGIN_SECURITY_MODE';
const MIGRATE_ECASH_STORAGE_KEY = 'MIGRATE_ECASH';
const POINT_OF_SALE_PAYOUT_DESCRIPTION = 'Blitz Tips Payout';
const NWC_SECURE_STORE_KEY = 'NWC_SECURE_STORE_KEY';
const NWC_SECURE_STORE_MNEMOINC = 'NWC_SECURE_STORE_MNEMOINC';
const NWC_LOACAL_STORE_KEY = 'NWC_LOACAL_STORE_KEY';
const LAST_LOADED_BLITZ_LOCAL_STOREAGE_KEY = 'LAST_LOADED_BLTIZ';
const BLITZ_PROFILE_IMG_STORAGE_REF = 'profile_pictures';
const BLITZ_DEFAULT_PAYMENT_DESCRIPTION = '';
const BIOMETRIC_KEY = 'biometricEncryptionKey';
const LOGIN_SECURITY_MODE_TYPE_KEY = 'LOGIN_SECURITY_MODE_TYPE';
const SPARK_CACHED_BALANCE_KEY = 'CACHED_SPARK_BALANCE';
const NWC_IDENTITY_PUB_KEY = 'NWC_WALLET_PUB_KEY';
const GENERATED_BITCOIN_ADDRESSES = 'GENERATED_BITCOIN_ADDRESSES';
const SHOPS_DIRECTORY_KEY = 'SHOPS_CURRENCY_LOCATION';
const RANDOM_LOGIN_KEYBOARD_LAYOUT_KEY = 'RANDOM_KEYBOARD_LAYOUT_KEY';
const PERSISTED_LOGIN_COUNT_KEY = 'PERSISTED_LOGIN_COUNT_KEY';
const HIDE_IN_APP_PURCHASE_ITEMS = Platform.OS === 'ios';
const GIFT_DERIVE_PATH_CUTOFF = 1763650239108;

const BLITZ_SUPPORT_DEFAULT_PAYMENT_DESCRIPTION = 'Blitz support';
const CUSTODY_ACCOUNTS_STORAGE_KEY = 'CUSTODY_ACCOUNTS';
const BLITZ_PAYMENT_DEEP_LINK_SCHEMES = [
  'bitcoin',
  'BITCOIN',
  'lightning',
  'LIGHTNING',
  'lnurl',
  'LNURL',
  'lnurlp',
  'LNURLP',
  'lnurlw',
  'LNURLW',
  'keyauth',
];

const CUSTOM_TOKEN_CURRENCY_OPTIONS = [{ token: 'USDB', currency: 'USD' }];

const CHATGPT_INPUT_COST = 10 / 1000000;
const CHATGPT_OUTPUT_COST = 30 / 1000000;

const MAX_DERIVED_ACCOUNTS = 1000; // Indices 0-999 for user accounts
const STARTING_INDEX_FOR_GIFTS_DERIVE = 1000; // Indices 1000-99999 for gifts
const MAX_GIFTS = 99000; // Maximum 99000 gifts
const STARTING_INDEX_FOR_POOLS_DERIVE = 100000; // Indices 100000+ for pools
const STARTING_INDEX_FOR_SAVINGS_DERIVE = 200000; // Indices 200000+ for savings (unlimited)

const POOL_DEEPLINK_REGEX =
  /^(?:blitz-wallet:\/\/pools\/|https:\/\/(?:blitz-wallet\.com|blitzwalletapp\.com|blitzwallet\.app)\/pools\/)[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\/?$/;

const PAYLINK_DEEPLINK_REGEX =
  /^(?:blitz-wallet:\/\/paylink\/|https:\/\/(?:blitz-wallet\.com|blitzwalletapp\.com|blitzwallet\.app)\/paylink\/)[A-Za-z0-9]{9}\/?$/;

const MIN_CHANNEL_OPEN_FEE = 500_000;
const MAX_CHANNEL_OPEN_FEE = 1_000_000;
const BLITZ_RECEIVE_FEE = 0.0;
const BLITZ_SEND_FEE = 0.0;
const LIQUID_DEFAULT_FEE = 30;
const MAX_ECASH_RECEIVE = 50_000;
const MAX_ECASH_BALANCE = 50_000;
const SMALLEST_ONCHAIN_SPARK_SEND_AMOUNT = 10_000;
const LIQUID_NON_BITCOIN_DRAIN_LIMIT = 10;

const CONTENT_KEYBOARD_OFFSET = 10;

const BLITZ_GOAL_USER_COUNT = 1_000_000;

const IS_DONTATION_PAYMENT_BUFFER = 10_000;
const SKELETON_ANIMATION_SPEED = 1200;
const TOKEN_TICKER_MAX_LENGTH = 10;

const BACKGROUND_THRESHOLD_MS = 8 * 60 * 1000;
const FORCE_RESET_SPAARK_STATE_MS = 6 * 60 * 1000;

const DEFAULT_PAYMENT_EXPIRY_SEC = 60 * 60 * 12;

const SMALL_BTC_PAYMENT_LIMIT = 500;
const SMALL_USD_PAYMENT_LIMIT = 0.05;

const SCREEN_DIMENSIONS = Dimensions.get('screen');

const USDB_TOKEN_ID =
  'btkn1xgrvjwey5ngcagvap2dzzvsy4uk8ua9x69k82dwvt5e7ef9drm9qztux87';
const DEFAULT_GOAL_EMOJI = '🎯';

const MAX_GIFT_QUANTITY = 20;
const GIFTS_QUANTITY_PRESETS = [1, 5, 10, 15, 20];

const OVER_BUDGET_LIMIT = 1;
const NEAR_BUDGET_LIMIT = 0.75;
const MIN_USD_BTC_LIGHTNING_SWAP = 1000;
const MIN_BTC_USD_AMOUNT_RECEIVEPAGE = 2000;

const BARCODE_FORMATS = ['qr-code'];

export {
  COLORS,
  FONT,
  SIZES,
  SHADOWS,
  ICONS,
  CENTER,
  BTN,
  Background,
  SATSPERBITCOIN,
  WEBSITE_REGEX,
  hasSpace,
  ECASH_TX_STORAGE_KEY,
  VALID_URL_REGEX,
  CHATGPT_INPUT_COST,
  CHATGPT_OUTPUT_COST,
  MIN_CHANNEL_OPEN_FEE,
  MAX_CHANNEL_OPEN_FEE,
  EMAIL_REGEX,
  VALID_USERNAME_REGEX,
  VALID_NAME_BIO_REGEX,
  BLITZ_RECEIVE_FEE,
  BLITZ_SEND_FEE,
  AUTO_CHANNEL_REBALANCE_STORAGE_KEY,
  ECASH_KEYSET_STORAGE,
  BREEZ_WORKING_DIR_KEY,
  QUICK_PAY_STORAGE_KEY,
  SPEND_AND_REPLACE_STORAGE_KEY,
  BLITZ_DEFAULT_PAYMENT_DESCRIPTION,
  LOGIN_SECUITY_MODE_KEY,
  LIQUID_DEFAULT_FEE,
  BITCOIN_SATS_ICON,
  MIGRATE_ECASH_STORAGE_KEY,
  CONTENT_KEYBOARD_OFFSET,
  HIDDEN_BALANCE_TEXT,
  MAX_ECASH_RECEIVE,
  MAX_ECASH_BALANCE,
  LIQUID_NON_BITCOIN_DRAIN_LIMIT,
  POINT_OF_SALE_PAYOUT_DESCRIPTION,
  BLITZ_GOAL_USER_COUNT,
  CUSTODY_ACCOUNTS_STORAGE_KEY,
  BLITZ_SUPPORT_DEFAULT_PAYMENT_DESCRIPTION,
  IS_DONTATION_PAYMENT_BUFFER,
  LAST_LOADED_BLITZ_LOCAL_STOREAGE_KEY,
  BLITZ_PROFILE_IMG_STORAGE_REF,
  SKELETON_ANIMATION_SPEED,
  BIOMETRIC_KEY,
  IS_LETTER_REGEX,
  BITCOIN_SAT_TEXT,
  LOGIN_SECURITY_MODE_TYPE_KEY,
  IS_SPARK_REQUEST_ID,
  SMALLEST_ONCHAIN_SPARK_SEND_AMOUNT,
  IS_BITCOIN_REQUEST_ID,
  NWC_SECURE_STORE_KEY,
  NWC_SECURE_STORE_MNEMOINC,
  NWC_LOACAL_STORE_KEY,
  SPARK_CACHED_BALANCE_KEY,
  IS_SPARK_ID,
  NOSTR_NAME_REGEX,
  TOKEN_TICKER_MAX_LENGTH,
  NOSTR_RELAY_URL,
  NWC_IDENTITY_PUB_KEY,
  SCREEN_DIMENSIONS,
  SHOPS_DIRECTORY_KEY,
  INFINITY_SYMBOL,
  GENERATED_BITCOIN_ADDRESSES,
  RANDOM_LOGIN_KEYBOARD_LAYOUT_KEY,
  PERSISTED_LOGIN_COUNT_KEY,
  BLITZ_PAYMENT_DEEP_LINK_SCHEMES,
  HIDE_IN_APP_PURCHASE_ITEMS,
  IS_BLITZ_URL_REGEX,
  MAX_DERIVED_ACCOUNTS,
  STARTING_INDEX_FOR_GIFTS_DERIVE,
  MAX_GIFTS,
  GIFT_DEEPLINK_REGEX,
  GIFT_DERIVE_PATH_CUTOFF,
  CONTACT_UNIVERSAL_LINK_REGEX,
  BACKGROUND_THRESHOLD_MS,
  FORCE_RESET_SPAARK_STATE_MS,
  DEFAULT_PAYMENT_EXPIRY_SEC,
  USDB_TOKEN_ID,
  APPROXIMATE_SYMBOL,
  FLASHNET_ERROR_CODE_REGEX,
  FLASHNET_REFUND_REGEX,
  CUSTOM_TOKEN_CURRENCY_OPTIONS,
  STARTING_INDEX_FOR_POOLS_DERIVE,
  STARTING_INDEX_FOR_SAVINGS_DERIVE,
  POOL_DEEPLINK_REGEX,
  PAYLINK_DEEPLINK_REGEX,
  BASIC_ACCOUNT_NAME_REGEX,
  DEFAULT_GOAL_EMOJI,
  MAX_GIFT_QUANTITY,
  GIFTS_QUANTITY_PRESETS,
  OVER_BUDGET_LIMIT,
  NEAR_BUDGET_LIMIT,
  MIN_USD_BTC_LIGHTNING_SWAP,
  BARCODE_FORMATS,
  SMALL_BTC_PAYMENT_LIMIT,
  SMALL_USD_PAYMENT_LIMIT,
  MIN_BTC_USD_AMOUNT_RECEIVEPAGE,
};
