<template>
  <q-card>
    <BalanceHeader v-model="sender" :show-selector="showSelector" @open-history="openHistory" />
    <q-separator />
    <q-card-section class="row q-col-gutter-md items-center">
      <balance-transfer-body :user="sender" />
    </q-card-section>
  </q-card>
</template>

<script lang="ts">
import { computed, ref, defineComponent } from 'vue';
import { hasPermission } from 'src/utils/permission';
import BalanceHeader from '../components/BalanceHeader.vue';
import BalanceTransferBody from 'src/plugins/balance/components/BalanceTransferBody.vue';
import PERMISSIONS from '../permissions';
import { useMainStore } from 'src/stores';

export default defineComponent({
  name: 'BalanceTransfer',
  components: { BalanceHeader, BalanceTransferBody },
  emits: { 'open-history': () => true },
  setup(_, { emit }) {
    const mainStore = useMainStore();

    const showSelector = computed(() => hasPermission(PERMISSIONS.SEND_OTHER));
    const sender = ref<FG.User | undefined>(mainStore.currentUser);

    function openHistory() {
      emit('open-history');
    }

    return {
      sender,
      showSelector,
      openHistory,
    };
  },
});
</script>
