import { createRouter, createWebHashHistory } from 'vue-router'
import AppLayout from '../components/AppLayout.vue'

const routes = [
  {
    path: '/',
    component: AppLayout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/Home.vue'),
        meta: { title: '首页', icon: 'House' }
      },
      {
        path: 'ptskit',
        name: 'Ptskit',
        component: () => import('../views/PtskitList.vue'),
        meta: { title: '站点种子', icon: 'Memo' }
      },
      {
        path: 'local-media',
        name: 'LocalMedia',
        component: () => import('../views/LocalMedia.vue'),
        meta: { title: '本地资源', icon: 'Folder' } 
      },
      {
        path: 'player-iframe', 
        name: 'PlayerIframe',  
        component: () => import('../views/PlayerIframeWrapper.vue'), 
        meta: { title: '在线观看', icon: 'VideoPlay' }
      },
      {
        path: 'fnos',
        name: 'Fnos',
        component: () => import('../views/MediaServerView.vue'),
        meta: { title: '飞牛影视', icon: 'Film', serverType: 'fnos' }
      },
      {
        path: 'emby',
        name: 'Emby',
        component: () => import('../views/MediaServerView.vue'),
        meta: { title: 'EMBY 媒体库', icon: 'VideoCamera', serverType: 'emby' }
      },
      {
        path: 'plex',
        name: 'Plex',
        component: () => import('../views/MediaServerView.vue'),
        meta: { title: 'Plex 媒体库', icon: 'Monitor', serverType: 'plex' }
      },
      {
        path: 'config',
        name: 'Config',
        component: () => import('../views/SystemConfig.vue'),
        meta: { title: '系统配置', icon: 'Setting' }
      }
    ]
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

const MAIN_TITLE = '短剧管理';
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = `${MAIN_TITLE} - ${to.meta.title}`;
  } else {
    document.title = MAIN_TITLE;
  }
  next();
});
export default router;
