"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateAiSidepane = generateAiSidepane;
function generateAiSidepane() {
    return `import { Component, type ErrorInfo, type PropsWithChildren, useMemo } from 'react'
import { useLocation } from '@tanstack/react-router'

import { Sheet, SheetContent, SheetHeader, SheetTitle, Tabs, TabsContent, TabsList, TabsTrigger } from '@postxl/ui-components'

import { APP_CONFIG } from '@lib/config'
import { useAiAssistantActions, useAiAssistantState } from './ai-assistant-store'
import { AiSidebarContent } from './ai-sidebar-content'

type AiSidepaneErrorBoundaryState = {
  hasError: boolean
}

class AiSidepaneErrorBoundary extends Component<PropsWithChildren, AiSidepaneErrorBoundaryState> {
  public constructor(props: PropsWithChildren) {
    super(props)
    this.state = { hasError: false }
  }

  public static getDerivedStateFromError(): AiSidepaneErrorBoundaryState {
    return { hasError: true }
  }

  public componentDidCatch(error: unknown, info: ErrorInfo) {
    console.error('AiSidepane rendering failed:', error, info)
  }

  public render() {
    if (this.state.hasError) {
      return null
    }

    return this.props.children
  }
}

export const AiSidepane = () => {
  return (
    <AiSidepaneErrorBoundary>
      <AiSidepaneInner />
    </AiSidepaneErrorBoundary>
  )
}

const AiSidepaneInner = () => {
  const pathname = useLocation({ select: (location) => location.pathname })
  const open = useAiAssistantState((state) => state.open)
  const tabs = useAiAssistantState((state) => state.tabs)
  const { setOpen } = useAiAssistantActions()

  const isAdminRoute = pathname.startsWith('/admin')
  const isAdminOverviewRoute = pathname === '/admin' || pathname === '/admin/'

  const allTabs = useMemo(
    () => [
      { id: 'ai', label: 'AI', render: () => <AiSidebarContent /> },
      ...tabs,
    ],
    [tabs],
  )

  if (!APP_CONFIG.enableAI || (isAdminRoute && !isAdminOverviewRoute)) {
    return null
  }

  return (
    <Sheet open={open} onOpenChange={setOpen}>
      <SheetContent side="right" className="w-full p-0 sm:max-w-xl">
        <SheetHeader className="border-b px-4 py-3">
          <SheetTitle>Assistant</SheetTitle>
        </SheetHeader>

        <Tabs defaultValue={allTabs[0]?.id} className="flex h-[calc(100%-56px)] min-h-0 flex-col">
          <TabsList variant="protocol" className="mx-2 mt-2 justify-start">
            {allTabs.map((tab) => (
              <TabsTrigger key={tab.id} value={tab.id} variant="protocol" className="cursor-pointer px-3 h-8">
                {tab.label}
              </TabsTrigger>
            ))}
          </TabsList>

          {allTabs.map((tab) => (
            <TabsContent key={tab.id} value={tab.id} className="mt-0 h-full min-h-0 flex-1">
              {tab.render()}
            </TabsContent>
          ))}
        </Tabs>
      </SheetContent>
    </Sheet>
  )
}
`;
}
//# sourceMappingURL=ai-sidepane.generator.js.map