// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ import type { ComputedRef, Ref, UnwrapRef } from 'vue' import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import type { RouteLocationRaw } from 'vue-router' import useMetaTitle from '@shared/composables/useMetaTitle' export interface HeaderOptions { title?: string | ComputedRef titleClass?: string | ComputedRef backTitle?: string | ComputedRef backUrl?: RouteLocationRaw | ComputedRef actionTitle?: string | ComputedRef actionDisabled?: boolean | ComputedRef | Ref onAction?(): unknown } 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 = {} }) }