text: import{buildDecafClient as e}from"@decafhub/decaf-client";import n from"js-cookie";import t,{useContext as o,useState as r,useRef as i,useEffect as a}from"react";const l=t.createContext({client:void 0,me:void 0,publicConfig:void 0}),s=()=>o(l);function c(e){const[n,o]=r(),l=i();return a(()=>(l.current&&clearInterval(l.current),l.current=window.setInterval(()=>{fetch(e.basePath+"/version.json?t="+(new Date).getTime()).then(e=>e.json()).then(n=>{n.version&&(o(n.version),e.currentVersion!==n.version&&(null==e.onNewVersion||e.onNewVersion(e.currentVersion,n.version)))}).catch(()=>{console.error("DECAF Error: Can not fetch version information!")})},6e4),()=>{clearInterval(l.current)}),[e]),e.onNewVersion||!n?null:t.createElement("div",null,n!==e.currentVersion&&t.createElement("div",{className:"version-modal"},t.createElement("style",null,"\n.version-modal {\n  background-color: rgba(0, 0, 0, 0.5);\n  position: fixed;\n  top: 0;\n  left: 0;\n  width: 100%;\n  height: 100%;\n  z-index: 9999;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  font-size: 1.4em;\n}\n\n.version-modal-title {\n  text-align: center;\n  padding: 10px 20px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n}\n\n.version-modal-title h2 {\n  font-size: 1.5rem;\n  font-weight: bold;\n  color: white;\n  margin: 0;\n  margin-left: 10px;\n}\n\n.version-modal .version-modal-body {\n  display: flex;\n  flex-direction: column;\n  width: 50%;\n  background-color: #333;\n  border-radius: 5px;\n}\n\n.version-modal .version-modal-content {\n  padding: 5px 20px;\n}\n\n.version-modal .version-modal-footer {\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  width: 100%;\n  padding: 10px;\n  margin-top: 20px;\n}\n.version-modal .reload-btn {\n  background-color: #177ddc;\n  color: white;\n  border: none;\n  width: 150px;\n  padding: 10px;\n  cursor: pointer;\n}\n\n.version-modal .reload-btn:hover {\n  background-color: #095cb5;\n}\n\n.version-modal .cancel-btn {\n  background-color: #333;\n  color: white;\n  border: none;\n  padding: 10px;\n  cursor: pointer;\n}\n\n.version-modal .cancel-btn:hover {\n  background-color: #444;\n}\n"),t.createElement("div",{className:"version-modal-body"},t.createElement("div",{className:"version-modal-title"},t.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"50",height:"50",viewBox:"0 0 24 24",fill:"#00c12c",className:"alert-status-icon"},t.createElement("path",{d:"M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm6.25 8.891l-1.421-1.409-6.105 6.218-3.078-2.937-1.396 1.436 4.5 4.319 7.5-7.627z"})),t.createElement("h2",null,"New Version Available")),t.createElement("div",{className:"version-modal-content"},t.createElement("p",null,"A new version of your app is available. Please reload the page to update to the latest version."),t.createElement("span",null,"New version: ",t.createElement("b",{style:{marginRight:10}},n),"(Current version: ",t.createElement("b",null,e.currentVersion),")")),t.createElement("div",{className:"version-modal-footer"},t.createElement("button",{className:"cancel-btn",onClick:()=>o(void 0)},"Let me finish my work first. I will reload later"),t.createElement("button",{className:"reload-btn",onClick:()=>{window.location.reload()}},"Reload")))))}function d(e){return a(()=>{if(!e.zendeskKey)return;const n=document.createElement("script");return n.src="https://static.zdassets.com/ekr/snippet.js?key="+e.zendeskKey,n.async=!0,n.id="ze-snippet",document.body.appendChild(n),window.zESettings=e.settings||{},()=>{document.body.removeChild(n)}},[e]),null}function m(e){return t.createElement("div",{className:"spinner-wrapper"},t.createElement("style",null,`\n    .spinner-wrapper {\n      display: flex;\n      justify-content: center;\n      align-items: center;\n      height: 100vh;\n      flex-direction: column;\n    }\n    .spinner-text {\n      color: ${e.titleColor||"#255d91"};\n    }\n    .spinner {\n      width: ${e.size||"40px"};\n      height: ${e.size||"40px"};\n      position: relative;\n      margin: 10px auto;\n    }\n\n    .double-bounce1,\n    .double-bounce2 {\n      width: 100%;\n      height: 100%;\n      border-radius: 50%;\n      background-color: ${e.color||"#1890ff"};\n      opacity: 0.6;\n      position: absolute;\n      top: 0;\n      left: 0;\n\n      -webkit-animation: sk-bounce 2s infinite ease-in-out;\n      animation: sk-bounce 2s infinite ease-in-out;\n    }\n\n    .double-bounce2 {\n      -webkit-animation-delay: -1s;\n      animation-delay: -1s;\n    }\n\n    @-webkit-keyframes sk-bounce {\n      0%,\n      100% {\n        -webkit-transform: scale(0);\n      }\n      50% {\n        -webkit-transform: scale(1);\n      }\n    }\n\n    @keyframes sk-bounce {\n      0%,\n      100% {\n        transform: scale(0);\n        -webkit-transform: scale(0);\n      }\n      50% {\n        transform: scale(1);\n        -webkit-transform: scale(1);\n      }\n    }\n  `),t.createElement("div",{className:"spinner"},t.createElement("div",{className:"double-bounce1"}),t.createElement("div",{className:"double-bounce2"})),e.title&&t.createElement("p",{className:"spinner-text"},e.title))}function u(o){var r;const[i,s]=t.useState(void 0),[u,p]=t.useState(void 0),[v,f]=t.useState(void 0),[b,h]=t.useState(!0);function w(){s(void 0),p(void 0),f(void 0),h(!1)}return a(()=>{const t=function(){const t=function(){const e=n.get("ember_simple_auth-session");if(e)try{var t;const n=JSON.parse(e);return null==n||null==(t=n.authenticated)?void 0:t.token}catch(e){return void console.error("Can not parse authentication information!")}}();return t?e("",{token:t}):void 0}();t?Promise.all([t.barista.get("/me/"),t.barista.get("/conf/public/")]).then(([e,n])=>{s(t),p(e.data),f(n.data),h(!1)}).catch(w):w()},[]),b?t.createElement(m,{title:"Please Wait..."}):void 0===i||void 0===u||void 0===v?(window.location.href=`/webapps/waitress/production/?next=${window.location.href}`,null):t.createElement(l.Provider,{value:{client:i,me:u,publicConfig:v}},(null==(r=o.config)?void 0:r.currentVersion)&&t.createElement(c,{basePath:o.config.basePath,currentVersion:o.config.currentVersion,onNewVersion:o.config.onNewVersion}),v.zendesk&&t.createElement(d,{zendeskKey:v.zendesk,settings:{contactForm:{fields:[{id:"name",prefill:{"*":u.fullname}},{id:"email",prefill:{"*":u.email}}]}}}),o.children)}export{u as DecafApp,m as DecafSpinner,d as ZendeskWidget,s as useDecaf};
  //# sourceMappingURL=index.modern.js.map
  