define(["exports","./../actionsheet/actionsheet.js"],function(_exports,_actionsheet){function FluidHeader(container,options){var self=this,more=(container.classList.add("fluidHeaderContainer"),self.container=container,self.latestWidth=null,self.overflowItems=[],self.isTitleVisible=!0,self.resizeObserver=null,container.querySelector(".fluidHeaderMore"));function getRelevantElements(sorted){var selector=".fluidHeaderItem:not(.fluidHeaderMore)",selector=(options.collapseTitle||(selector+=":not(.formDialogHeaderTitle):not(h1):not(h2):not(h3)"),Array.from(self.container.querySelectorAll(selector)));return sorted?selector.map(function(element,idx){return{element:element,idx:idx}}).sort(function(a,b){var apri=a.element.dataset.fluidPriority||options.defaultPriority,bpri=b.element.dataset.fluidPriority||options.defaultPriority;return apri===bpri?options.defaultLTR?b.idx-a.idx:a.idx-b.idx:bpri-apri}):selector}function updateContainer(){var items=getRelevantElements(!0),more=(items.forEach(function(item){item.element.classList.remove("hide")}),container.querySelector(".fluidHeaderMore"));for(container.scrollWidth>container.clientWidth||0<options.extraItems.length?more.classList.remove("hide"):more.classList.add("hide"),self.overflowItems=[],self.isTitleVisible=!0;container.scrollWidth>container.clientWidth&&0!==function(){var _item$element$querySe,item=items.pop();return item?(item.element.classList.add("hide"),(item.element.classList.contains("formDialogHeaderTitle")||["H1","H2","H3"].find(function(tag){return item.element.tagName===tag}))&&(self.isTitleVisible=!1),"A"!==item.element.tagName&&"BUTTON"!==item.element.tagName?1:void self.overflowItems.push({id:"fluid-"+item.idx,Name:item.element.ariaLabel||item.element.title,icon:item.element.classList.contains("md-icon")?item.element.textContent:null==(_item$element$querySe=item.element.querySelector(".md-icon"))?void 0:_item$element$querySe.textContent})):0}(););}more?more.classList.add("hide"):((more=document.createElement("button")).className="fluidHeaderMore paper-icon-button-light md-icon hide",more.type="button",more.textContent=options.moreIcon,more.title=options.moreTitle,more.ariaLabel=options.moreTitle,options.moreLeft?container.prepend(more):container.append(more)),more.addEventListener("click",function(){var overflowItems=self.overflowItems.concat(options.extraItems),overflowItems=Object.assign({item:options.moreItemIfTitleCollapsed&&!self.isTitleVisible&&options.item,items:overflowItems,fields:["Name"],positionTo:more,positionY:"bottom",positionX:options.moreLeft?"left":"right",transformOrigin:(options.moreLeft?"left":"right")+" top",resolveOnClick:!0,hasItemIcon:!0},options.actionSheetOptions);_actionsheet.default.show(overflowItems).then(function(itemid){var idmatch=itemid.match(/fluid-(-?[0-9]+)/i),idmatch=(idmatch&&getRelevantElements()[idmatch[1]].click(),options.extraItems.find(function(ex){return ex.id===itemid}));idmatch&&idmatch.handler()})}),self.resizeObserver=new ResizeObserver(function(entries){container.clientWidth!==self.latestWidth&&(self.latestWidth=container.clientWidth,updateContainer())}),self.resizeObserver.observe(container),updateContainer(),self.cleanup=function(){self.resizeObserver&&(self.resizeObserver.unobserve(container),self.resizeObserver=null);getRelevantElements().forEach(function(item){item.element.classList.remove("hide")});var more=container.querySelector(".fluidHeaderMore");0<options.extraItems.length?more.classList.remove("hide"):more.classList.add("hide")}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["formDialogStyle","css!modules/fluidheader/fluidheader.css"]);_exports.default={fluidify:function(options){if(("object"!=typeof options||options instanceof HTMLElement)&&(options={container:options}),!(options=Object.assign({container:void 0,defaultPriority:1,defaultLTR:!1,collapseTitle:!0,extraItems:[],moreIcon:"more_horiz",moreTitle:"",moreItemIfTitleCollapsed:!0,moreLeft:!1,actionSheetOptions:{}},options)).container)throw new Error("Fluid header requires a container.");var container=options.container;if((container="string"==typeof container?document.querySelector(container):container)instanceof HTMLElement)return new FluidHeader(container,options);throw new Error("The container must be a HTML element.")}}});