import PNotify from"./PNotify.js";function data(){return Object.assign({_notice:null,_options:{}},PNotify.modules.History.defaults)}var methods={initModule(t){if(this.set(t),this.get().history){const{_notice:t}=this.get();t.get().destroy&&t.set({destroy:!1})}},beforeOpen(){const{maxInStack:t,_options:e}=this.get();if(t===1/0)return;const i=e.stack;if(!1!==i&&PNotify.notices&&PNotify.notices.length>t){const e="top"===i.push,o=[];let s=0;for(let n=e?0:PNotify.notices.length-1;e?n<PNotify.notices.length:n>=0;e?n++:n--)-1!==["opening","open"].indexOf(PNotify.notices[n].get()._state)&&PNotify.notices[n].get().stack===i&&(s>=t?o.push(PNotify.notices[n]):s++);for(let t=0;t<o.length;t++)o[t].close(!1)}}};function setup(t){t.key="History",t.defaults={history:!0,maxInStack:1/0},t.init=(e=>new t({target:document.body})),t.showLast=(t=>{if(void 0===t&&(t=PNotify.defaultStack),!1===t)return;const e="top"===t.push;let i,o=e?0:PNotify.notices.length-1;do{if(!(i=PNotify.notices[o]))return;o+=e?1:-1}while(i.get().stack!==t||!i.get()._modules.History.get().history||"opening"===i.get()._state||"open"===i.get()._state);i.open()}),t.showAll=(t=>{if(void 0===t&&(t=PNotify.defaultStack),!1!==t)for(let e=0;e<PNotify.notices.length;e++){const i=PNotify.notices[e];!0!==t&&i.get().stack!==t||!i.get()._modules.History.get().history||i.open()}}),PNotify.modules.History=t}function create_main_fragment(t,e){return{c:noop,m:noop,p:noop,d:noop}}function PNotifyHistory(t){init(this,t),this._state=assign(data(),t.data),this._intro=!0,this._fragment=create_main_fragment(this,this._state),t.target&&(this._fragment.c(),this._mount(t.target,t.anchor))}function noop(){}function init(t,e){t._handlers=blankObject(),t._slots=blankObject(),t._bind=e._bind,t._staged={},t.options=e,t.root=e.root||t,t.store=e.store||t.root.store,e.root||(t._beforecreate=[],t._oncreate=[],t._aftercreate=[])}function assign(t,e){for(var i in e)t[i]=e[i];return t}function destroy(t){this.destroy=noop,this.fire("destroy"),this.set=noop,this._fragment.d(!1!==t),this._fragment=null,this._state={}}function get(){return this._state}function fire(t,e){var i=t in this._handlers&&this._handlers[t].slice();if(i)for(var o=0;o<i.length;o+=1){var s=i[o];if(!s.__calling)try{s.__calling=!0,s.call(this,e)}finally{s.__calling=!1}}}function on(t,e){var i=this._handlers[t]||(this._handlers[t]=[]);return i.push(e),{cancel:function(){var t=i.indexOf(e);~t&&i.splice(t,1)}}}function set(t){this._set(assign({},t)),this.root._lock||flush(this.root)}function _set(t){var e=this._state,i={},o=!1;for(var s in t=assign(this._staged,t),this._staged={},t)this._differs(t[s],e[s])&&(i[s]=o=!0);o&&(this._state=assign(assign({},e),t),this._recompute(i,this._state),this._bind&&this._bind(i,this._state),this._fragment&&(this.fire("state",{changed:i,current:this._state,previous:e}),this._fragment.p(i,this._state),this.fire("update",{changed:i,current:this._state,previous:e})))}function _stage(t){assign(this._staged,t)}function _mount(t,e){this._fragment[this._fragment.i?"i":"m"](t,e||null)}function _differs(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function blankObject(){return Object.create(null)}function flush(t){t._lock=!0,callAll(t._beforecreate),callAll(t._oncreate),callAll(t._aftercreate),t._lock=!1}function callAll(t){for(;t&&t.length;)t.shift()()}assign(PNotifyHistory.prototype,{destroy:destroy,get:get,fire:fire,on:on,set:set,_set:_set,_stage:_stage,_mount:_mount,_differs:_differs}),assign(PNotifyHistory.prototype,methods),PNotifyHistory.prototype._recompute=noop,setup(PNotifyHistory);export default PNotifyHistory;
//# sourceMappingURL=PNotifyHistory.js.map