/* eslint-disable react/button-has-type */
/* eslint-disable jsx-a11y/img-redundant-alt */
import React from 'react';
import bgPng from './images/bg.png';
import styles from './index.less';

function isAndroid() {
  const u = navigator.userAgent;
  return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
}

function isIOS() {
  const u = navigator.userAgent;
  return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
}

export default function Download() {
  return (
    <>
      <div className={styles.download}>
        <img className={styles.bgImage} src={bgPng} alt="background image" />
        <button onClick={() => {
          if (isAndroid()) {
            window.open(
              `http://hn-fm-oss.mangguonews.com/bkb/BKB_release.apk?${new Date().getTime()}`);
          } else if(isIOS()) {
            window.open(
              `https://apps.apple.com/us/app/bkb-app/id6474423781`);
          } else {
            window.open(
              `http://hn-fm-oss.mangguonews.com/bkb/BKB_release.apk?${new Date().getTime()}`);
          }
        }}
          className={styles.button}
        >
          Download
        </button>
      </div>
    </>
  );
}
