import { useMemo } from 'react';
import useLocalStorageState from 'use-local-storage-state';
import { config } from '@/shared/configs';
import { StorageKeys } from '@/shared/constants/local-storage';

export const DEFAULT_APP_VERSION = '1.0';
export const useAppVersion = () => {
  const [appVersion] = useLocalStorageState(StorageKeys.AppVersion, { defaultValue: DEFAULT_APP_VERSION });
  return appVersion;
};

export const webVersion = config.WEB_VERSION.replace(/\b(\d+)(?:\.0\.0)?\b/g, '$1');
export const useFullVersion = () => {
  const appVersion = useAppVersion();
  const fullVersion = useMemo(() => `${appVersion}.${webVersion}`, [appVersion]);
  return { fullVersion };
};
