
class MediaUpload {

    static upload(isMultiple, callback, windowTitle = '', libraryType = [], addBtnLabel = '') {

        let send_attachment_bkp = wp.media.editor.send.attachment;
        let frame = wp.media({
            title: windowTitle, // Title of the modal window
            multiple: isMultiple || false,
            library: { type: libraryType },
            button: { text: addBtnLabel }
        });
        frame.on('close', function () {
            let selection = frame.state().get('selection');
            let attachments = [];
            selection.each(function (attachment) {
                attachments.push(attachment.toJSON());
            });
            wp.media.editor.send.attachment = send_attachment_bkp;
            callback(attachments);
        });
    
        // Open the media frame
        frame.open();
    }
}

export default MediaUpload;
