// import-zones.ts — engine ZoneDefinition[] → schema Zone[] with auto-layout
export function importZones(engineZones, options) {
    const w = options?.defaultWidth ?? 6;
    const h = options?.defaultHeight ?? 5;
    const sp = options?.spacing ?? 4;
    const fidelity = [];
    const cols = Math.max(1, Math.ceil(Math.sqrt(engineZones.length)));
    const rows = Math.ceil(engineZones.length / cols);
    if (cols > 20 || rows > 20) {
        fidelity.push({
            level: 'approximated', domain: 'zones', severity: 'warning',
            fieldPath: 'grid-layout',
            message: `Auto-layout grid is ${cols}\u00d7${rows} — exceeds 20\u00d720 recommended maximum. Consider grouping zones into districts.`,
            reason: 'grid-exceeds-recommended-size',
        });
    }
    const zones = engineZones.map((ez, i) => {
        const col = i % cols;
        const row = Math.floor(i / cols);
        // Grid positions are auto-generated — always approximated
        fidelity.push({
            level: 'approximated', domain: 'zones', severity: 'warning',
            entityId: ez.id, fieldPath: 'gridX,gridY',
            message: `Zone '${ez.name}' grid position auto-generated`,
            reason: 'grid-auto-generated',
        });
        // Reconstruct description from TextBlock[] or string
        let description = '';
        if (ez.description) {
            if (Array.isArray(ez.description)) {
                description = ez.description.map((b) => b.text).join(' ');
            }
            else {
                description = ez.description;
            }
        }
        // Reconstruct interactables — engine only preserves names
        const interactables = (ez.interactables ?? []).map((name) => {
            fidelity.push({
                level: 'approximated', domain: 'zones', severity: 'info',
                entityId: ez.id, fieldPath: `interactables.${name}`,
                message: `Interactable '${name}' type defaulted to 'inspect'`,
                reason: 'interactable-type-defaulted',
            });
            return { name, type: 'inspect' };
        });
        // Reconstruct exits
        const exits = (ez.exits ?? []).map((e) => ({
            targetZoneId: e.targetZoneId,
            label: e.label ?? '',
            condition: e.condition?.type,
        }));
        return {
            id: ez.id,
            name: ez.name,
            tags: [...(ez.tags ?? [])],
            description,
            gridX: col * (w + sp),
            gridY: row * (h + sp),
            gridWidth: w,
            gridHeight: h,
            neighbors: [...(ez.neighbors ?? [])],
            exits,
            light: ez.light ?? 5,
            noise: ez.noise ?? 3,
            hazards: [...(ez.hazards ?? [])],
            interactables,
        };
    });
    return { zones, fidelity };
}
//# sourceMappingURL=import-zones.js.map