(this["webpackJsonpreact-starter-app"]=this["webpackJsonpreact-starter-app"]||[]).push([[0],{135:function(e,t,n){},138:function(e,t,n){},139:function(e,t,n){},140:function(e,t,n){},209:function(e,t,n){},210:function(e,t,n){},211:function(e,t,n){},212:function(e,t,n){},213:function(e,t,n){},214:function(e,t,n){"use strict";n.r(t);var c=n(0),r=n.n(c),i=n(27),a=n.n(i),s=n(221),d=(n(118),n(8)),l=n(45),o=n(14),j=n(22),b=n(51),u=n(18),O=n(46),f=o.useLocalStorage.object("seven:players",[]),x=o.useLocalStorage.number("seven:firstDealer",0),h=o.useLocalStorage.object("seven:bids",[]),p=[1,2,3,4,5,6,7,6,5,4,3,2,1].map((function(e,t){return{id:t,handCount:e,complete:!1}})),m=o.useLocalStorage.object(p),y=function(e){var t=f(),n=Object(u.a)(t,2),c=n[0],r=n[1],i=x(),a=Object(u.a)(i,2),s=a[0],d=a[1];return Object(j.a)(Object(j.a)({},e),{},{players:{list:c,add:function(e){0===c.length&&d(0),r([].concat(Object(b.a)(c),[{id:(c[c.length-1]||{id:-1}).id+1,name:e}]))},remove:function(e){return function(){r(c.filter((function(t){return t.id!==e}))),s===e&&d((c.filter((function(t){return t.id!==e}))[0]||{id:-1}).id)}},clear:function(){r([])}}})},g=function(e,t,n){return(e+t)%n},v=function(e){var t=x(),n=Object(u.a)(t,2),c=n[0],r=n[1],i=f(),a=Object(u.a)(i,1)[0];return Object(j.a)(Object(j.a)({},e),{},{dealer:{first:c,current:function(e){return g(c,e,a.length)},set:function(e){return function(){r(e)}}}})},I=function(e){var t=h(),n=Object(u.a)(t,2),c=n[0],r=n[1];return Object(j.a)(Object(j.a)({},e),{},{bids:{clear:function(){r([])},get:{byRound:function(e){return c.filter((function(t){return t.roundId===e}))},byPlayer:function(e){return c.filter((function(t){return t.playerId===e}))},one:function(e,t){return Object(O.first)(c.filter((function(n){return n.roundId===e&&n.playerId===t})))||{roundId:e,playerId:t,bid:void 0}}},set:function(e,t){return function(n){return r([].concat(Object(b.a)(c.filter((function(n){return n.roundId!==e||n.playerId!==t}))),[{roundId:e,playerId:t,bid:n}]))}},win:function(e,t){return function(){r(c.map((function(n){return n.roundId===e&&n.playerId===t?Object(j.a)(Object(j.a)({},n),{},{won:!0}):n})))}},lose:function(e,t){return function(){r(c.map((function(n){return n.roundId===e&&n.playerId===t?Object(j.a)(Object(j.a)({},n),{},{won:!1}):n})))}}}})},w=n(230),C=n(231),k=n(226),N=n(227),S=n(232),P=n(222),A=n(224),B=n(217),F=n(225),L=n(220),T=n(218),D=n(39),G=(n(135),n(4)),z=Object(o.inject)(Object(o.mergeProps)(y,v))((function(e){var t=Object(c.useState)(""),n=Object(u.a)(t,2),r=n[0],i=n[1],a=function(){e.players.add(r),i("")},s=Object(d.f)(),l=-1===e.dealer.first||e.players.list.length<2;return Object(G.jsxs)(P.a,{className:"new-game-form",children:[Object(G.jsx)(A.a,{xs:24,className:"page-title",children:Object(G.jsxs)("em",{children:[Object(G.jsx)(w.a,{})," New Game"]})}),Object(G.jsx)(B.a,{}),e.players.list.map((function(t){return Object(G.jsxs)(A.a,{xs:24,children:[t.name,Object(G.jsx)(C.a,{style:{float:"right"},onClick:e.players.remove(t.id)}),e.dealer.first===t.id&&Object(G.jsxs)(F.a,{color:"green",style:{float:"right"},children:[Object(G.jsx)(k.a,{})," First dealer"]}),e.dealer.first!==t.id&&Object(G.jsx)(F.a,{onClick:e.dealer.set(t.id),style:{float:"right"},children:"Deal first"})]},t.id)})),Object(G.jsxs)(A.a,{xs:24,children:[e.players.list.length<7&&Object(G.jsx)(L.a,{onChange:function(e){i(e.currentTarget.value)},value:r,placeholder:"New player",onPressEnter:a,addonAfter:Object(G.jsx)(N.a,{onClick:a})}),7===e.players.list.length&&Object(G.jsx)(T.a,{type:"info",message:"The game is full"})]}),Object(G.jsx)(A.a,{xs:24,className:"start-btn-container",children:Object(G.jsxs)(D.a,{type:"primary",size:"large",onClick:function(){s("/overview")},disabled:l,children:[Object(G.jsx)(S.a,{})," Start game"]})})]})})),E=n(233),J=n(234),R=n(235),H=n(223),M=n(71),U=(n(138),Object(o.inject)(Object(o.mergeProps)((function(e){return e})))((function(e){return e.bid&&"undefined"!==typeof e.bid.bid&&e.bid.bid>=0?e.bid.won?Object(G.jsx)("span",{style:{color:"#00aa00"},children:Object(G.jsx)("b",{children:e.bid.bid+10})}):Object(G.jsx)("span",{style:{color:"#aa0000"},children:Object(G.jsx)(M.a,{})}):Object(G.jsx)(G.Fragment,{})}))),q=(n(139),Object(o.inject)(Object(o.mergeProps)(I))((function(e){var t=e.bids.get.byPlayer(e.playerId).filter((function(e){return e.won||!1})).map((function(e){return e.bid||0})).reduce((function(e,t){return e+t+10}),0);return Object(G.jsx)(G.Fragment,{children:t})}))),K=(n(140),Object(o.inject)(Object(o.mergeProps)(v,y,(function(e){var t=m(),n=Object(u.a)(t,2),c=n[0],r=n[1];return Object(j.a)(Object(j.a)({},e),{},{rounds:{list:c,complete:function(e){return function(){r(c.splice(e,1,Object(j.a)(Object(j.a)({},c[e]),{},{complete:!0})))}},clear:function(){r(p)}}})}),I))((function(e){var t={textAlign:"center",width:"".concat(100/(e.players.list.length+2),"%")},n=Object(d.f)(),c=function(e){return function(){n("/set-bids/".concat(e))}};return Object(G.jsx)(P.a,{children:Object(G.jsxs)(A.a,{children:[Object(G.jsx)("div",{className:"ant-table ant-table-default",children:Object(G.jsx)("div",{className:"ant-table-content",children:Object(G.jsx)("div",{className:"ant-table-body",children:Object(G.jsxs)("table",{className:"overview",children:[Object(G.jsx)("thead",{className:"ant-table-thead",children:Object(G.jsxs)("tr",{children:[Object(G.jsx)("th",{style:t}),e.players.list.map((function(e){return Object(G.jsx)("th",{className:"overview-player-header",style:t,children:Object(G.jsx)("div",{className:"overview-player-label",children:e.name})},e.id)})),Object(G.jsx)("th",{style:t})]})}),Object(G.jsx)("tbody",{className:"ant-table-body",children:e.rounds.list.map((function(n){return Object(G.jsxs)("tr",{className:"ant-table-row",children:[Object(G.jsx)("td",{style:t,children:Object(G.jsx)("b",{children:n.handCount})}),e.players.list.map((function(c){return Object(G.jsx)("td",{style:t,children:Object(G.jsx)(U,{bid:e.bids.get.one(n.id,c.id)})},c.id)})),Object(G.jsx)("td",{style:t,children:n.complete?Object(G.jsx)(E.a,{color:"#00aa00",onClick:c(n.id)}):Object(G.jsx)(J.a,{onClick:c(n.id)})})]},n.id)}))}),Object(G.jsx)("tfoot",{className:"ant-table-tfoot",children:Object(G.jsxs)("tr",{children:[Object(G.jsx)("th",{style:t}),e.players.list.map((function(e){return Object(G.jsx)("th",{className:"overview-player-footer",style:t,children:Object(G.jsx)(q,{playerId:e.id})},e.id)})),Object(G.jsx)("th",{style:t})]})})]})})})}),Object(G.jsx)(H.a,{onConfirm:function(){e.players.clear(),e.rounds.clear(),e.bids.clear(),n("/")},title:"Are you sure you want to start a new game?",okText:"Start a new game",cancelText:"Continue this game",children:Object(G.jsxs)(D.a,{style:{display:"block",width:"50%",margin:"auto"},children:[Object(G.jsx)(R.a,{})," New game"]})})]})})}))),Q=n(59),V=n(228),W=n(236),X=n(237),Y=n(229),Z=n(238),$=n(219),_=(n(209),Object(o.inject)(Object(o.mergeProps)(I))((function(e){var t;return Object(G.jsxs)(F.a,{color:!0===(null===(t=e.bids.get.one(e.roundId,e.playerId))||void 0===t?void 0:t.won)?"green":void 0,onClick:e.bids.win(e.roundId,e.playerId),children:["Got my ",e.bid]})}))),ee=(n(210),Object(o.inject)(Object(o.mergeProps)(I))((function(e){var t;return Object(G.jsx)(F.a,{color:!1===(null===(t=e.bids.get.one(e.roundId,e.playerId))||void 0===t?void 0:t.won)?"red":void 0,onClick:e.bids.lose(e.roundId,e.playerId),children:"Got screwed"})}))),te=(n(211),function(e,t,n){for(var c=Object(Q.a)({},-1,""),r=0;r<=e;r++)c[r]=t&&r===n?{label:"".concat(r),style:{color:"#ff0000"}}:"".concat(r);return c}),ne=Object(o.inject)(Object(o.mergeProps)((function(e){var t=m(),n=Object(u.a)(t,1)[0],c=h(),r=Object(u.a)(c,1)[0],i=f(),a=Object(u.a)(i,1)[0],s=x(),l=Object(u.a)(s,1)[0],o=Object(d.g)(),b=o.roundId?+o.roundId:-1,p=Object(O.first)(n.filter((function(e){return e.id===b})))||{id:-1,handCount:1,complete:!1},y=r.filter((function(e){return e.roundId===b&&"undefined"!==typeof e.won})).length===a.length,v=r.filter((function(e){return e.roundId===b&&"undefined"!==typeof e.bid&&e.bid>=0})).length===a.length,I=p.handCount-r.filter((function(e){return e.roundId===b&&"number"===typeof e.bid&&e.bid>=0&&e.playerId!==g(l,b,a.length)})).map((function(e){return e.bid||0})).reduce((function(e,t){return e+t}),0);return Object(j.a)(Object(j.a)({},e),{},{round:{current:p,canStart:y,canFinish:v,dealerCantBid:I}})}),y,v,I))((function(e){for(var t=r.a.useState(!1),n=Object(u.a)(t,2),c=n[0],i=n[1],a=e.round.current,s=Object(b.a)(e.players.list);s[s.length-1].id!==e.dealer.current(a.id);)s=s.slice(1).concat(s[0]);var l=e.dealer.current(a.id),o=Object(d.f)();return Object(G.jsx)("div",{className:"set-bids",children:!!e.round&&Object(G.jsxs)(P.a,{children:[Object(G.jsx)(A.a,{xs:24,children:Object(G.jsxs)("b",{children:["Round ",a.id+1," (",a.handCount," ",a.handCount>1?"hands":"hand",")"]})}),Object(G.jsx)(B.a,{}),s.map((function(t,n){var r;return Object(G.jsxs)(A.a,{xs:24,children:[t.name,"\xa0",0===n&&Object(G.jsx)(F.a,{color:"green",children:"Leads"}),t.id===l&&Object(G.jsxs)(G.Fragment,{children:[Object(G.jsx)(F.a,{color:"green",children:"Dealer"}),e.round.dealerCantBid>=0&&!c&&Object(G.jsxs)(F.a,{color:"red",children:["Can't bid ",e.round.dealerCantBid]})]}),c&&Object(G.jsxs)("div",{style:{float:"right"},children:[Object(G.jsx)(_,{roundId:a.id,playerId:t.id,bid:null===(r=e.bids.get.one(a.id,t.id))||void 0===r?void 0:r.bid}),Object(G.jsx)(ee,{roundId:a.id,playerId:t.id})]}),Object(G.jsx)("div",{style:{marginBottom:c?"16px":"32px"},children:!c&&Object(G.jsx)($.a,{disabled:c,min:-1,max:a.handCount,marks:te(a.handCount,t.id===l,e.round.dealerCantBid),step:1,value:e.bids.get.one(a.id,t.id).bid,onChange:e.bids.set(a.id,t.id)})}),Object(G.jsx)(B.a,{})]},t.id)})),Object(G.jsx)(A.a,{xs:6,children:a.id>0&&Object(G.jsx)(D.a,{onClick:function(){o("/set-bids/".concat(a.id-1))},title:"Previous round",children:Object(G.jsx)(V.a,{})})}),Object(G.jsxs)(A.a,{xs:12,className:"lock-btn-container",children:[!c&&Object(G.jsxs)(D.a,{onClick:function(){i(!0)},children:[Object(G.jsx)(W.a,{})," Lock bids"]}),c&&Object(G.jsxs)(D.a,{onClick:function(){i(!1)},children:[Object(G.jsx)(X.a,{})," Unlock bids"]})]}),Object(G.jsx)(A.a,{xs:6,children:Object(G.jsx)("div",{style:{textAlign:"right"},children:a.id<12&&Object(G.jsx)(D.a,{disabled:!e.round.canFinish,onClick:function(){i(!1),o("/set-bids/".concat(a.id+1))},title:"Next round",children:Object(G.jsx)(Y.a,{})})})}),Object(G.jsx)(A.a,{xs:24,style:{textAlign:"center",marginTop:"16px"},children:Object(G.jsxs)(D.a,{onClick:function(){o("/overview")},children:[Object(G.jsx)(Z.a,{})," Back to overview"]})})]})})})),ce=(n(212),function(){return Object(G.jsxs)(s.a,{className:"app",children:[Object(G.jsx)(s.a.Header,{children:Object(G.jsx)("ul",{className:"ant-menu ant-menu-horizontal ant-menu-dark",children:Object(G.jsx)("li",{className:"ant-menu-item",children:"Andy's Awesome Seven Scoring App"})})}),Object(G.jsx)(s.a.Content,{children:Object(G.jsx)(l.a,{children:Object(G.jsxs)(d.c,{children:[Object(G.jsx)(d.a,{path:"/",element:Object(G.jsx)(z,{})}),Object(G.jsx)(d.a,{path:"/overview",element:Object(G.jsx)(K,{})}),Object(G.jsx)(d.a,{path:"/set-bids/:roundId",element:Object(G.jsx)(ne,{})})]})})})]})});n(213);a.a.render(Object(G.jsx)(r.a.StrictMode,{children:Object(G.jsx)(ce,{})}),document.getElementById("root"))}},[[214,1,2]]]); //# sourceMappingURL=main.346071f6.chunk.js.map