export const storedFiles = (arg, id = true) => {
    // prettier-ignore
    const files = 'flow' in arg
        ? storedModule(arg)
        : 'type' in arg ? storedElement(arg) : storedBlock(arg);
    return id ? files.map(file => file.match(/BCE:\/\/([^/]+)\//)[1]) : files;
};
const storedModule = (module) => {
    return stored(module.image) ? [module.image] : [];
};
const storedBlock = (block) => {
    return [].concat(...block.elements.map(storedElement));
};
const storedElement = (element) => {
    switch (element.type) {
        case 'audio':
        case 'download':
        case 'image':
        case 'image-map':
        case 'video':
            return stored(element.location) ? [element.location] : [];
        case 'checkbox':
        case 'radio':
        case 'sort':
            return storedOptions(element.options);
        case 'matrix':
            const rows = storedOptions(element.rows);
            const columns = storedOptions(element.columns);
            return [...rows, ...columns];
        case 'table':
            return storedOptions(element.columns);
        default:
            return [];
    }
};
const storedOptions = (options) => {
    return options
        .filter(option => option.image && stored(option.image))
        .map(option => option.image);
};
const stored = (location) => {
    return !!location && location.startsWith('BCE://');
};
