﻿<template>
  <div class="card dialog">
    <div class="card-title">
      Courriel
    </div>

    <div class="card-entry">
      <v-text-field
          v-model="email"
          label="Votre courriel"
          variant="outlined"
      ></v-text-field>
    </div>

    <div class="card-actions">
      <button class="secondary"
              @click="cancel">
        Annuler
      </button>
      <button class="primary"
              @click="save">
        Enregistrer
      </button>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue';
import {useClient} from "@/plugins/api.js";

const props = defineProps({
  creator: {
    required: true
  }
})

const emits = defineEmits(['closeRequested'])

const email = ref(props.creator.email)

const client = useClient()
const save = async () => {
  try {
    await client.post(
        `/api/creators/${props.creator.id}/email`,
        {
          "facebookUrl": facebookUrl.value
        })

    props.creator.socials.facebookUrl = facebookUrl

    emits('closeRequested')
  } catch (error) {
    console.error(error)
  }
}

const cancel = () => {
  emits('closeRequested')
}

</script>


