import Head from 'next/head'
import { useState } from 'react';


export default function Home() {
  const [randomeLetter, setRandomLetter] = useState(_getRandomLetter())

  function _getRandomLetter() {
    return thaiConsonantsArray[Math.floor(Math.random() * thaiConsonantsArray.length)]
  }

  return (
    <>
      <Head>
        <title>Thai Stuff</title>
      </Head>

      <div className='card'>
        <div>
          <p>{randomeLetter.letter}</p>
          <p>{randomeLetter.phono}</p>
        </div>
        <div className='buttons'>
          <button onClick={async () => {
            console.log("pressed listen")
          }}>Listen</button>
          <button onClick={async () => {
            let k = _getRandomLetter()
            while (k == randomeLetter) {
              k = _getRandomLetter()
            }
            setRandomLetter(k)
          }}>Next</button>
        </div>
      </div>
    </>
  )
}


const thaiConsonantsArray = [
  {
    letter: 'ก',
    phono: 'ko kai',
  },
  {
    letter: 'ข',
    phono: 'kho khai',
  },
  {
    letter: 'คง',
    phono: 'kho khon',
  },
  {
    letter: 'ง',
    phono: 'ngo ngoo',
  },
  {
    letter: 'จ',
    phono: 'cho chan',
  },
  {
    letter: 'ฉ',
    phono: 'so chan',
  },
  {
    letter: 'ช',
    phono: 'so chon',
  },
  {
    letter: 'ซ',
    phono: 'so san',
  },
  {
    letter: 'ฌ',
    phono: 'so cho',
  },
  {
    letter: 'ญ',
    phono: 'yo ning',
  },
  {
    letter: 'ฎ',
    phono: 'do dek',
  },
  {
    letter: 'ฏ',
    phono: 'to tao',
  },
  {
    letter: 'ฐ',
    phono: 'tho thon',
  },
  {
    letter: 'ฑ',
    phono: 'tho thung',
  },
  {
    letter: 'ฒ',
    phono: 'tho tho',
  },
  {
    letter: 'ณ',
    phono: 'no nen',
  },
  {
    letter: 'บ',
    phono: 'bo bai',
  },
  {
    letter: 'ป',
    phono: 'po pao',
  },
  {
    letter: 'พ',
    phono: 'pho phan',
  },
  {
    letter: 'ม',
    phono: 'mo mi',
  },
  {
    letter: 'ฝ',
    phono: 'fo fan',
  },
  {
    letter: 'ฟ',
    phono: 'fo fa',
  },
  {
    letter: 'ภ',
    phono: 'pho phran',
  },
  {
    letter: 'ฝ',
    phono: 'fo fan',
  },
  {
    letter: 'ส',
    phono: 'so san',
  },
  {
    letter: 'ศ',
    phono: 'so si',
  },
  {
    letter: 'ษ',
    phono: 'so so',
  },
  {
    letter: 'ส',
    phono: 'so san',
  },
  {
    letter: 'ห',
    phono: 'ho hin',
  },
  {
    letter: 'ฬ',
    phono: 'lo ling',
  },
  {
    letter: 'ฮ',
    phono: 'ho ho',
  },
];
