"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateAdminDetailSidebar = generateAdminDetailSidebar;
const Generator = __importStar(require("@postxl/generator"));
/**
 * Generator function that generates the Admin Detail Sidebar wrapper component.
 * This component owns the right-side sidebar shell (Sidebar, SidebarRail, SidebarContent, Tabs)
 * and renders AuditLogSidebar and (optionally) ModelCommentContent internally.
 */
function generateAdminDetailSidebar({ context }) {
    const imports = Generator.ImportGenerator
        //
        .from(Generator.toBackendModuleLocation('@ui/admin/AdminDetailSidebar'))
        .add(context.admin.components.auditLogSidebar)
        .addImport({
        from: Generator.toBackendModuleLocation('@app-actions/ai-assistant-store'),
        items: [Generator.toFunctionName('useAiAssistantActions'), Generator.toFunctionName('useAiAssistantState')],
    })
        .addImport({
        from: Generator.toBackendModuleLocation('@app-actions/ai-sidebar-content'),
        items: [Generator.toFunctionName('AiSidebarContent')],
    });
    const hasComments = !!context.admin.components.commentSidebar;
    if (hasComments) {
        imports.add(context.admin.components.commentSidebar); // NOSONAR
    }
    return `
import type { ComponentProps } from 'react'
${hasComments ? "import { useState } from 'react'" : ''}
${imports.generate()}
import { APP_CONFIG } from '@lib/config'
import {
  Badge,
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarGroupContent,
  SidebarRail,
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from '@postxl/ui-components'

type AdminDetailSidebarProps = Readonly<{
  model: string
  entityId?: string | null
  entityIds?: readonly string[]
  field?: string | null
  labelField?: string
  onClearField?: () => void
  onClearEntity?: () => void
  ${hasComments
        ? `filteredIds?: string[]
  labelMap?: Record<string, string>
  selectedEntityId?: string
  singleCommentThread?: boolean`
        : ''}
}> & ComponentProps<typeof Sidebar>

export function AdminDetailSidebar({
  model,
  entityId,
  entityIds,
  field,
  labelField,
  onClearField,
  onClearEntity,
  ${hasComments ? 'filteredIds, labelMap, selectedEntityId, singleCommentThread,' : ''}
  ...sidebarProps
}: AdminDetailSidebarProps) {
  ${hasComments ? 'const [commentCount, setCommentCount] = useState(0)' : ''}
  const activeAdminTab = useAiAssistantState((state) => state.activeAdminTab)
  const { setActiveAdminTab } = useAiAssistantActions()
  const availableTabs = new Set([${hasComments ? "'comments', " : ''}'audit-log', ...(APP_CONFIG.enableAI ? ['ai'] : [])])
  const selectedTab = availableTabs.has(activeAdminTab) ? activeAdminTab : '${hasComments ? 'comments' : 'audit-log'}'

  return (
    <Sidebar {...sidebarProps} onMouseDown={(e) => e.stopPropagation()}>
      <SidebarRail />
      <SidebarContent>
        <Tabs value={selectedTab} onValueChange={setActiveAdminTab} className="h-full">
          <SidebarGroup>
            <SidebarGroupContent className="px-2 pt-2">
              <TabsList variant="protocol">
                ${hasComments
        ? `<TabsTrigger value="comments" variant="protocol" className="group/tab cursor-pointer px-3 h-8">Comments{commentCount > 0 && <Badge variant="secondary" size="xs" className="ml-1.5 transition-none group-hover/tab:bg-primary group-hover/tab:text-primary-foreground group-data-[state=active]/tab:bg-primary group-data-[state=active]/tab:text-primary-foreground">{commentCount}</Badge>}</TabsTrigger>`
        : ''}
                <TabsTrigger value="audit-log" variant="protocol" className="cursor-pointer px-3 h-8">Audit Log</TabsTrigger>
                {APP_CONFIG.enableAI && (
                  <TabsTrigger value="ai" variant="protocol" className="cursor-pointer px-3 h-8">AI</TabsTrigger>
                )}
              </TabsList>
            </SidebarGroupContent>
          </SidebarGroup>
          ${hasComments
        ? `<TabsContent value="comments" className="mt-0">
            <${context.admin.components.commentSidebar.name}
              model={model}
              filteredIds={filteredIds}
              labelMap={labelMap}
              selectedEntityId={selectedEntityId}
              onCommentCountChange={setCommentCount}
              singleCommentThread={singleCommentThread}
            />
          </TabsContent>`
        : ''}
          <TabsContent value="audit-log" className="mt-0">
            <AuditLogSidebar
              model={model}
              entityId={entityId}
              entityIds={entityIds}
              field={field}
              labelField={labelField}
              onClearField={onClearField}
              onClearEntity={onClearEntity}
            />
          </TabsContent>
          {APP_CONFIG.enableAI && (
            <TabsContent value="ai" className="mt-0 h-full min-h-0">
              <AiSidebarContent />
            </TabsContent>
          )}
        </Tabs>
      </SidebarContent>
    </Sidebar>
  )
}
`;
}
//# sourceMappingURL=detail-sidebar.generator.js.map