import Nav from "./Nav"

function Emberek() {

    
    return (
        <>
            <Nav/>
            <button onClick={() => lekeres()}>Emberek lekérése</button>
            <div className="people-wrapper"></div>
        </>
    )
}

async function lekeres() {
    try {
        const lekeres = await fetch("https://swapi.dev/api/people")
        const result = await lekeres.json()
    
        const peopleWrapperDiv = document.querySelector(".people-wrapper")
        
        for (let person of result.results) {
            const person_values = Object.entries(person)

            for (let i = 0; i < 8; i++) {
                let person_value_list = person_values[i]
                const pCreate = document.createElement("p")
                pCreate.innerHTML = `${person_value_list[0]}: ${person_value_list[1]}`
                peopleWrapperDiv.appendChild(pCreate)
            }

            peopleWrapperDiv.appendChild(document.createElement("br"))
        }
    }

    catch (e) {
        alert(`Hiba történt: ${e}`)
    }
}


export default Emberek