;'use strict';(function(exports){const CHUNK_SIZE=10;function DownloadPicker(){this.header=document.querySelector('#header');this.list=document.querySelector('#downloads ul');this.downloads=Object.create(null);navigator.mozSetMessageHandler('activity',this.handleActivity.bind(this));} DownloadPicker.prototype={handleActivity:function(activity){switch(activity.source.name){case'pick':this.activity=activity;this.attachActionHandlers();this.renderList();break;default:activity.postError('name not supported');}},renderList:function(){DownloadStore.getAll().onsuccess=(event)=>{var result=event.target.result;if(!Array.isArray(result)){result=[result];} var items=result.reverse();var total=document.body.dataset.downloads=items.length;this.renderFragment(items,0,total);};},renderFragment:function(items,from,total){var target=document.createDocumentFragment();var idx=from;for(;idx{this.renderFragment(items,idx,total);});},appendDownload:function(download,target){var id=download.id;if(this.downloads[id]){return;} this.downloads[id]=download;var item=document.createElement('li');item.dataset.id=id;var pFileName=document.createElement('p');pFileName.classList.add('fileName');pFileName.textContent=DownloadFormatter.getFileName(download);var pInfo=document.createElement('p');pInfo.classList.add('info');DownloadFormatter.getDate(download,(date)=>{DownloadFormatter.getTotalSize(download).then(totalSize=>{navigator.mozL10n.setAttributes(pInfo,'summary',{date:date,status:totalSize});});});item.appendChild(pFileName);item.appendChild(pInfo);target.appendChild(item);},attachActionHandlers:function(){this.header.addEventListener('action',()=>{this.activity.postError('cancelled');});this.list.addEventListener('click',(event)=>{var download=this.downloads[event.target.dataset.id];download&&this.pick(download);});},pick:function(download){LazyLoader.load(['shared/js/mime_mapper.js','shared/js/download/download_helper.js'],()=>{var req=DownloadHelper.info(download);req.onsuccess=(event)=>{this.activity.postResult(event.target.result);};req.onerror=(event)=>{DownloadHelper.handlerError(req.error,download);};});}};exports.downloadPicker=new DownloadPicker();}(window));