<template>
  <router-link :to="routerTo">
    <slot />
  </router-link>
</template>

<script lang="ts">
import { Address, VALUE_TYPE } from "@/types/base";
import { defineComponent, PropType } from "vue";
import { RouteLocationRaw } from "vue-router";

interface IPointer {
  entity?: Address;
  attribute?: string;
  value?: { t: VALUE_TYPE; c: string };
}

export default defineComponent({
  name: "UpLink",
  props: {
    to: {
      type: Object as PropType<IPointer>,
      required: true,
    },
  },
  computed: {
    routerTo(): RouteLocationRaw {
      if (this.$route.name == "browse") {
        if (this.to.entity) {
          return {
            name: "browse",
            params: {
              addresses: [...this.$route.params.addresses].concat([
                this.to.entity,
              ]),
            },
          };
        }
      }
      return {};
    },
  },
});
</script>

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