window.W2PShopAdminOrder = new function () {
	this.get_preview_container_element = function () {
		return jQuery( '#w2pshop-order-item-preview-container' );
	}

	this.display_preview_image = function (title, images) {
		if (typeof images === 'undefined') {
			return; }

		this.get_preview_container_element().empty();
		images = (typeof images === 'string') ? [images] : images;
		for (let image of images) {
			this.get_preview_container_element().append(
				jQuery( '<img />' )
					.attr( 'src', image )
					.attr( 'alt', title )
					.attr( 'style', 'max-width: 100%;' )
			);
		}

		var vh = (window.innerHeight || jQuery(window).height() || 0);
		var size = Math.floor(vh * 0.9); // height ~90% of viewport; width equals height
		var tbUrl = '#TB_inline?width=' + size + '&height=' + size + '&inlineId=w2pshop-order-item-preview-container';
		window.tb_show(title, tbUrl);

		// wait a tick, then override ThickBox’s inline styles
		setTimeout(function() {
			jQuery('#TB_window').css({
				width: size + 'px',
				height: size + 'px',
				marginLeft: -(size / 2) + 'px',
				top: '35%'
			});
            jQuery('#TB_ajaxContent').css({
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                maxHeight: '90%',
                minWidth: '90%'
            });
        }, 50);
	}
}