import { getURLSearchParams } from '@/tools';


const userAgent = navigator.userAgent;

export function platformIsAIO() {
  return /Six\/applet \(AIO;.+\)/i.test(userAgent) || /aio\/\w+/i.test(userAgent);
}

export function platformIsAIO_1() {
  return /aio\/1\.0/i.test(userAgent);
}

export function getSerialNumberSync() {
  const match = userAgent.match(/sn\/(\w+)/i);
  return match?.[ 1 ] ?? (
    function() {
      const query = getURLSearchParams();
      return query.get('serial') ?? query.get('serialNumber') ?? query.get('sn') ?? void 0;
    }
  )();
}

let getNetworkWall = async (): Promise<"exterior" | "interior"> => {
  const controller = new AbortController();
  setTimeout(() => controller.abort(), 1000);

  const wall = await fetch(`https://wx.hzliuzhi.com/aio/`, { method: 'HEAD', mode: 'no-cors', signal: controller.signal }).then(
    () => 'exterior' as const,
    () => 'interior' as const,
  );
  return (getNetworkWall = () => Promise.resolve(wall), wall);
};

export { getNetworkWall };

export * from './dialog.ui';
export * from './notify.ui';
export * from './toast.ui';
