import DefaultTheme from 'vitepress/theme';
import { useRoute } from 'vitepress';
import { watch } from 'vue';
import { injectSpeedInsights } from '@vercel/speed-insights';
import { inject } from '@vercel/analytics';
import Layout from './Layout.vue';
import RuleBadge from './components/RuleBadge.vue';
import RuleCard from './components/RuleCard.vue';
import CodeTabs from './components/CodeTabs.vue';
import FeatureGrid from './components/FeatureGrid.vue';
import ConfigExample from './components/ConfigExample.vue';
import RuleCount from './components/RuleCount.vue';
import RuleHeader from './components/RuleHeader.vue';
import SchemaRef from './components/SchemaRef.vue';
import SkillCard from './components/SkillCard.vue';
import FaqList from './components/FaqList.vue';
import HelperCard from './components/HelperCard.vue';
import PromptDemo from './components/PromptDemo.vue';
import FeaturesSection from './components/FeaturesSection.vue';
import InstallCTA from './components/InstallCTA.vue';
import ShowcaseCard from './components/ShowcaseCard.vue';
import PipelineDiagram from './components/PipelineDiagram.vue';
import './style.css';

export default {
  extends: DefaultTheme,
  Layout,
  enhanceApp({ app }) {
    app.component('RuleBadge', RuleBadge);
    app.component('RuleCard', RuleCard);
    app.component('CodeTabs', CodeTabs);
    app.component('FeatureGrid', FeatureGrid);
    app.component('ConfigExample', ConfigExample);
    app.component('RuleCount', RuleCount);
    app.component('RuleHeader', RuleHeader);
    app.component('SchemaRef', SchemaRef);
    app.component('SkillCard', SkillCard);
    app.component('FaqList', FaqList);
    app.component('HelperCard', HelperCard);
    app.component('PromptDemo', PromptDemo);
    app.component('FeaturesSection', FeaturesSection);
    app.component('InstallCTA', InstallCTA);
    app.component('ShowcaseCard', ShowcaseCard);
    app.component('PipelineDiagram', PipelineDiagram);
  },
  setup() {
    const route = useRoute();
    const update = () => {
      if (typeof document !== 'undefined') {
        document.body.classList.toggle('rules-page', route.path.startsWith('/rules/'));
      }
    };
    update();
    watch(() => route.path, update);
    injectSpeedInsights();
    inject();
  },
};
