"use strict";
/**
 * Module Template
 *
 * Generates {Module}Module.ts for module configuration and registration.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateModuleTemplate = generateModuleTemplate;
const field_mapping_types_1 = require("../types/field-mapping.types");
/**
 * Generate the module configuration file content
 *
 * @param data - Frontend template data
 * @returns Generated file content
 */
function generateModuleTemplate(data) {
    const { names, moduleId, endpoint, fields, extendsContent } = data;
    // Build inclusions for lists
    const listFieldNames = getListFieldNames(data);
    const listInclusionFields = listFieldNames.map((f) => `\`${f}\``).join(", ");
    return `import { ${names.pascalCase} } from "@/features/${data.importTargetDir}/${names.kebabCase}/data/${names.pascalCase}";
import { createJsonApiInclusion } from "@carlonicora/nextjs-jsonapi/core";
import { ModuleFactory } from "@carlonicora/nextjs-jsonapi/core";
import { ${field_mapping_types_1.DEFAULT_MODULE_ICON} } from "lucide-react";

export const ${names.pascalCase}Module = (factory: ModuleFactory) =>
  factory({
    pageUrl: "/${names.pluralKebab}",
    name: "${names.pluralCamel}",
    model: ${names.pascalCase},
    moduleId: "${moduleId}",
    icon: ${field_mapping_types_1.DEFAULT_MODULE_ICON},
    inclusions: {
      lists: {
        fields: [
          createJsonApiInclusion("${endpoint}", [${listInclusionFields}]),
          createJsonApiInclusion("users", [\`name\`, \`avatar\`]),
        ],
      },
    },
  });
`;
}
/**
 * Get field names suitable for list display
 */
function getListFieldNames(data) {
    const { fields, extendsContent } = data;
    const fieldNames = [];
    // Content-extending modules get name, tldr
    if (extendsContent) {
        fieldNames.push("name", "tldr");
    }
    // Add other displayable fields (not content or abstract)
    fields.forEach((field) => {
        if (!["id", "content", "abstract", "createdAt", "updatedAt"].includes(field.name)) {
            if (!fieldNames.includes(field.name)) {
                fieldNames.push(field.name);
            }
        }
    });
    return fieldNames;
}
//# sourceMappingURL=module.template.js.map