﻿<script setup>
import XIcon from '@/assets/icons/x.svg'
import {ref} from 'vue'
import {useClient} from "@/plugins/api.js";

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

const emits = defineEmits(['closeRequested'])

const facebookUrl = ref(props.creator.socials.facebookUrl)
const instagramUrl = ref(props.creator.socials.instagramUrl)
const linkedInUrl = ref(props.creator.socials.linkedInUrl)
const redditUrl = ref(props.creator.socials.redditUrl)
const tikTokUrl = ref(props.creator.socials.tikTokUrl)
const websiteUrl = ref(props.creator.socials.websiteUrl)
const xUrl = ref(props.creator.socials.xUrl)
const youtubeUrl = ref(props.creator.socials.youtubeUrl)

const client = useClient()
const save = async () => {
  try {
    await client.post(
        `/api/creators/${props.creator.id}/socials`,
        {
          "facebookUrl": facebookUrl.value || null,
          "instagramUrl": instagramUrl.value || null,
          "linkedInUrl": linkedInUrl.value || null,
          "redditUrl": redditUrl.value || null,
          "tikTokUrl": tikTokUrl.value || null,
          "websiteUrl": websiteUrl.value || null,
          "xUrl": xUrl.value || null,
          "youtubeUrl": youtubeUrl.value || null,
        })

    props.creator.socials.facebookUrl = facebookUrl
    props.creator.socials.instagramUrl = instagramUrl
    props.creator.socials.linkedInUrl = linkedInUrl
    props.creator.socials.redditUrl = redditUrl
    props.creator.socials.tikTokUrl = tikTokUrl
    props.creator.socials.websiteUrl = websiteUrl
    props.creator.socials.xUrl = xUrl
    props.creator.socials.youtubeUrl = youtubeUrl

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

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

</script>

<style scoped>
.icon {
  
  width: 28px;
  height: 30px;
  fill: #000000;
}
</style>

<template>
  <div class="pb-5 text-2xl">Reseaux Sociaux</div>
  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-facebook</v-icon>
    <v-text-field
        variant="outlined"
        v-model="facebookUrl"
        label="Lien Facebook"
        outlined
    ></v-text-field>
  </div>


  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-instagram</v-icon>
    <v-text-field
        variant="outlined"
        v-model="instagramUrl"
        label="Lien Instagram"
        outlined
    ></v-text-field>
  </div>

  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-linkedin</v-icon>
    <v-text-field
        variant="outlined"
        v-model="linkedInUrl"
        label="Lien LinkedIn"
        outlined
    ></v-text-field>
  </div>

  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-reddit</v-icon>
    <v-text-field
        variant="outlined"
        v-model="redditUrl"
        label="Lien Reddit"
        outlined
    ></v-text-field>
  </div>

  <div class="flex flex-row align-center">
    <div class="w-6 h-6 mb-5 mr-2">
      <XIcon></XIcon>
    </div>
    <v-text-field
        variant="outlined"
        v-model="tikTokUrl"
        label="Lien TikTok"
        outlined
    ></v-text-field>
  </div>

  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-web</v-icon>
    <v-text-field
        variant="outlined"
        v-model="websiteUrl"
        label="Lien site web"
        outlined
    ></v-text-field>
  </div>
  <div class="flex flex-row align-center">

    <div class="w-6 h-6 mb-5 mr-2">
      <XIcon class="icon"></XIcon>
    </div>

    <v-text-field
        variant="outlined"
        v-model="xUrl"
        label="Lien X"
        outlined
    ></v-text-field>
  </div>

  <div class="flex flex-row align-center">
    <v-icon class="mb-5 mr-2">mdi-youtube</v-icon>
    <v-text-field
        variant="outlined"
        v-model="youtubeUrl"
        label="Lien Youtube"
        outlined
    ></v-text-field>
  </div>

  <div class="flex justify-end space-x-4">
    <v-btn color="black" variant="text" @click="cancel">Annuler</v-btn>
    <v-btn color="#A6147D" @click="save">Enregistrer</v-btn>
  </div>
</template>
