import { computed } from 'vue'

// 特殊映射表：slug -> pageType
const SLUG_TO_PAGE_TYPE_MAP: Record<string, string> = {
  'pagetype': 'PageType',
  'todo': 'ToDo',
  // 可以在这里添加更多映射
}

// URL slug 处理工具函数
export function slugToPageType(slug: string): string {
  if (!slug) return ''
  
  // 优先检查特殊映射
  if (SLUG_TO_PAGE_TYPE_MAP[slug]) {
    return SLUG_TO_PAGE_TYPE_MAP[slug]
  }
  
  // 默认转换规则
  return slug
    .split('-')
    .map(word => word.charAt(0).toUpperCase() + word.slice(1))
    .join(' ')
}

export function pageTypeToSlug(pageType: string): string {
  if (!pageType) return ''

  // 默认转换规则
  return pageType
    .split(' ')
    .map(word => word.toLowerCase())
    .join('-')
}

// URL参数处理组合式函数
export function usePageTypeSlug(route: any) {
  const pagetypeSlug = computed(() => (route.params.entity as string) || '')
  const entity = computed(() => slugToPageType(pagetypeSlug.value))
  
  return {
    pagetypeSlug,
    entity
  }
}
