(this.webpackJsonpscanapp=this.webpackJsonpscanapp||[]).push([[0],{80:function(e,t,n){},83:function(e,t,n){},94:function(e,t,n){"use strict";n.r(t);var c=n(0),a=n.n(c),s=n(57),r=n.n(s),i=(n(80),n(30)),o=n.n(i),l=n(40),j=n(13),u={base:"https://scanapi.ullstar.de"},d=n(2),b=Object(c.createContext)({}),h=function(e){var t=Object(c.useState)(localStorage.getItem("access_token")),n=Object(j.a)(t,2),a=n[0],s=n[1];Object(c.useEffect)((function(){var e=function(){var e=Object(l.a)(o.a.mark((function e(){var t,n;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+a}},e.next=3,fetch(u.base+"/user",t);case 3:n=e.sent,console.log("after fetch /user",n,a),n.ok||s(null),a&&localStorage.setItem("access_token",a);case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();e()}),[a]);var r=a||void 0;return Object(d.jsx)(b.Provider,{value:{token:r,setToken:s},children:e.children})},p=function(e){var t=e.message;return Object(d.jsx)("p",{className:"has-text-weight-bold has-text-danger",children:t})},x=function(){var e,t,n=Object(c.useState)(""),a=Object(j.a)(n,2),s=a[0],r=a[1],i=Object(c.useState)(""),u=Object(j.a)(i,2),h=u[0],x=u[1],O=Object(c.useState)(""),f=Object(j.a)(O,2),m=f[0],v=f[1],g=null===(e=Object(c.useContext)(b))||void 0===e?void 0:e.setToken,w=null===(t=Object(c.useContext)(b))||void 0===t?void 0:t.token,k=function(){var e=Object(l.a)(o.a.mark((function e(){var t,n,c;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:JSON.stringify("grant_type=&username=".concat(s,"&password=").concat(h,"&scope=&client_id=&client_secret="))},e.next=3,fetch("https://scanapi.ullstar.de/token",t);case 3:return n=e.sent,e.next=6,n.json();case 6:c=e.sent,console.log("fetch done",c,g,w),n.ok?g&&g(c.access_token):v(c.detail);case 9:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return Object(d.jsx)("div",{className:"column",children:Object(d.jsxs)("form",{className:"box",onSubmit:function(e){e.preventDefault(),k()},children:[Object(d.jsx)("h1",{className:"title has-text-centered",children:"Login"}),Object(d.jsxs)("div",{className:"field",children:[Object(d.jsx)("label",{className:"label",children:"Email Address"}),Object(d.jsx)("div",{className:"control",children:Object(d.jsx)("input",{type:"username",placeholder:"Enter email",value:s,onChange:function(e){return r(e.target.value)},className:"input",required:!0})})]}),Object(d.jsxs)("div",{className:"field",children:[Object(d.jsx)("label",{className:"label",children:"Password"}),Object(d.jsx)("div",{className:"control",children:Object(d.jsx)("input",{type:"password",placeholder:"Enter password",value:h,onChange:function(e){return x(e.target.value)},className:"input",required:!0})})]}),Object(d.jsx)(p,{message:m}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{className:"button is-primary",type:"submit",children:"Login"})]})})},O=(n(83),n(129)),f=n(126),m=n(44),v=n.n(m),g=n(132),w=n(135),k=n(134),y=n(133),C=n(128),N=n(125),S=n(136),T=n(130),A=n(131),E=n(65),B=n(127),_=n(138),I=Object(E.a)();function P(){var e,t=Object(c.useState)(0),n=Object(j.a)(t,2),a=n[0],s=n[1],r=Object(c.useState)({pages:[]}),i=Object(j.a)(r,2),o=i[0],l=i[1],h=null===(e=Object(c.useContext)(b))||void 0===e?void 0:e.token;return Object(c.useEffect)((function(){fetch(u.base+"/pagelist",{method:"GET",headers:new Headers({Accept:"application/json",Authorization:"Bearer "+h})}).then((function(e){return e.json()})).then((function(e){console.log(e),l(e)})).catch((function(e){return console.log(e)}))}),[h]),Object(d.jsxs)(B.a,{theme:I,children:[Object(d.jsx)(C.a,{}),Object(d.jsx)(O.a,{position:"relative",children:Object(d.jsxs)(T.a,{children:[Object(d.jsx)(v.a,{sx:{mr:2}}),Object(d.jsx)(A.a,{variant:"h6",color:"inherit",noWrap:!0,children:"Scan App"})]})}),Object(d.jsx)("main",{children:Object(d.jsx)(_.a,{maxWidth:"xl",sx:{display:"flex",flexDirection:"row",alignContent:"center",justifyContent:"center"},children:Object(d.jsx)(N.a,{item:!0,container:!0,spacing:1,paddingTop:2,xs:12,columnSpacing:{xs:1,sm:1,md:1},children:o.pages&&o.pages.map((function(e){return Object(d.jsx)(N.a,{item:!0,sm:4,md:2,children:Object(d.jsxs)(g.a,{onClick:function(e){return s(a+1)},variant:"outlined",sx:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",alignContent:"center",border:"2px dotted darkgray",background:"lightgray"},children:[Object(d.jsx)(y.a,{component:"img",sx:{maxWidth:220,pt:2},image:"https://source.unsplash.com/random",alt:"random"}),Object(d.jsxs)(k.a,{sx:{flexGrow:1},children:[Object(d.jsx)(A.a,{gutterBottom:!0,variant:"h6",component:"h2",children:"Page"}),Object(d.jsx)(A.a,{children:"This is a media card. You can use this section to describe the content."})]}),Object(d.jsxs)(w.a,{children:[Object(d.jsx)(f.a,{size:"small",children:"View"}),Object(d.jsx)(f.a,{size:"small",children:"Edit"})]})]})},e.name)}))})})}),Object(d.jsxs)(S.a,{sx:{bgcolor:"background.paper",p:6},component:"footer",children:[Object(d.jsx)(A.a,{variant:"h6",align:"center",gutterBottom:!0}),Object(d.jsx)(A.a,{variant:"subtitle1",align:"center",color:"text.secondary",component:"p"})]})]})}var z=n(123);function L(){var e,t=null===(e=Object(c.useContext)(b))||void 0===e?void 0:e.token,n=Object(c.useState)({}),a=Object(j.a)(n,2),s=a[0],r=a[1];return Object(c.useEffect)((function(){var e=function(){fetch(u.base+"/wlan",{method:"GET",headers:new Headers({Accept:"application/json",Authorization:"Bearer "+t})}).then((function(e){return e.json()})).then((function(e){r(e)})).catch((function(e){return console.log(e)}))};e();var n=setInterval((function(){e()}),1e3);return function(){return clearInterval(n)}}),[t]),Object(d.jsxs)("div",{children:[Object(d.jsx)(O.a,{position:"relative",children:Object(d.jsxs)(T.a,{children:[Object(d.jsx)(v.a,{sx:{mr:2}}),Object(d.jsx)(A.a,{variant:"h6",color:"inherit",noWrap:!0,children:"WLAN"})]})}),Object(d.jsx)("main",{children:Object(d.jsx)("div",{children:Object.keys(s).sort().map((function(e){return Object(d.jsxs)("div",{children:[s[e].name,Object(d.jsx)(z.a,{checked:s[e].enabled,disabled:s[e].updating,onClick:function(){return n=e,c=!s[e].enabled,void fetch(u.base+"/wlan",{method:"POST",body:JSON.stringify({wifi_name:n,wifi_enable:c}),headers:new Headers({"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+t})}).then((function(e){return e.json()})).then((function(e){r(e)})).catch((function(e){return console.log(e)}));var n,c}})]},e)}))})})]})}var W=n(63),D=n(14);var F=function(){var e,t=null===(e=Object(c.useContext)(b))||void 0===e?void 0:e.token;return Object(d.jsx)(W.a,{children:Object(d.jsx)("div",{className:"App",children:t?Object(d.jsxs)(D.c,{children:[Object(d.jsx)(D.a,{path:"/wifi",children:Object(d.jsx)(L,{})}),Object(d.jsx)(D.a,{path:"/",children:Object(d.jsx)(P,{})})]}):Object(d.jsx)("div",{className:"columns",children:Object(d.jsx)(x,{})})})})},G=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,139)).then((function(t){var n=t.getCLS,c=t.getFID,a=t.getFCP,s=t.getLCP,r=t.getTTFB;n(e),c(e),a(e),s(e),r(e)}))};r.a.render(Object(d.jsx)(a.a.StrictMode,{children:Object(d.jsx)(h,{children:Object(d.jsx)(F,{})})}),document.getElementById("root")),G()}},[[94,1,2]]]); //# sourceMappingURL=main.0bd4034d.chunk.js.map