"use strict";

const Promise = require("bluebird");
const awaitImageElementLoad = require("../await-image-element-load");

module.exports = function loadImageFile(file) {
	// FIXME: Validation
	let objectURL = URL.createObjectURL(file);

	let element = document.createElement("img");
	element.src = objectURL;

	return Promise.try(() => {
		return awaitImageElementLoad(element);
	}).then(() => {
		URL.revokeObjectURL(objectURL);

		return element;
	});
};
