/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { NotebookDTO } from '../../models/NotebookDTO.js';
import { LexicalDTO } from '../../models/LexicalDTO.js';
import { ItemTypes } from '../constants.js';
/**
 * Convert raw space items from API response to model instances.
 * This utility function is shared between Space.getItems() and SpacerMixin.getSpaceItems()
 * to avoid code duplication.
 *
 * @param response - Raw API response containing space items
 * @param client - Client instance to pass to model constructors
 * @returns Array of Notebook and Lexical model instances
 */
export function convertSpaceItemsToModels(items, client) {
    const modelItems = [];
    for (const item of items) {
        // Check various possible type fields
        const itemType = item.type_s;
        // Only include notebooks and lexicals
        if (itemType === ItemTypes.NOTEBOOK) {
            modelItems.push(new NotebookDTO(item, client));
        }
        else if (itemType === ItemTypes.LEXICAL) {
            modelItems.push(new LexicalDTO(item, client));
        }
        // Skip everything else (exercises, cells, etc.)
    }
    return modelItems;
}
