"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.generateAdminSidebar = generateAdminSidebar;
const Generator = __importStar(require("@postxl/generator"));
const utils_1 = require("../utils");
/**
 * Generator function that generates the shared Admin sidebar component
 */
function generateAdminSidebar({ context }) {
    const imports = Generator.ImportGenerator
        //
        .from(Generator.toBackendModuleLocation('@ui/admin/AdminSidebar'))
        .addImport({
        from: Generator.toBackendModuleLocation('@components/ui/sidebar/sidebar'),
        items: [
            Generator.toFunctionName('Sidebar'),
            Generator.toFunctionName('SidebarContent'),
            Generator.toFunctionName('SidebarHeader'),
            Generator.toFunctionName('SidebarItem'),
            Generator.toFunctionName('sidebarLinkClassName'),
            Generator.toFunctionName('SidebarMobileToggle'),
            Generator.toFunctionName('SidebarOverlay'),
            Generator.toFunctionName('SidebarProvider'),
            Generator.toFunctionName('SidebarSection'),
        ],
    });
    const { schemas: sortedSchemas, modelsBySchema } = (0, utils_1.groupAndSortModelsBySchema)(context);
    // Generate the schema sections
    const schemaSections = sortedSchemas
        .map((schema) => {
        const models = modelsBySchema.get(schema);
        const modelLinks = models
            .map((model) => `
              <SidebarItem key="${model.name}">
                <Link to="${model.route}" className={sidebarLinkClassName}>
                  ${model.userFriendlyName}
                </Link>
              </SidebarItem>`)
            .join('');
        return `
            <SidebarSection key="${schema}" title="${schema}">
              ${modelLinks}
            </SidebarSection>`;
    })
        .join('');
    return `
import { Link } from '@tanstack/react-router'
${imports.generate()}

export function AdminSidebar() {
  return (
    <SidebarProvider>
      <SidebarMobileToggle />
      <Sidebar>
        <div className="p-4">
          <SidebarHeader
            title={
              <Link to="/admin" className="text-lg font-bold hover:text-blue-600 dark:hover:text-blue-400 transition-colors">
                Admin
              </Link>
            }
          />
          <SidebarContent>
            ${schemaSections}
            {import.meta.env.NEXT_PUBLIC_ALLOW_ADMIN === 'true' && (
              <SidebarSection title="Advanced">
                <SidebarItem>
                  <Link to="/admin/data-management" className={sidebarLinkClassName}>
                    Data Management
                  </Link>
                </SidebarItem>
              </SidebarSection>
            )}
          </SidebarContent>
        </div>
      </Sidebar>
      <SidebarOverlay />
    </SidebarProvider>
  )
}
`;
}
//# sourceMappingURL=admin-sidebar.generator.js.map