"use client"

import { useEffect } from "react"
import {
  applyDriveEditorFavicon,
  driveEditorDocumentTitle,
  type DriveEditorKind,
} from "@/lib/drive/drive-editor-metadata"

export function useDriveDocumentTitle(titleSegment: string, kind: DriveEditorKind) {
  useEffect(() => {
    const previousTitle = document.title
    document.title = driveEditorDocumentTitle(titleSegment, kind)
    const restoreFavicon = applyDriveEditorFavicon(kind)
    return () => {
      document.title = previousTitle
      restoreFavicon()
    }
  }, [titleSegment, kind])
}
