import { speaker } from '@kano/icons/parts.js';
import { FieldSample } from './blockly/field-sample.js';
import { WebAudioTimestamp } from '../../../types.js';
import { _ } from '../../../i18n/index.js';
export function SpeakerAPIFactory(partClass) {
    const getter = {
        type: 'function',
        name: 'getSample',
        verbose: '',
        parameters: [{
                type: 'parameter',
                name: 'sample',
                verbose: '',
                returnType: 'Sample',
                blockly: {
                    customField() {
                        return new FieldSample(partClass.defaultSample, partClass.items);
                    },
                },
            }],
        returnType: 'Sample',
        blockly: {
            toolbox: false,
            javascript(Blockly, block) {
                const value = block.getFieldValue('SAMPLE');
                return [`'${value || ''}'`, Blockly.JavaScript.ORDER_ATOMIC];
            },
        }
    };
    return {
        type: partClass.type,
        label: _('PART_SPEAKER_LABEL', 'Speaker'),
        icon: speaker,
        color: '#ef5284',
        symbols: [{
                type: 'function',
                name: 'play',
                verbose: _('PART_SPEAKER_PLAY', 'play'),
                parameters: [{
                        type: 'parameter',
                        name: 'sample',
                        verbose: '',
                        returnType: 'Sample',
                        default: partClass.defaultSample,
                        blockly: {
                            shadow(def, m) {
                                return `<shadow type="${m.def.name}_getSample"><field name="SAMPLE">${partClass.defaultSample}</field></shadow>`;
                            },
                        },
                    }, {
                        type: 'parameter',
                        name: 'time',
                        returnType: Number,
                        blockly: {
                            scope: WebAudioTimestamp,
                        },
                    }],
            }, {
                type: 'function',
                name: 'loop',
                verbose: _('PART_SPEAKER_LOOP', 'loop'),
                parameters: [{
                        type: 'parameter',
                        name: 'sample',
                        verbose: '',
                        returnType: 'Sample',
                        default: partClass.defaultSample,
                        blockly: {
                            shadow(def, m) {
                                return `<shadow type="${m.def.name}_getSample"><field name="SAMPLE">${partClass.defaultSample}</field></shadow>`;
                            },
                        },
                    }],
            }, {
                type: 'function',
                name: 'stop',
                verbose: _('PART_SPEAKER_STOP', 'stop'),
            }, {
                type: 'variable',
                name: 'pitch',
                verbose: _('PART_SPEAKER_PITCH', 'pitch'),
                setter: true,
                returnType: Number,
                default: 100,
            }, {
                type: 'variable',
                name: 'volume',
                verbose: _('PART_SPEAKER_VOLUME', 'volume'),
                setter: true,
                returnType: Number,
                default: 100,
            }, getter],
    };
}
//# sourceMappingURL=factory.js.map