// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import useMetaTitle from '#shared/composables/useMetaTitle.ts' import type { ComputedRef, Ref, UnwrapRef } from 'vue' import type { RouteLocationRaw } from 'vue-router' export interface HeaderOptions { title?: string | ComputedRef titleClass?: string | ComputedRef backTitle?: string | ComputedRef backUrl?: RouteLocationRaw | ComputedRef backAvoidHomeButton?: boolean backIgnore?: string[] refetch?: ComputedRef actionTitle?: string | ComputedRef actionHidden?: boolean | ComputedRef | Ref onAction?(): void } export const headerOptions = ref({}) const { setViewTitle } = useMetaTitle() watch( () => headerOptions.value.title, (title) => title && setViewTitle(title), ) export const useHeader = (options: HeaderOptions) => { onBeforeMount(() => { headerOptions.value = options as UnwrapRef }) onBeforeUnmount(() => { headerOptions.value = {} }) }