import defaultSettings from '@/settings';
import { useSettingsStore } from '@/store/modules/settings';
import { useUserStore } from '@/store/modules/user';

/**
 * 动态修改标题
 */
export const useDynamicTitle = () => {
  const settingsStore = useSettingsStore();
  const userStore = useUserStore();
  
  // 优先使用租户名称
  if (userStore.tenantName) {
    document.title = userStore.tenantName;
  } else if (settingsStore.dynamicTitle) {
    document.title = settingsStore.title + ' - ' + import.meta.env.VITE_APP_TITLE;
  } else {
    document.title = defaultSettings.title as string;
  }
};
