<template>
<section class="shadowbox">
<h2>Register</h2>
<account v-if="!step" :err="err" @submit="create" />
</section>
</template>

<script setup>
import { ref } from "vue"
import Account from "./account.vue"

let err = ref("")
const step = ref(0)

function create(user) {
  console.log(user)
  fetch(`/api/user`,
	    {method: 'POST',
	        body: JSON.stringify(user),
    		headers: {
        	"Accept": "application/json",
    		},
        }).then(resp => {
            console.log(resp)
            if (resp.ok) {
              return resp.json()
            } else {
              resp.text().then( e => err.value = e)
            }
        }).then(u => console.log(u))
}
</script>

<style scoped>
section {
	max-width: 400px;
	margin: auto;
}
</style>
