<script setup lang="ts">
import {
  StoredObjectVersionPersisted,
  StoredObjectVersionWithPointInTime,
} from "../../../types";
import { useToast } from "vue-toast-notification";
import { restore_version } from "./api";

interface RestoreVersionButtonProps {
  storedObjectVersion: StoredObjectVersionPersisted;
}

const emit = defineEmits<{
  restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
}>();

const props = defineProps<RestoreVersionButtonProps>();

const $toast = useToast();

const restore_version_fn = async () => {
  const newVersion = await restore_version(props.storedObjectVersion);

  $toast.success("Version restaurée");
  emit("restoreVersion", { newVersion });
};
</script>

<template>
  <button
    class="btn btn-outline-action"
    @click="restore_version_fn"
    title="Restaurer"
  >
    <i class="fa fa-rotate-left"></i> Restaurer
  </button>
</template>

<style scoped lang="scss"></style>
