import { StampsField } from '../../blockly/fields/stamps-field.js';
import { defaultStamp, stamps } from './data.js';
import { resolve } from '../../util/image-stamp.js';
import { _ } from '../../i18n/index.js';
const getImage = {
    type: 'function',
    name: 'getImage',
    verbose: '',
    parameters: [{
            type: 'parameter',
            name: 'sticker',
            verbose: '',
            returnType: 'Sticker',
            blockly: {
                customField() {
                    const images = stamps.map((image) => {
                        return {
                            id: image.id,
                            label: image.label,
                            stickers: Object.keys(image.stickers).map(id => ({ id, src: resolve(image.stickers[id]) })),
                        };
                    });
                    return new StampsField(defaultStamp, images);
                },
            },
        }],
    returnType: 'Sticker',
    blockly: {
        toolbox: false,
        javascript(Blockly, block) {
            const value = block.getFieldValue('STICKER');
            return [`'${value || ""}'`, Blockly.JavaScript.ORDER_ATOMIC];
        },
    }
};
export const random = {
    type: 'function',
    name: 'random',
    verbose: _('PART_STICKER_RANDOM', 'random'),
    returnType: 'Sticker'
};
export const randomFrom = {
    type: 'function',
    name: 'randomFrom',
    verbose: _('PART_STICKER_RANDOM_FROM', 'random'),
    returnType: 'Sticker',
    parameters: [{
            type: 'parameter',
            name: 'set',
            verbose: '',
            returnType: 'Enum',
            enum: stamps.map(stamp => [stamp.label, stamp.id]),
        }]
};
function hideBlock(block) {
    const newBlock = Object.assign({}, block);
    newBlock.blockly = { toolbox: false };
    return newBlock;
}
export const StampAPI = {
    type: 'module',
    name: 'stamp',
    verbose: 'Stamp',
    color: '#00c7b6',
    symbols: [
        getImage,
        hideBlock(random),
        hideBlock(randomFrom)
    ]
};
export default StampAPI;
//# sourceMappingURL=api.js.map