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

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

const emits = defineEmits(['closeRequested']);

const stripeId = ref(props.creator.stripeId);
const t = useTranslations();

const client = useClient();

const save = async () => {
  try {
    await client.post(`/api/membership/stripe-account`, {
      stripeAccountId: stripeId.value,
    });

    props.creator.stripeId = stripeId.value;
    emits('closeRequested');
  } catch (error) {
    console.error('Error saving stripe id:', error);
  }
};

const cancel = () => {
  emits('closeRequested');
};
</script>

<template>
  <div class="card dialog">
    <div class="card-title">
      {{ t('title') }}
    </div>

    <div class="card-content">
      <v-text-field
          v-model="stripeId"
          :label="t('label')"
          outlined
          variant="outlined"
      ></v-text-field>

      <div class="card-actions">
        <button class="secondary"
                @click="cancel">
          {{ t('cancel') }}
        </button>
        <button class="primary"
                @click="save">
          {{ t('save') }}
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped>

</style>
