!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var i in s)("object"==typeof exports?exports:e)[i]=s[i]}}(self,(function(){return(()=>{"use strict";var e={d:(t,s)=>{for(var i in s)e.o(s,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{EllipsisDrive:()=>i});const s=class{folders=[];blocks=[];text=void 0;name=void 0;id=void 0;root=!1;showExpanded=!1;foldersExpanded=!1;trueRoot=!1;depth=0;constructor(e,t,s,i=0,o=!1){this.text=e,this.name=t,this.id=s,this.root=o,this.blocks=[],this.folders=[],this.depth=i}},i=class{BLUE="#089EC8";GRAY="rgba(0, 0, 0, 0.87)";SVGGRAY="rgba(0, 0, 0, 0.54)";APIURL="https://api.ellipsis-drive.com/v1";DEPTHFACTOR=25;debounce=(e,t=300)=>{let s;return(...i)=>{clearTimeout(s),s=setTimeout((()=>{e.apply(this,i)}),t)}};arrowDown=(e=0)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.innerHTML='',t.style.fill=this.SVGGRAY,t.style.height=15,t.style.width=15,t.style.cursor="pointer",t.style.transition="transform 195ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",t.style.marginLeft=this.DEPTHFACTOR*e+"px",t.classList.add("ellipsis-folder-arrow-down"),t};arrowRight=(e=0)=>{let t=this.arrowDown(e);return t.classList.remove("ellipsis-folder-arrow-down"),t.classList.add("ellipsis-folder-arrow-right"),t.style.transform="rotate(-90deg)",t};getFolderSVG=(e,t=0)=>{const s=document.createElementNS("http://www.w3.org/2000/svg","svg");switch(s.style.height=23,s.style.width=23,s.style.position="relative",s.style.bottom=5,s.style.fill=this.SVGGRAY,s.style.cursor="pointer",s.style.marginLeft=this.DEPTHFACTOR*t+10+"px",s.style.float="left",s.classList.add("ellipsis-folder-icon"),e){case"myMaps":s.innerHTML='';break;case"shared":s.innerHTML='';break;case"favorites":s.innerHTML='';break;default:s.innerHTML=''}return s};getVectorSVG=e=>{let t=document.createElement("div");t.style.backgroundColor="#3F51B5",t.style.borderRadius="50%",t.style.height="20px",t.style.width="20px",t.style.alignItems="center",t.style.display="flex",t.style.float="left",t.style.marginLeft=this.DEPTHFACTOR*(e+1)+"px";const s=document.createElementNS("http://www.w3.org/2000/svg","svg");return s.style.height=15,s.style.cursor="pointer",s.style.float="left",s.classList.add("ellipsis-vector-icon"),s.innerHTML='',t.appendChild(s),t};getRasterSVG=e=>{let t=document.createElement("div");t.style.backgroundColor="#00796B",t.style.borderRadius="50%",t.style.height="20px",t.style.width="20px",t.style.alignItems="center",t.style.display="flex",t.style.float="left",t.style.marginLeft=this.DEPTHFACTOR*(e+1)+"px";const s=document.createElementNS("http://www.w3.org/2000/svg","svg");return s.style.height=15,s.style.fill="#FFFFFF",s.style.cursor="pointer",s.style.float="left",s.classList.add("ellipsis-raster-icon"),s.innerHTML='',t.appendChild(s),t};authError=!1;defaultSettings={loggedIn:!1,token:null,types:"",cb:e=>{console.log("Default callback is called, please provide your own callback!")},icon:"default",onlyFolders:!1,div:null};settings={};constructor(e={}){if(this.root={name:"ellipsis-folder-root",text:"ellipsis-folder-root",id:"ellipsis-folder-root",trueRoot:!0,showExpanded:!0,foldersExpanded:!0,folders:[new s("My Drive","myMaps","myMaps",0,!0),new s("Shared with me","shared","shared",0,!0),new s("Favorites","favorites","favorites",0,!0)],blocks:[]},this.settings={...this.defaultSettings,...e},"div"in e){if("token"in e)this.settings.token=e.token,this.settings.loggedIn=!0;else{const e=window.location.search,t=new URLSearchParams(e);t.has("token")&&(this.settings.token=t.get("token"),this.settings.loggedIn=!0)}this.settings.div.style.backgroundColor="#f5f5f5",this.settings.div.style.overflow="scroll",this.render()}else console.warn("No div is provided!")}bouncingOnClick=(e,t)=>{e.showExpanded=!e.showExpanded,this.render()};onClick=this.debounce(this.bouncingOnClick,100);p=(e,t=0)=>{let s=document.createElement("p");return s.innerText=e,s.style.paddingLeft=this.DEPTHFACTOR*t+40+"px",s.classList.add("ellipsis-folder-p"),s.style.fontFamily='"Roboto Condensed","Roboto","Helvetica","Lucida Sans Unicode","sans-serif"',s};getListFolder=async(e,t="folder",s=!1)=>{let i="";i=s?`${this.APIURL}/path/listRoot`:`${this.APIURL}/path/listFolder`;let o={root:e.id,pathId:e.id,type:t},l={"Content-Type":"application/json",Authorization:`Bearer ${this.settings.token}`};return(await fetch(i,{method:"POST",body:JSON.stringify(o),headers:l})).json()};login=e=>{};fixFolder=e=>{let t=new s;return t.name=e.name,t.id=e.id,t.text=e.name,t.obj=e,t};fixBlock=e=>{let t=new class{type=void 0;name=void 0;id=void 0};return t.type=e.type,t.id=e.id,t.name=e.name,t.obj=e,t};expandFolder=e=>{e.foldersExpanded=!0;let t=e.root,s=this.getListFolder(e,"folder",t),i=this.getListFolder(e,"map",t);Promise.all([s,i]).then((t=>{if(!("result"in t[0]))return this.authError=!0,void this.render();e.folders=t[0].result.map(this.fixFolder),e.blocks=t[1].result.map(this.fixBlock),e.folders.map((t=>{t.depth=e.depth+1})),e.blocks.map((t=>{t.depth=e.depth+1})),this.render()}))};attachMouseEnter=(e,t)=>{e.style.color=this.GRAY,t||(t=[]),e.style.cursor="pointer";let s=(s,i)=>()=>{e.style.color=s;for(const e of t)e.style.fill=i};e.onmouseenter=s(this.BLUE,this.BLUE),e.onmouseleave=s(this.GRAY,this.SVGGRAY);for(const e of t)e.onmouseenter=s(this.BLUE,this.BLUE),e.onmouseleave=s(this.GRAY,this.SVGGRAY);return e};renderBlock=e=>{let t=document.createElement("div"),s=this.p(`${e.name}`,e.depth);return s.style.paddingLeft=`${parseInt(s.style.paddingLeft)+20}px`,s.onclick=()=>{this.settings.cb(e.obj)},s=this.attachMouseEnter(s),"map"==e.type?t.appendChild(this.getRasterSVG(e.depth)):t.appendChild(this.getVectorSVG(e.depth)),t.appendChild(s),t};renderFolder=e=>{let t=document.createElement("div");t.setAttribute("id",`${e.id}`),t.classList.add("ellipsis-folder");let s=document.createElement("div");s.setAttribute("id",`${e.id}_start`);let i=document.createElement("div");if(i.setAttribute("id",`${e.id}_end`),t.appendChild(s),t.appendChild(i),!e.trueRoot){s.onclick=t=>this.onClick(e,t);let t=this.p(`${e.text}`,e.depth);t.style.marginLeft="20px";let i=this.arrowRight(e.depth);e.showExpanded&&(i=this.arrowDown(e.depth));let o=this.getFolderSVG(e.id);t=this.attachMouseEnter(t,[i,o]),i.style.float="left",s.appendChild(i),s.appendChild(o),s.appendChild(t)}if(e.showExpanded&&!e.foldersExpanded){let s=this.p("Loading...",e.depth+1);t.insertBefore(s,i),this.expandFolder(e)}if(e.showExpanded){for(const s of e.folders)t.insertBefore(this.renderFolder(s),i);for(const s of e.blocks)t.insertBefore(this.renderBlock(s),i);0==e.folders.length&&e.blocks.length}return t};getButton=(e,t)=>{let s=document.createElement("button");return s.onclick=t,s.innerHTML=e,s.style.color="#fff",s.style.backgroundColor="#089EC8",s.style.boxShadow="0px 3px 1px -2px rgba(0,0,0,0.2),0px 2px 2px 0px rgba(0,0,0,0.14),0px 1px 5px 0px rgba(0,0,0,0.12)",s.style.padding="6px 16px",s.style.fontSize="1rem",s.style.minWidth="64px",s.style.boxSizing="border-box",s.style.transition='"background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',s.style.fontFamily=["Roboto Condensed","Roboto","-apple-system","BlinkMacSystemFont","Segoe UI","Helvetica Neue","Arial","sans-serif","Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Exo 2"],s.style.fontWeight="500",s.style.lineHeight="1.75",s.style.borderRadius="4px",s.style.letterSpacing="0.5px",s.style.textTransform="uppercase",s.style.border=0,s};loginDiv=()=>{let e=document.createElement("div");e.appendChild(this.p("Please log in to your Ellipsis Drive account:")),e.style.textAlign="center";let t=this.getButton("Log in",(()=>{window.location=`https://app.ellipsis-drive.com/login?referer=${window.location.href}`}));return e.appendChild(t),e};authErrorDiv=()=>{let e=document.createElement("div");e.appendChild(this.p("Authentication error, please check if token is correct")),e.style.textAlign="center";let t=this.getButton("Retry",(()=>{console.log("Retrying render"),this.render()}));return console.warn(`Authentication error, token used is: ${this.settings.token}`),e.appendChild(t),e};render=()=>{this.settings.div.innerHTML="",this.settings.loggedIn?this.authError?this.settings.div.appendChild(this.authErrorDiv()):this.settings.div.appendChild(this.renderFolder(this.root)):this.settings.div.appendChild(this.loginDiv())}};return t})()}));