import{c as S,b as k,u as w,a as x,i as f,g as v,d as D,e as H,f as b}from"../index.js";var g={exports:{}},l={exports:{}};(function(d){(function(i){var u=-1,n={onVisible:function(e){var r=n.isSupported();if(!r||!n.hidden())return e(),r;var a=n.change(function(s,t){n.hidden()||(n.unbind(a),e())});return a},change:function(e){if(!n.isSupported())return!1;u+=1;var r=u;return n._callbacks[r]=e,n._listen(),r},unbind:function(e){delete n._callbacks[e]},afterPrerendering:function(e){var r=n.isSupported(),a="prerender";if(!r||a!=n.state())return e(),r;var s=n.change(function(t,o){a!=o&&(n.unbind(s),e())});return s},hidden:function(){return!!(n._doc.hidden||n._doc.webkitHidden)},state:function(){return n._doc.visibilityState||n._doc.webkitVisibilityState||"visible"},isSupported:function(){return n._doc.hidden!==void 0||n._doc.webkitHidden!==void 0},_doc:document||{},_callbacks:{},_change:function(e){var r=n.state();for(var a in n._callbacks)n._callbacks[a].call(n._doc,e,r)},_listen:function(){if(!n._init){var e="visibilitychange";n._doc.webkitVisibilityState&&(e="webkit"+e);var r=function(){n._change.apply(n,arguments)};n._doc.addEventListener?n._doc.addEventListener(e,r):n._doc.attachEvent(e,r),n._init=!0}}};d.exports?d.exports=n:i.Visibility=n})(S)})(l);(function(d){(function(i){var u=-1,n=function(e){return e.every=function(r,a,s){e._time(),s||(s=a,a=null),u+=1;var t=u;return e._timers[t]={visible:r,hidden:a,callback:s},e._run(t,!1),e.isSupported()&&e._listen(),t},e.stop=function(r){return e._timers[r]?(e._stop(r),delete e._timers[r],!0):!1},e._timers={},e._time=function(){e._timed||(e._timed=!0,e._wasHidden=e.hidden(),e.change(function(){e._stopRun(),e._wasHidden=e.hidden()}))},e._run=function(r,a){var s,t=e._timers[r];if(e.hidden()){if(t.hidden===null)return;s=t.hidden}else s=t.visible;var o=function(){t.last=new Date,t.callback.call(i)};if(a){var _=new Date,c=_-t.last;s>c?t.delay=setTimeout(function(){t.id=setInterval(o,s),o()},s-c):(t.id=setInterval(o,s),o())}else t.id=setInterval(o,s)},e._stop=function(r){var a=e._timers[r];clearInterval(a.id),clearTimeout(a.delay),delete a.id,delete a.delay},e._stopRun=function(r){var a=e.hidden(),s=e._wasHidden;if(a&&!s||!a&&s)for(var t in e._timers)e._stop(t),e._run(t,!a)},e};d.exports?d.exports=n(l.exports):n(i.Visibility||l.exports)})(window)})(g);var m=g.exports,L=k(({router:d,store:i})=>{const u=w(i),n=x();u.setUser(),u.setNonces(),n.initSession();const e=()=>{const t=u.getCurrentUserMetaData("wc_pos_assigned_outlets")||[],o=b("id");return t.includes(o)},r=()=>n.isActive&&n.open_last!==u.user.id,a=()=>!n.hasStarted||n.hasEnded||n.isLocked;if(d.beforeEach((t,o)=>{if(o.name==="error-reload-register")return!1;if(!e()){const _=["error-unauthorized","login"];return t.name&&!_.includes(t.name)?{name:"error-unauthorized"}:!0}return a()?t.name!=="login"?{name:"login"}:!0:r()?t.name!=="error-register-in-use"?{name:"error-register-in-use"}:!0:t.name==="dining"&&!f("dining")||t.name==="shipping"&&!f("shipping")||t.name==="refund"&&!f("refunds")||t.name==="coupon"&&!f("coupons")||t.name==="discount"&&!f("discounts")?{name:"error-forbidden",path:t.name}:!0}),n.$subscribe((t,o)=>{o.locked&&d.push({name:"login"})}),v("pos","auto_logout",0)&&m.isSupported()){const t=v("pos","auto_logout")*60*1e3;let o;m.change((_,c)=>{c==="hidden"?o=setTimeout(()=>{D("set_session_lock",{register_id:String(H("id")),lock:"1"}).then(p=>{if(p.ok){const h=p.body;n.initSession(h)}})},t):c==="visible"&&clearTimeout(o)})}});export{L as default};
