"use strict";(self.webpackChunk_battleship_client=self.webpackChunk_battleship_client||[]).push([[792],{7550:(e,t,n)=>{n.r(t),n.d(t,{default:()=>a});var r,o=n(4041);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{n.r(t),n.d(t,{default:()=>i});var r=n(4041);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;te.theme.colors.onSurfacePrimary}; background-color: ${e=>e.theme.colors.surfacePrimary}; padding-block: ${e=>e.theme.paddingSm}; @media (max-width: 35em) { padding-block: ${e=>e.theme.paddingMin}; } `,y=a.styled.footer` background-color: ${e=>e.theme.colors.surfacePrimary}; grid-area: footer; height: 10vh; `;t.default=()=>(0,o.jsxs)(m.default,{children:[(0,o.jsx)(s.Helmet,{children:(0,o.jsx)("title",{children:"Battleship"})}),(0,o.jsxs)("div",{className:"App",children:[(0,o.jsx)(i.BrowserRouter,{children:(0,o.jsxs)(g,{children:[(0,o.jsx)(f.default,{}),(0,o.jsx)(v,{children:(0,o.jsxs)(i.Routes,{children:[(0,o.jsx)(i.Route,{index:!0,element:(0,o.jsx)(i.Navigate,{to:"/login",replace:!0})}),(0,o.jsx)(i.Route,{path:"/login",element:(0,o.jsx)(l.default,{})}),(0,o.jsx)(i.Route,{path:"/menu",element:(0,o.jsx)(c.default,{})}),(0,o.jsxs)(i.Route,{path:"/game",element:(0,o.jsx)(d.default,{}),children:[(0,o.jsx)(i.Route,{path:"getReady",element:(0,o.jsx)(u.default,{})}),(0,o.jsx)(i.Route,{path:"play",element:(0,o.jsx)(p.default,{})})]})]})}),(0,o.jsx)(y,{})]})}),(0,o.jsx)(h.default,{})]})]})},9150:function(e,t,n){var r=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o{switch(e.$variant){case"warning":return e.theme.colors.containerWarning;case"danger":return e.theme.colors.containerDanger;default:return e.theme.colors.containerSecondary}}}; --colorContent: ${e=>{switch(e.$variant){case"warning":return e.theme.colors.onContainerWarning;case"danger":return e.theme.colors.onContainerDanger;default:return e.theme.colors.onContainerSecondary}}}; position: relative; width: 100%; display: flex; justify-content: center; align-items: center; background-color: var(--colorBg); color: var(--colorContent); border: ${e=>e.theme.borderStyle}; transition: ${e=>`all ${e.theme.durationTransitionDefault}ms ease-out`}; padding: ${e=>e.theme.paddingMin}; &:hover { filter: invert(10%) saturate(300%); } &:disabled { filter: opacity(60%); } `,c=a.styled.div` position: absolute; width: min-content; `,d=a.styled.div` visibility: ${e=>e.$visible?"visible":"hidden"}; `;t.default=e=>{var{children:t,variant:n="primary",loading:o=!1,style:a={}}=e,u=r(e,["children","variant","loading","style"]);return(0,i.jsxs)(l,Object.assign({$variant:n,style:a},u,{children:[(0,i.jsx)(d,{$visible:!o,children:t}),(0,i.jsx)(c,{children:(0,i.jsx)(s.default,{visible:o})})]}))}},1296:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(1085),l=n(3864),c=i(n(4041)),d=n(1560),u=a(n(1061)),p=a(n(366)),h=n(8450),f=(0,l.styled)(d.animated.div)` width: 100%; border: ${e=>e.theme.borderStyle}; padding: ${e=>e.theme.paddingMin}; overflow: clip; `,m=(0,c.forwardRef)((({label:e,onCollapsedStateChange:t,initialState:n,children:r},o)=>{const i=(0,c.useRef)(null),a=(0,c.useRef)(null),m=(0,c.useRef)(null),g=(0,l.useTheme)(),v=(0,c.useMemo)((()=>({background:g.colors.containerSecondary,color:g.colors.onContainerSecondary})),[g]),y=(0,c.useMemo)((()=>({background:g.colors.containerPrimary,color:g.colors.onContainerPrimary})),[g]),[S,b]=(0,d.useSpring)((()=>({from:"closed"===n?v:y,config:{duration:g.durationTransitionDefault,easing:d.easings.easeOutCubic}})),[g]);(0,c.useEffect)((()=>{var e;"open"===(null===(e=a.current)||void 0===e?void 0:e.getState())?b.start({to:y}):b.start({to:v})}),[g,b,v,y]);const x=(0,c.useCallback)((()=>{var e,t;return null!==(t=null===(e=a.current)||void 0===e?void 0:e.getState())&&void 0!==t?t:n}),[n]),w=(0,c.useCallback)((e=>{var t;null===(t=a.current)||void 0===t||t.setState(e)}),[]),_=(0,c.useCallback)((()=>{var e,t;return null!==(t=null===(e=a.current)||void 0===e?void 0:e.toggleState())&&void 0!==t?t:n}),[n]);(0,c.useImperativeHandle)(o,(()=>({getState:x,setState:w,toggleState:_})));const j=(0,c.useCallback)((e=>{var t;e.target!==i.current&&e.target!==m.current||null===(t=a.current)||void 0===t||t.toggleState()}),[]),C=(0,c.useCallback)((e=>{switch(e){case"open":b.start({to:y});break;case"closed":b.start({to:v});break;default:(0,h.assertNever)(e)}t&&t(e)}),[t,b,v,y]),M=(0,c.useCallback)((()=>{b.start({to:y})}),[b,y]),P=(0,c.useCallback)((()=>{var e;"open"!==(null===(e=a.current)||void 0===e?void 0:e.getState())&&b.start({to:v})}),[b,v]);return(0,s.jsxs)(f,{ref:i,onClick:j,onPointerEnter:M,onPointerLeave:P,style:S,children:[(0,s.jsx)(u.default,{ref:m,children:e}),(0,s.jsx)(p.default,{initialState:n,onCollapsedStateChange:C,ref:a,children:r})]})}));t.default=m},366:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(1085),l=n(3864),c=i(n(4041)),d=n(1560),u=a(n(8829)),p=(0,l.styled)(d.animated.div)` width: 100%; display: flex; justify-content: center; align-items: center; overflow: clip; `,h=(0,c.forwardRef)((({onCollapsedStateChange:e,initialState:t="closed",children:n},r)=>{var o;const i=(0,c.useRef)(null),a=(0,c.useRef)(t),h=null!==(o=(0,c.useContext)(l.ThemeContext))&&void 0!==o?o:u.default,[f,m]=(0,d.useSpring)((()=>{var e;return{from:{height:"closed"===t?"0px":`${null===(e=i.current)||void 0===e?void 0:e.offsetHeight}px`,opacity:"closed"===t?0:1},config:{duration:h.durationTransitionDefault}}})),g=(0,c.useCallback)((()=>a.current),[]),v=(0,c.useCallback)((t=>{var n,r,o,s;t!==a.current&&("open"===a.current?m.start({from:{height:`${null!==(r=null===(n=i.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==r?r:0}px`,opacity:1},to:{height:"0px",opacity:0}}):m.start({from:{height:"0px",opacity:0},to:{height:`${null!==(s=null===(o=i.current)||void 0===o?void 0:o.offsetHeight)&&void 0!==s?s:0}px`,opacity:1}}),a.current=t,e&&e(a.current))}),[e,m]),y=(0,c.useCallback)((()=>(v("open"===a.current?"closed":"open"),a.current)),[v]);return(0,c.useImperativeHandle)(r,(()=>({getState:g,setState:v,toggleState:y}))),(0,s.jsx)(p,{style:f,children:(0,s.jsx)(p,{ref:i,children:n})})}));t.default=h},3137:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},a=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);oe.theme.gameGridLineThickness}; border-color: ${e=>e.theme.colors.shipStroke}; border-style: solid; grid-row: ${e=>e.$row+1} / span 1; grid-column: ${e=>e.$col+1} / span 1; `,u=l.styled.div` --cols: ${e=>e.$cols}; --rows: ${e=>e.$rows}; --thickness: ${e=>e.theme.gameGridLineThickness}; --borderColor: ${e=>e.theme.colors.shipStroke}; display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr); aspect-ratio: 1; background-color: ${e=>e.theme.colors.surfaceSecondary}; border: var(--thickness) solid var(--borderColor); `,p=(0,c.forwardRef)(((e,t)=>{const{columns:n,rows:r,children:o}=e,i=a(e,["columns","rows","children"]),l=(0,c.useMemo)((()=>((e,t)=>{const n=[];for(let r=0;re.theme.paddingMin}; grid-column-gap: ${e=>e.theme.paddingMin}; padding: ${e=>e.theme.paddingMin} 0 0 0; width: 100%; `,p=i.styled.p` grid-area: label; text-align: center; `;t.default=({disabled:e})=>{const t=(0,l.useAppDispatch)(),n=(0,l.useAppSelector)((e=>e.gameRoom.requestStatus.loadingJoinRoom)),[r,i]=(0,a.useState)("");return(0,o.jsxs)(u,{onSubmit:e=>{e.preventDefault(),n||r.length>0&&t((0,c.joinGameRoom)(r))},children:[(0,o.jsx)(s.default,{type:"text",inputMode:"numeric",placeholder:"Room code",style:{gridArea:"code"},value:r,onChange:e=>i(e.target.value),disabled:e}),(0,o.jsx)(p,{children:"Join using an invite code."}),(0,o.jsx)(d.default,{type:"submit",variant:"primary",style:{gridArea:"button"},disabled:e||0===r.length,loading:n,children:(0,o.jsx)("div",{children:"Join"})})]})}},2333:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(8955),l=n(6292),c=r(n(1061)),d=r(n(3697)),u=n(9178),p=r(n(9150)),h=r(n(1296)),f=i.styled.div` display: flex; flex-direction: column; align-items: center; gap: ${e=>e.theme.paddingMin}; min-width: 20rem; width: min(90vw, 20rem); `;t.default=()=>{const e=(0,l.useAppDispatch)(),t=(0,l.useAppSelector)((e=>e.gameRoom.roomID)),n=(0,l.useAppSelector)((e=>e.auth.loginResult)),r=(0,l.useAppSelector)((e=>e.gameRoom.requestStatus.loadingNewRoom)),i=(0,a.useRef)(null),[m,g]=(0,a.useState)("closed");return(null==n?void 0:n.accessToken)?t?(0,o.jsx)(s.Navigate,{to:"/game/getReady",replace:!0}):(0,o.jsxs)(f,{children:[(0,o.jsx)(p.default,{variant:"primary",loading:r,onClick:()=>{var t;r||(null===(t=i.current)||void 0===t||t.setState("closed"),e((0,u.createGameRoom)()))},children:(0,o.jsx)(c.default,{children:"Start a new game"})}),(0,o.jsx)(h.default,{ref:i,label:"Join a game",initialState:"closed",onCollapsedStateChange:e=>g(e),children:(0,o.jsx)(d.default,{disabled:"closed"===m})})]}):(0,o.jsx)(s.Navigate,{to:"/login",replace:!0})}},9309:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(5855),s=n(7269),l=n(6292),c=n(303),d=n(6588),u=n(8450),p=r(n(9150)),h=i.keyframes` from { backdrop-filter: blur(0); } to { backdrop-filter: blur(0.2rem); } `,f=i.keyframes` from { opacity: 0; } to { opacity: 1; } `,m=i.styled.div` position: absolute; left: 0; right: 0; top: 0; bottom: 0; display: flex; justify-content: center; align-items: center; background: hsl(0 0% 100% / 0.1); backdrop-filter: blur(0); animation: ${h} 500ms linear forwards; z-index: 999; `,g=i.styled.div` display: grid; grid-template-areas: "header" "body" "footer"; width: fit-content; border: ${e=>e.theme.borderStyle}; margin: ${e=>e.theme.paddingSm}; color: ${e=>e.theme.colors.onContainerPrimary}; background-color: ${e=>e.theme.colors.containerPrimary}; box-shadow: rgba(0, 0, 0, 0.25) 0px 25px 50px -12px; opacity: 0; animation: ${f} 100ms 400ms linear forwards; `,v=i.styled.div` grid-area: header; padding: ${e=>e.theme.paddingSm}; text-align: center; font-size: 1.5rem; font-weight: 800; `,y=i.styled.div` grid-area: body; padding: ${e=>e.theme.paddingSm}; text-align: center; font-weight: 800; white-space: pre-line; `,S=i.styled.div` grid-area: footer; display: flex; padding: ${e=>e.theme.paddingSm}; gap: ${e=>e.theme.paddingSm}; `;t.default=()=>{const{gameResult:e,opponentName:t}=(0,l.useAppSelector)((e=>e.gameRoom)),n=(0,l.useAppDispatch)();let r="";if(!e||!t)return null;switch(e){case s.GameResult.PlayerWon:r="Congratulations, you won!";break;case s.GameResult.OpponentWon:r=`${t} has won.\nBetter luck next time.`;break;case s.GameResult.OpponentDisconnected:r=`${t} has quit, you win!`;break;default:(0,u.assertNever)(e)}return(0,o.jsx)(m,{children:(0,o.jsxs)(g,{children:[(0,o.jsx)(v,{children:"Game Over"}),(0,o.jsx)(y,{children:r}),(0,o.jsxs)(S,{children:[e!==s.GameResult.OpponentDisconnected&&(0,o.jsx)(p.default,{variant:"primary",onClick:()=>{n((0,a.rematch)());const e={code:d.ClientMessageCode.RoomStatusRequest};n((0,c.sendMessage)(e))},children:"Rematch"}),(0,o.jsx)(p.default,{variant:"warning",onClick:()=>{n((0,a.clearRoom)()),n((0,c.closeWSConnection)())},children:"Exit"})]})]})})}},5762:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},o=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);oe.$owner}; opacity: ${e=>e.$active?1:.5}; transition: opacity 0.5s; `,y=(0,s.styled)(l.animated.div)` grid-column: ${e=>e.$col+1} / span 1; grid-row: ${e=>e.$row+1} / span 1; z-index: 2; `;t.default=({owner:e})=>{var t,n,i,S;const b=(0,p.useAppDispatch)(),x=(0,c.useRef)(null),w=(0,s.useTheme)(),{colors:_}=w,{gameStarted:j,currentPlayer:C}=(0,p.useAppSelector)((e=>e.gameRoom)),M=(0,p.useAppSelector)((t=>{switch(e){case"player":return t.gameRoom.playerName;case"opponent":return t.gameRoom.opponentName;default:return(0,h.assertNever)(e)}})),P=(0,p.useAppSelector)((e=>e.gameRoom.gameSettings)),R=(0,p.useAppSelector)((t=>{if(!(0,u.GameRoomIsReady)(t.gameRoom))return null;switch(e){case"player":return t.gameRoom.playerScore;case"opponent":return t.gameRoom.opponentScore;default:return(0,h.assertNever)(e)}})),O=(0,p.useAppSelector)((t=>{if("player"===e&&t.gameRoom.playerShips)return t.gameRoom.playerShips})),k=(0,c.useMemo)((()=>null==O?void 0:O.filter((e=>void 0===(null==R?void 0:R.sunkenShips.find((t=>t.ship.shipID===e.ship.shipID)))))),[null==R?void 0:R.sunkenShips,O]),$=(0,c.useCallback)((t=>{if("player"===e)return;const n=(0,m.calculateGridPosition)(t,x.current,P);n&&b((0,d.opponentCellClicked)(n))}),[b,P,e]),[T,I]=(0,l.useTransition)(null!==(t=null==R?void 0:R.hitCells)&&void 0!==t?t:[],(()=>({keys:t=>`${e}-hit-${t.x}-${t.y}`,from:{opacity:.5,scale:.66,background:_.hitCellHighlight,zIndex:10},enter:[{opacity:1,scale:1.2,background:_.hitCellHighlight,zIndex:10},{scale:1,background:_.hitCell,zIndex:1}]}))),[D,A]=(0,l.useTransition)(null!==(n=null==R?void 0:R.missedCells)&&void 0!==n?n:[],(()=>({keys:t=>`${e}-miss-${t.x}-${t.y}`,from:{opacity:.5,scale:.66,background:_.missedCell,zIndex:10},enter:[{opacity:1,scale:1.2,zIndex:10},{scale:1,zIndex:1}]}))),[E,N]=(0,l.useTransition)(null!==(i=null==R?void 0:R.inaccessibleCells)&&void 0!==i?i:[],(()=>({keys:t=>`${e}-empty-${t.x}-${t.y}`,from:{opacity:0,scale:.66,background:_.missedCell,zIndex:10},enter:{opacity:1,scale:1,background:_.missedCell,zIndex:1}}))),[G,z]=(0,l.useTransition)(null!==(S=null==R?void 0:R.sunkenShips)&&void 0!==S?S:[],(()=>({keys:t=>`${e}-ship-${t.position.x}-${t.position.y}`,from:{opacity:1,scale:1,background:"transparent",fill:_.shipFill,stroke:_.shipStroke,zIndex:20},enter:()=>e=>r(void 0,void 0,void 0,(function*(){yield e({scale:1.2,fill:_.sunkShipHighlight,stroke:_.sunkShipHighlight}),yield e({scale:1,fill:_.sunkShipFill,stroke:_.sunkShipStroke}),yield e({zIndex:1,background:_.missedCell}),N.start()}))})));(0,c.useEffect)((()=>{I.start()}),[null==R?void 0:R.hitCells]),(0,c.useEffect)((()=>{A.start()}),[null==R?void 0:R.missedCells]),(0,c.useEffect)((()=>{z.start()}),[null==R?void 0:R.sunkenShips]),(0,c.useEffect)((()=>{I.set({background:_.hitCell}),A.set({background:_.missedCell}),z.set({fill:_.sunkShipFill,stroke:_.sunkShipStroke,background:_.missedCell}),N.set({background:_.missedCell})}),[w,_.hitCell,_.missedCell,_.sunkShipFill,_.sunkShipStroke]);const{boardWidth:L,boardHeight:q}=null!=P?P:{boardWidth:10,boardHeight:10},H=j&&C!==M;return(0,a.jsx)(v,{$owner:e,$active:H,children:(0,a.jsxs)(f.default,{ref:x,onClick:$,rows:q,columns:L,children:[G(((e,t)=>{var{fill:n,stroke:r}=e,i=o(e,["fill","stroke"]);return(0,a.jsx)(g.default,{ref:()=>{},col:t.position.x,row:t.position.y,size:t.ship.size,orientation:t.orientation,containerStyle:Object.assign({},i),imageStyle:{fill:n,stroke:r}})})),T(((e,t)=>(0,a.jsx)(y,{style:e,$col:t.x,$row:t.y}))),D(((e,t)=>(0,a.jsx)(y,{style:e,$col:t.x,$row:t.y}))),E(((e,t)=>(0,a.jsx)(y,{style:e,$col:t.x,$row:t.y}))),null==k?void 0:k.map((e=>(0,a.jsx)(g.default,{ref:()=>{},col:e.position.x,row:e.position.y,size:e.ship.size,orientation:e.orientation},e.ship.shipID)))]})})}},3988:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(1560),l=r(n(5721)),c=n(7269),d=n(6292),u=i.styled.div` position: relative; display: grid; grid-template-areas: "timer" "name" "score"; gap: 1em; grid-template-rows: 0.5rem 0.5fr 1fr; justify-items: ${e=>"player"===e.$owner?"end":"start"}; @media (max-width: 60em) { gap: 0.5em; } `,p=i.styled.p` grid-area: name; font-size: x-large; word-wrap: break-word; word-break: break-all; text-overflow: ellipsis; @media (max-width: 60em) { font-size: medium; } `,h=i.styled.div` grid-area: score; display: flex; flex-direction: ${e=>"player"===e.$owner?"row":"row-reverse"}; gap: 0.33em; @media (max-width: 60em) { gap: 0.2em; } `,f=(0,i.styled)(s.animated.div)` width: 1em; height: ${e=>`${e.$ship.size}em`}; @media (max-width: 60em) { width: 0.5em; height: ${e=>e.$ship.size/2+"em"}; } `,m=(e,t)=>({background:e.sunken?t.colors.scoreRed:t.colors.scoreGreen});t.default=({owner:e,username:t})=>{const n=(0,d.useAppSelector)((e=>e.gameRoom)),r=(0,i.useTheme)();let g={hitCells:[],missedCells:[],inaccessibleCells:[],sunkenShips:[]};(0,c.GameRoomIsReady)(n)&&(g="player"===e?n.playerScore:n.opponentScore);const{gameSettings:v,currentPlayer:y}=n,S="player"===e?n.playerName:n.opponentName,b=(0,a.useMemo)((()=>(null==v?void 0:v.availableShips)?((e,t)=>{const n=e.map((e=>Object.assign(Object.assign({},e),{sunken:!1}))).sort(((e,t)=>e.size-t.size));return t.forEach((e=>{const t=n.findIndex((t=>t.shipID===e.ship.shipID));t>=0&&(n[t].sunken=!0)})),n})(v.availableShips,g.sunkenShips):[]),[null==v?void 0:v.availableShips,g.sunkenShips]),[x,w]=(0,s.useTransition)(b,(()=>({keys:e=>`${e.shipID}-${e.sunken?"dead":"alive"}`,from:e=>m(e,r),enter:e=>m(e,r)})),[r]);if((0,a.useEffect)((()=>{w.start(((e,t)=>m(t.item,r)))}),[r,b]),!v)return null;const _=y===S;return(0,o.jsxs)(u,{$owner:e,children:[_&&(0,o.jsx)(l.default,{owner:e}),(0,o.jsx)(p,{$owner:e,children:t}),(0,o.jsx)(h,{$owner:e,children:x(((e,t)=>(0,o.jsx)(f,{style:e,$ship:t})))})]})}},5721:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(1085),o=n(3864),i=n(4041),a=n(1560),s=n(6292),l=(0,o.styled)(a.animated.div)` position: relative; grid-area: timer; height: 100%; width: 100%; background-color: ${e=>"player"===e.$owner?e.theme.colors.scoreGreen:e.theme.colors.scoreRed}; `;t.default=({owner:e})=>{const{gameSettings:t,round:n,gameResult:o}=(0,s.useAppSelector)((e=>e.gameRoom)),[c,d]=(0,a.useSpring)((()=>{var e;return{from:{width:"100%"},to:{width:"0%"},config:{duration:1e3*(null!==(e=null==t?void 0:t.turnDuration)&&void 0!==e?e:0)}}}));return(0,i.useEffect)((()=>{var e;d.start({from:{width:"100%"},to:{width:"0%"},config:{duration:1e3*(null!==(e=null==t?void 0:t.turnDuration)&&void 0!==e?e:0)}})}),[n,null==t?void 0:t.turnDuration,d]),(0,i.useEffect)((()=>{o&&d.pause()}),[o,d]),(0,r.jsx)(l,{$owner:e,style:c})}},7193:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(6292),s=r(n(3988)),l=i.styled.div` grid-area: score; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-column-gap: ${e=>e.theme.paddingSm}; `;t.default=()=>{var e,t;const n=(0,a.useAppSelector)((e=>e.gameRoom));return n.gameStarted?(0,o.jsxs)(l,{children:[(0,o.jsx)(s.default,{owner:"player",username:null!==(e=n.playerName)&&void 0!==e?e:""}),(0,o.jsx)(s.default,{owner:"opponent",username:null!==(t=n.opponentName)&&void 0!==t?t:""})]}):null}},6128:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(8955),s=n(4041),l=r(n(9309)),c=n(6292),d=r(n(5762)),u=r(n(7193)),p=i.styled.div` display: grid; grid-template-areas: "score score" "player opponent"; grid-template-rows: 1fr 5fr; grid-template-columns: 1fr 1fr; grid-row-gap: ${e=>e.theme.paddingSm}; grid-column-gap: ${e=>e.theme.paddingSm}; width: min(60vw, 70rem); @media (max-width: 40rem) { width: 95vw; } @media (max-width: 60rem) { grid-template-areas: ". player ." "score score score" "opponent opponent opponent"; grid-template-rows: none; grid-template-columns: 1fr 2.5fr 1fr; } `;t.default=()=>{const e=(0,c.useAppSelector)((e=>e.gameRoom)),[t,n]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{e.gameResult&&setTimeout((()=>{n(!0)}),2e3)}),[e.gameResult]),e.playerShips?(0,o.jsxs)(p,{children:[(0,o.jsx)(d.default,{owner:"player"}),(0,o.jsx)(u.default,{}),(0,o.jsx)(d.default,{owner:"opponent"}),t&&(0,o.jsx)(l.default,{})]}):(0,o.jsx)(a.Navigate,{to:"/game/getReady",replace:!0})}},5461:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.calculateGridPosition=void 0,t.calculateGridPosition=(e,t,n)=>{if(!t||!n)return;const{clientX:r,clientY:o}=e,{boardWidth:i,boardHeight:a}=n,{left:s,top:l,width:c,height:d}=t.getBoundingClientRect(),u=c/i,p=d/a,h=r-s,f=o-l,m=Math.floor(h/u),g=Math.floor(f/p);return m<0||m>=i||g<0||g>=a?void 0:{x:m,y:g}},t.default={}},2567:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(7225)),s=r(n(2500)),l=r(n(9150)),c=i.styled.div` --tooltip-arrow-size: 12px; --gap: ${e=>e.theme.paddingMin}; position: absolute; display: grid; grid-template-columns: auto 1fr auto; justify-content: space-between; align-items: center; padding: var(--gap); margin-inline: var(--gap); gap: var(--gap); z-index: 9999; transform: translate3d(0, -80%, 0); filter: drop-shadow(${e=>e.theme.boxShadow}); border: ${e=>e.theme.borderStyle}; color: ${e=>e.theme.colors.onContainerWarning}; background-color: ${e=>e.theme.colors.containerWarning}; &:before { content: ""; position: absolute; pointer-events: none; border: solid transparent; border-width: var(--tooltip-arrow-size); border-top-color: inherit; border-right-color: transparent; top: 100%; left: calc(50% - var(--gap)); @media (min-width: 100em) { border-top-color: transparent; border-right-color: inherit; top: calc(50% - var(--gap)); left: calc(-2 * var(--tooltip-arrow-size)); } } @media (min-width: 100em) { transform: translate3d(110%, 100%, 0); } `;t.default=()=>{const{hint:e,nextHint:t}=(0,s.default)();return null===e?null:(0,o.jsxs)(c,{children:[(0,o.jsx)(a.default,{}),(0,o.jsx)("p",{children:e}),(0,o.jsx)(l.default,{onClick:t,children:"Got it"})]})}},4698:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(1487),l=r(n(5592)),c=r(n(1346)),d=i.styled.div` display: grid; grid-template-rows: subgrid; grid-template-columns: subgrid; grid-row-end: ${e=>e.$vertical?`span ${e.$shipSize+1}`:"span 2"}; grid-column-end: ${e=>e.$vertical?"span 2":`span ${e.$shipSize+1}`}; `;t.default=({id:e})=>{const t=(0,a.useRef)(null),n=(0,l.default)({id:e,shipContainerRef:t});if(null===n)return null;const{ship:r,orientation:i,gridPosition:u,listeners:p,containerSpring:h,imageSpring:f}=n,{x:m,y:g}=null!=u?u:{x:-1,y:-1},v=(0,o.jsx)(c.default,{ref:t,listeners:p,containerStyle:h,imageStyle:f,col:m,row:g,orientation:i,size:r.size});return null!==u?v:(0,o.jsxs)(d,{$shipSize:r.size,$vertical:i===s.ShipOrientation.Vertical,children:[(0,o.jsx)("div",{style:{gridArea:"1 / 1 / 1 / -1"}}),(0,o.jsx)("div",{style:{gridArea:"2 / 1 / 2 / 1"}}),v]})}},7777:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(8686),l=r(n(4698)),c=r(n(5308)),d=r(n(3137)),u=r(n(2567)),p=i.styled.div` width: 100%; `,h=i.styled.div` position: relative; display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(8, 1fr); grid-auto-flow: dense; aspect-ratio: 10 / 8; background-color: ${e=>e.theme.colors.surfacePrimary}; `,f=i.styled.div` grid-area: 1 / 10 / span 10 / span 1; `;t.default=()=>{const e=(0,s.useSelector)((({shipPlacement:e})=>e.grid.columns)),t=(0,s.useSelector)((({shipPlacement:e})=>e.grid.rows)),n=(0,s.useSelector)((({shipPlacement:e})=>e.shipStates)),r=(0,a.useRef)(null),i=(0,a.useRef)(null),m=(0,a.useMemo)((()=>({componentContainerRef:r,gridContainerRef:i})),[]);return(0,o.jsx)(c.default.Provider,{value:m,children:(0,o.jsxs)(p,{ref:r,children:[(0,o.jsx)(d.default,{ref:i,columns:e,rows:t,children:n.filter((({position:e})=>null!==e)).map((({ship:e,orientation:t,position:n})=>(0,o.jsx)(l.default,{id:e.shipID},`${e.shipID}-${null==n?void 0:n.x}-${null==n?void 0:n.y}-${t}`)))}),(0,o.jsxs)(h,{children:[n.filter((({position:e})=>null===e)).map((({ship:e,orientation:t})=>(0,o.jsx)(l.default,{id:e.shipID},`${e.shipID}-${t}`))),(0,o.jsx)(f,{}),(0,o.jsx)(u.default,{})]})]})})}},7009:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(8955),a=n(3864),s=r(n(7777)),l=n(6686),c=n(6292),d=r(n(9150)),u=a.styled.div` width: min(90vw, 30rem); display: flex; flex-direction: column; gap: ${e=>e.theme.paddingSm}; `,p=a.styled.div` display: grid; grid-template-columns: 1fr auto; align-items: center; gap: ${e=>e.theme.paddingSm}; `;t.default=()=>{const e=(0,c.useAppDispatch)(),{roomID:t,playerShips:n}=(0,c.useAppSelector)((e=>e.gameRoom)),r=(0,c.useAppSelector)((e=>e.shipPlacement)),a=(0,c.useAppSelector)((e=>e.shipPlacement.nonPlacedIDs.length));return t?n?(0,o.jsx)(i.Navigate,{to:"/game/play",replace:!0}):0===r.shipStates.length?null:(0,o.jsxs)(u,{children:[(0,o.jsxs)(p,{children:[(0,o.jsx)("p",{children:"Place your ships"}),(0,o.jsx)(d.default,{variant:"primary",disabled:a>0,onClick:()=>{e((0,l.submitPlacement)(t))},children:"Start"})]}),(0,o.jsx)(s.default,{})]}):(0,o.jsx)(i.Navigate,{to:"/menu",replace:!0})}},6235:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(1085),o=n(3864),i=n(1560),a=n(1487),s=o.styled.svg` width: 90%; height: 90%; `,l=(0,o.styled)(i.animated.path)` fill: ${e=>e.theme.colors.shipFill}; stroke: ${e=>e.theme.colors.shipStroke}; stroke-width: 1.5; `;t.default=({shipSize:e,shipOrientation:t,pathStyle:n})=>{const o=t===a.ShipOrientation.Vertical,i=((e,t)=>{switch(e){case 2:return t?"M 0 15 V 12 C 0 5 4 2 6 1 Q 10 -1 14 1 C 16 2 20 5 20 12 L 20 30 C 20 40 20 40 15 40 L 5 40 C 0 40 0 40 0 30 Z":"M 25 0 H 28 C 35 -0 38 4 39 6 Q 41 10 39 14 C 38 16 35 20 28 20 L 10 20 C 0 20 0 20 0 15 L 0 5 C 0 0 0 0 10 0 Z";case 3:return t?"M 0 15 V 12 C 0 5 4 2 6 1 Q 10 -1 14 1 C 16 2 20 5 20 12 L 20 50 C 20 60 20 60 15 60 L 5 60 C 0 60 0 60 0 50 Z":"M 45 0 H 48 C 55 0 58 4 59 6 Q 61 10 59 14 C 58 16 55 20 48 20 L 10 20 C 0 20 0 20 0 15 L 0 5 C 0 0 0 0 10 0 Z";case 4:return t?"M 0 20 V 18 C 0 15 0 15 5 6 Q 10 -6 15 6 C 20 15 20 15 20 18 L 20 20 L 20 70 C 20 80 20 80 15 80 L 5 80 C 0 80 0 80 0 70 Z":"M 60 0 H 62 C 65 0 65 0 74 5 Q 86 10 74 15 C 65 20 65 20 62 20 L 60 20 L 10 20 C 0 20 0 20 0 15 L 0 5 C 0 0 0 0 10 0 Z";case 5:return t?"M 0 85 L 2 83 L 2 71 V 50 L 2 48 L 2 34 L 0 32 L 0 22 L 3 19 L 6 0 L 14 0 L 17 19 L 20 22 L 20 98 L 2 100 L 2 100 L 2 95 L 0 93 Z":"M 15 0 L 17 2 L 29 2 H 50 L 52 2 L 66 2 L 68 0 L 78 0 L 81 3 L 100 6 L 100 14 L 81 17 L 78 20 L 2 20 L 0 2 L 0 2 L 5 2 L 7 0 Z";default:return t?"M 0 15 V 7 C 0 5 4 2 6 1 Q 10 -1 14 1 C 16 2 20 5 20 7 L 20 15 C 20 20 20 20 15 20 H 5 C 0 20 0 20 0 15 Z":"M 5 0 H 13 C 15 0 18 4 19 6 Q 21 10 19 14 C 18 16 15 20 13 20 L 5 20 C 0 20 0 20 0 15 V 5 C 0 0 0 0 5 0 Z"}})(e,o),c=((e,t)=>{switch(e){case 2:return t?"-1 -1 22 42":"-1 -1 42 22";case 3:return t?"-1 -1 22 62":"-1 -1 62 22";case 4:return t?"-1 -1 22 82":"-1 -1 82 22";case 5:return t?"-1 -1 22 102":"-1 -1 102 22";default:return"-1 -1 22 22"}})(e,o);return(0,r.jsx)(s,{viewBox:c,preserveAspectRatio:"none",children:(0,r.jsx)(l,{d:i,style:n})})}},1346:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(1560),s=n(4041),l=r(n(6235)),c=n(1487),d=(0,i.styled)(a.animated.div)` touch-action: none; grid-row-start: ${({$row:e})=>e>=0?e+1:"auto"}; grid-row-end: ${({$vertical:e,$size:t})=>e?`span ${t}`:"span 1"}; grid-column-start: ${({$col:e})=>e>=0?`${e+1}`:"auto"}; grid-column-end: ${({$vertical:e,$size:t})=>e?"span 1":`span ${t}`}; display: flex; align-items: center; justify-content: center; `,u=(0,s.forwardRef)((({row:e,col:t,size:n,orientation:r,containerStyle:i,imageStyle:a,listeners:s},u)=>(0,o.jsx)(d,Object.assign({ref:u,style:i},s,{$row:e,$col:t,$size:n,$vertical:r===c.ShipOrientation.Vertical,children:(0,o.jsx)(l.default,{shipSize:n,shipOrientation:r,pathStyle:null!=a?a:{}})}))));t.default=u},7533:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(1085),o=n(3864),i=n(6292),a=o.styled.div` width: min(100%, 30rem); padding: ${e=>e.theme.paddingMin}; border: ${e=>e.theme.borderStyle}; background-color: ${e=>e.theme.colors.containerWarning}; color: ${e=>e.theme.colors.onContainerWarning}; text-align: center; `,s=o.styled.span` font-weight: bolder; `;t.default=()=>{const{inviteCode:e}=(0,i.useAppSelector)((e=>e.gameRoom));return e?(0,r.jsx)(a,{children:(0,r.jsxs)("p",{children:["Game invite code: ",(0,r.jsx)(s,{children:e})]})}):null}},812:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(7269),s=n(6292),l=n(8450),c=r(n(7469)),d=i.styled.div` display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: ${e=>e.theme.paddingMin}; `,u=i.styled.p` text-align: center; `;t.default=()=>{const{opponentStatus:e,opponentName:t}=(0,s.useAppSelector)((e=>e.gameRoom));let n="",r=!1;switch(e){case a.PlayerStatus.Disconnected:n="Waiting for an opponent to connect";break;case a.PlayerStatus.Connected:n=`${null!=t?t:"Opponent"} connected, waiting for them to get ready`;break;case a.PlayerStatus.Ready:n=`${null!=t?t:"Opponent"} ready`,r=!0;break;default:(0,l.assertNever)(e)}return(0,o.jsxs)(d,{children:[(0,o.jsx)(u,{children:n}),(0,o.jsx)(c.default,{visible:!0,success:r})]})}},6825:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(7269),l=n(6292),c=r(n(812)),d=r(n(7533)),u=r(n(366)),p=i.styled.div` display: flex; flex-direction: column; align-items: center; gap: ${e=>e.theme.paddingMin}; `;t.default=()=>{const{inviteCode:e,opponentStatus:t,gameStarted:n,gameResult:r}=(0,l.useAppSelector)((e=>e.gameRoom)),i=(0,a.useRef)(null),h=(0,a.useRef)(null);return(0,a.useEffect)((()=>{var o,a,l,c;if(r||n)return null===(o=i.current)||void 0===o||o.setState("closed"),void(null===(a=h.current)||void 0===a||a.setState("closed"));e&&t===s.PlayerStatus.Disconnected?null===(l=i.current)||void 0===l||l.setState("open"):null===(c=i.current)||void 0===c||c.setState("closed")}),[e,t,r,n]),(0,o.jsxs)(p,{children:[(0,o.jsx)(u.default,{initialState:e?"open":"closed",ref:i,children:(0,o.jsx)(d.default,{})}),(0,o.jsx)(u.default,{initialState:"open",ref:h,children:(0,o.jsx)(c.default,{})})]})}},1113:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(8955),a=n(3864),s=r(n(6825)),l=a.styled.div` display: flex; flex-direction: column; gap: ${e=>e.theme.paddingMin}; width: min-content; `;t.default=()=>(0,o.jsxs)(l,{children:[(0,o.jsx)(s.default,{}),(0,o.jsx)(i.Outlet,{})]})},6972:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(3171)),s=i.styled.div` position: absolute; bottom: 0; height: 100%; width: 100%; opacity: ${e=>e.$opacity}; background-image: ${e=>{return t=e.$color,`url("data:image/svg+xml,${encodeURIComponent((e=>`\n\n \n\n`)(t))}")`;var t}}; background-repeat: repeat-x; background-size: ${e=>e.$width}% ${e=>e.$height}%; animation: ${e=>e.$duration}s ${e=>{return t=e.$width,n=e.$offset,i.keyframes` 0% { background-position: ${n}% bottom; } 100% { background-position: ${t+n}% bottom; } `;var t,n}} infinite linear; `,l=i.styled.nav` position: relative; grid-area: hero; display: flex; align-items: center; justify-content: space-between; background-color: ${e=>e.theme.colors.surfaceTertiary}; isolation: isolate; `;t.default=()=>{const e=(0,i.useTheme)(),t=e.colors.hero,n=e.colors.surfacePrimary;return(0,o.jsxs)(l,{children:[(0,o.jsx)(s,{$color:t,$opacity:.5,$offset:75,$width:500,$height:65,$duration:60}),(0,o.jsx)(s,{$color:t,$opacity:.5,$offset:50,$width:400,$height:60,$duration:60}),(0,o.jsx)(s,{$color:t,$opacity:.5,$offset:25,$width:300,$height:55,$duration:60}),(0,o.jsx)(s,{$color:n,$opacity:1,$offset:0,$width:200,$height:25,$duration:60}),(0,o.jsx)(a.default,{})]})}},3171:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(1085),o=n(3864),i=o.styled.div` width: min(100%, 75rem); margin-inline: auto; padding-block: ${e=>e.theme.paddingMin}; `,a=o.styled.text` font-weight: 900; font-stretch: normal; font-size: 5rem; fill: ${e=>e.theme.colors.heroComplementary}; stroke: ${e=>e.theme.colors.heroComplementary}; stroke-width: 1px; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: none; paint-order: stroke fill markers; user-select: none; `;t.default=()=>(0,r.jsx)(i,{children:(0,r.jsxs)("svg",{viewBox:"0 0 700 100",version:"1.1",id:"svg1",xmlns:"http://www.w3.org/2000/svg",style:{mixBlendMode:"difference"},children:[(0,r.jsx)("defs",{id:"defs1"}),(0,r.jsxs)("g",{id:"layer1",children:[(0,r.jsx)("rect",{width:700,height:100,fill:"none",stroke:"none"}),(0,r.jsx)(a,{x:350,y:50,dominantBaseline:"middle",textAnchor:"middle",id:"text1",children:"Battleship"})]})]})})},839:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=r(n(4435)),l=r(n(2313)),c=r(n(6867)),d=r(n(3886)),u=n(3896),p=r(n(366)),h=i.styled.div` --padding: ${e=>e.theme.paddingMin}; --gap: calc(${e=>e.theme.paddingMin} / 2); --border-style: ${e=>e.theme.borderStyle}; grid-area: theme; position: relative; padding: var(--gap); `,f=i.styled.button` width: min-content; border-radius: 50%; padding: var(--gap); display: flex; background-color: ${e=>e.theme.colors.surfaceTertiary}; color: ${e=>e.theme.colors.onSurfaceTertiary}; &:hover { filter: invert(10%) saturate(300%); } `,m=i.styled.div` position: absolute; top: calc(100% + var(--gap)); z-index: 9999; `,g=i.styled.div` display: flex; flex-direction: column; flex-wrap: nowrap; gap: var(--gap); padding: var(--gap); border: var(--border-style); background-color: ${e=>e.theme.colors.containerPrimary}; color: ${e=>e.theme.colors.onContainerPrimary}; `,v=i.styled.button` --selected-filter: invert(10%) saturate(300%); display: flex; flex-direction: row; align-items: center; background-color: transparent; color: ${e=>e.theme.colors.onContainerPrimary}; filter: ${e=>e.$selected?"var(--selected-filter)":"none"}; &:hover { filter: var(--selected-filter); } `,y=i.styled.div` width: min-content; border: var(--border-style); padding: var(--gap); display: flex; background-color: ${e=>e.theme.colors.containerSecondary}; color: ${e=>e.theme.colors.onContainerSecondary}; `,S=i.styled.p` align-self: stretch; display: flex; align-items: center; padding-inline: var(--padding); width: 100%; border: var(--border-style); border-left: none; background-color: ${e=>e.theme.colors.surfaceTertiary}; color: ${e=>e.theme.colors.onSurfaceTertiary}; `,b=[{option:"light",icon:(0,o.jsx)(c.default,{height:24,width:24}),label:"Light"},{option:"dark",icon:(0,o.jsx)(l.default,{height:24,width:24}),label:"Dark"},{option:"system",icon:(0,o.jsx)(d.default,{height:24,width:24}),label:"System"}];t.default=()=>{const{userPreference:e,setUserPreference:t}=(0,u.useThemePreference)(),n=(0,a.useRef)(null);return(0,o.jsxs)(h,{onClick:()=>{var e;null===(e=n.current)||void 0===e||e.toggleState()},children:[(0,o.jsx)(f,{children:(0,o.jsx)(s.default,{})}),(0,o.jsx)(m,{children:(0,o.jsx)(p.default,{ref:n,children:(0,o.jsx)(g,{children:b.map((({option:n,icon:r,label:i})=>{return(0,o.jsxs)(v,{$selected:n===e,onClick:(a=n,()=>{t(a)}),children:[(0,o.jsx)(y,{children:r}),(0,o.jsx)(S,{children:i})]},n);var a}))})})})]})}},7267:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(2683)),s=r(n(4497)),l=n(6292),c=n(5713),d=i.styled.div` --padding: ${e=>e.theme.paddingMin}; --gap: calc(${e=>e.theme.paddingMin} / 2); grid-area: user; align-self: center; justify-self: end; margin-inline: var(--padding); display: flex; flex-direction: row; align-items: center; gap: var(--gap); font-weight: 900; `,u=i.styled.button` width: min-content; border-radius: 50%; padding: var(--gap); display: flex; background-color: ${e=>e.theme.colors.surfaceTertiary}; color: ${e=>e.theme.colors.onSurfaceTertiary}; &:hover { filter: invert(10%) saturate(300%); } `;t.default=()=>{const e=(0,l.useAppSelector)((e=>e.auth.loginResult)),t=(0,l.useAppDispatch)();return e?(0,o.jsxs)(d,{"data-testid":"container",children:[(0,o.jsx)(s.default,{width:24,height:24,"data-testid":"icon-user"}),e.username,(0,o.jsx)(u,{onClick:()=>{t((0,c.logout)())},"data-testid":"button-logout",children:(0,o.jsx)(a.default,{width:24,height:24})})]}):null}},5268:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(6972)),s=r(n(839)),l=r(n(7267)),c=i.styled.div` grid-area: header; display: grid; grid-template-areas: "theme user" "hero hero"; grid-template-rows: auto auto; grid-template-columns: auto 1fr; background-color: ${e=>e.theme.colors.surfaceTertiary}; color: ${e=>e.theme.colors.onSurfaceTertiary}; `;t.default=()=>(0,o.jsxs)(c,{children:[(0,o.jsx)(s.default,{}),(0,o.jsx)(l.default,{}),(0,o.jsx)(a.default,{})]})},1061:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(3864).styled.p` font-size: large; font-weight: bolder; text-align: center; cursor: default; `;t.default=r},9521:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(1560),a=n(3864),s=n(4041),l=n(7991),c=n(8450),d=r(n(9055)),u=n(6292),p=n(2009),h=(0,a.styled)(i.animated.div)` background-color: ${e=>{switch(e.$type){case l.NotificationType.Info:return e.theme.colors.containerSuccess;case l.NotificationType.Warning:return e.theme.colors.containerWarning;case l.NotificationType.Error:return e.theme.colors.containerDanger;default:return(0,c.assertNever)(e.$type)}}}; color: ${e=>{switch(e.$type){case l.NotificationType.Info:return e.theme.colors.onContainerSuccess;case l.NotificationType.Warning:return e.theme.colors.onContainerWarning;case l.NotificationType.Error:return e.theme.colors.onContainerDanger;default:return(0,c.assertNever)(e.$type)}}}; `,f=(0,a.styled)(h)` border: ${e=>e.theme.borderStyle}; box-shadow: rgba(0, 0, 0, 0.25) 0px 25px 50px -12px; display: grid; grid-template-areas: "life life" "message button"; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; `,m=(0,a.styled)(h)` grid-area: life; width: 100%; height: 0.25rem; filter: invert(20%) saturate(2000%); `,g=a.styled.p` grid-area: message; margin: ${e=>e.theme.paddingMin}; `,v=a.styled.button` grid-area: button; width: 2rem; aspect-ratio: 1; display: flex; background-color: transparent; justify-content: center; align-items: center; margin: ${e=>e.theme.paddingMin}; color: currentColor; `,y=(0,s.forwardRef)((({notification:e},t)=>{var n;const{id:r,type:a,message:s,transientInfo:l}=e,c=(0,u.useAppDispatch)(),h=(0,i.useSpring)({from:{width:"100%"},to:{width:"0%"},config:{duration:null!==(n=null==l?void 0:l.duration)&&void 0!==n?n:0}});return(0,o.jsxs)(f,{$type:a,ref:t,children:[l&&(0,o.jsx)(m,{$type:a,style:h}),(0,o.jsx)(g,{children:s}),(0,o.jsx)(v,{onClick:()=>{c((0,p.dismissNotification)(r))},children:(0,o.jsx)(d.default,{})})]})}));t.default=y},2418:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(1560),s=n(4041),l=n(6292),c=r(n(9521)),d=i.styled.div` position: fixed; bottom: ${e=>e.theme.paddingLg}; left: 0; right: 0; width: min(95vw, 50rem); margin-inline: auto; display: flex; flex-direction: column; z-index: 500; `,u=(0,i.styled)(a.animated.div)` position: relative; overflow: hidden; `;t.default=()=>{const e=(0,i.useTheme)(),t=(0,l.useAppSelector)((e=>e.notification.notifications)),n=(0,s.useMemo)((()=>new WeakMap),[]),r=(0,a.useTransition)(t,{keys:e=>e.id,from:{opacity:0,height:0,marginBottom:"0rem"},enter:t=>r=>{var o,i;return r({opacity:1,height:null!==(i=null===(o=n.get(t))||void 0===o?void 0:o.offsetHeight)&&void 0!==i?i:0,marginBottom:e.paddingMin})},leave:{opacity:0,height:0,marginBottom:"0rem"}});return(0,o.jsx)(d,{children:r(((e,t)=>(0,o.jsx)(u,{style:e,children:(0,o.jsx)(c.default,{ref:e=>{e&&n.set(t,e)},notification:t})})))})}},7469:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(7550)),s=r(n(2821)),l=i.styled.div` opacity: ${e=>e.$visible?1:0}; aspect-ratio: 1; display: flex; justify-content: center; align-items: center; `;t.default=({visible:e,success:t})=>{const n=t?(0,o.jsx)(s.default,{}):(0,o.jsx)(a.default,{});return(0,o.jsx)(l,{$visible:e,"data-testid":"container",children:n})}},4851:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(3864).styled.input` padding: ${e=>e.theme.paddingMin}; border: ${e=>e.theme.borderStyle}; border-color: ${e=>e.theme.colors.containerSecondary}; border-radius: 9999px; &:focus { outline-offset: -2px; } `;t.default=r},3896:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useThemePreference=t.ThemePreferenceContext=void 0;const r=n(4041);t.ThemePreferenceContext=(0,r.createContext)({theme:"light",userPreference:"system",setUserPreference:()=>{}}),t.useThemePreference=()=>(0,r.useContext)(t.ThemePreferenceContext)},741:function(e,t,n){var r,o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(1085),a=n(4041),s=n(3864),l=n(3285),c=o(n(8829)),d=o(n(2114)),u=n(3896),p=o(n(708)),h=window.matchMedia("(prefers-color-scheme: light)"),f=window.matchMedia("(prefers-color-scheme: dark)"),m=f.matches?"dark":"light",g=null!==(r=p.default.getThemePreference())&&void 0!==r?r:"system",v="system"!==g?g:m;t.default=({children:e})=>{const[t,n]=(0,a.useState)(m),[r,o]=(0,a.useState)(g),[y,S]=(0,a.useState)(v),b=(0,a.useCallback)((({matches:e})=>{e&&(n("light"),"system"===r&&S("light"))}),[r]),x=(0,a.useCallback)((({matches:e})=>{e&&(n("dark"),"system"===r&&S("dark"))}),[r]);(0,a.useLayoutEffect)((()=>(h.onchange=b,f.onchange=x,b(h),x(f),()=>{h.onchange=null,f.onchange=null})),[x,b]);const w=(0,a.useCallback)((e=>{p.default.saveThemePreference(e),o(e),S("system"===e?t:e)}),[t]),_=(0,a.useMemo)((()=>({theme:y,userPreference:r,setUserPreference:w})),[y,r,w]),j=(0,a.useMemo)((()=>"dark"===y?d.default:c.default),[y]);return(0,i.jsx)(u.ThemePreferenceContext.Provider,{value:_,children:(0,i.jsxs)(s.ThemeProvider,{theme:j,children:[(0,i.jsxs)(l.Helmet,{children:[(0,i.jsx)("meta",{name:"theme-color",content:j.colors.surfaceTertiary}),(0,i.jsx)("meta",{name:"color-scheme",content:y})]}),e]})})}},4589:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=r(n(4851)),s=r(n(3524)),l=n(6292),c=n(5713),d=r(n(7469)),u=r(n(9150)),p=i.styled.form` width: 100%; display: grid; grid-template-rows: 0.75fr 0.75fr 1fr; grid-template-areas: "username" "status" "button"; grid-row-gap: ${e=>e.theme.paddingMin}; grid-column-gap: ${e=>e.theme.paddingMin}; padding: ${e=>e.theme.paddingMin} 0 0 0; `,h=i.styled.div` grid-area: status; font-size: smaller; display: flex; flex-direction: row; justify-content: space-between; `;t.default=({disabled:e})=>{const{username:t,setUsername:n,checkIsPending:r,message:i,isValid:f}=(0,s.default)("Pick a username or continue and have one picked for you","Good to go!","Username is taken"),m=(0,l.useAppDispatch)(),{loginRequestPending:g}=(0,l.useAppSelector)((e=>e.auth));return(0,o.jsxs)(p,{onSubmit:e=>{e.preventDefault(),0===t.length?m((0,c.guestLogin)(null)):f&&m((0,c.guestLogin)(t))},children:[(0,o.jsx)(a.default,{type:"text",placeholder:"Pick a username?",style:{gridArea:"username"},value:t,onChange:e=>n(e.target.value),disabled:e}),(0,o.jsxs)(h,{children:[(0,o.jsx)("p",{children:i}),(0,o.jsx)(d.default,{visible:r})]}),(0,o.jsx)(u.default,{type:"submit",variant:"primary",style:{gridArea:"button"},disabled:e,loading:g,children:(0,o.jsx)("div",{children:"Continue"})})]})}},4119:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=n(3864),a=n(4041),s=n(8955),l=r(n(4589)),c=n(6292),d=r(n(1296)),u=i.styled.div` display: flex; flex-direction: column; align-items: center; gap: ${e=>e.theme.paddingMin}; min-width: 20rem; width: min(90vw, 20rem); `;t.default=()=>{const e=(0,a.useRef)([]),[t,n]=(0,a.useState)(null),r=(0,c.useAppSelector)((e=>e.auth.loginResult)),i=(0,a.useCallback)(((t,n)=>{n&&(e.current.findIndex((e=>e.key===t))>=0||e.current.push({key:t,collapsible:n}))}),[]),p=(0,a.useCallback)((t=>{e.current.forEach((e=>{e.key!==t&&e.collapsible.setState("closed")})),n(t)}),[]);return(null==r?void 0:r.accessToken)?(0,o.jsx)(s.Navigate,{to:"/menu",replace:!0}):(0,o.jsxs)(u,{children:[(0,o.jsx)(d.default,{label:"Continue as guest",initialState:"closed",ref:e=>i("guest",e),onCollapsedStateChange:e=>"closed"===e?n(null):p("guest"),children:(0,o.jsx)(l.default,{disabled:"guest"!==t})}),(0,o.jsx)(d.default,{label:"Login",initialState:"closed",ref:e=>i("login",e),onCollapsedStateChange:e=>"closed"===e?n(null):p("login"),children:(0,o.jsxs)("form",{children:[(0,o.jsx)("input",{type:"text",placeholder:"Username"}),(0,o.jsx)("input",{type:"password",placeholder:"Password"}),(0,o.jsx)("button",{type:"button",children:"Log in"})]})}),(0,o.jsx)(d.default,{label:"Register",initialState:"closed",ref:e=>i("register",e),onCollapsedStateChange:e=>"closed"===e?n(null):p("register"),children:(0,o.jsxs)("form",{children:[(0,o.jsx)("input",{type:"text",placeholder:"Username"}),(0,o.jsx)("input",{type:"password",placeholder:"Password"}),(0,o.jsx)("button",{type:"button",children:"Log in"})]})})]})}},2114:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(n(8829)),i=Object.assign(Object.assign({},o.default),{boxShadow:"rgba(255, 255, 255, 0.15) 0px 20px 10px",borderStyle:"2px solid #bfbfbf",gameGridLineThickness:"0.1em",colors:Object.assign(Object.assign({},o.default.colors),{hero:"hsl(200, 80%, 15%)",heroComplementary:"hsl(27, 73%, 25%)",surfacePrimary:"hsl(200, 100%, 5%)",surfaceSecondary:"hsl(201, 53%, 16%)",surfaceTertiary:"hsl(231, 60%, 5%)",containerPrimary:"hsl(200, 0%, 20%)",containerSecondary:"hsl(200, 100%, 20%)",containerTertiary:"hsl(250, 73%, 35%)",containerSuccess:"hsl(229, 70%, 25%)",containerWarning:"hsl(50, 70%, 25%)",containerDanger:"hsl(0, 60%, 25%)",surfacePrimaryComp:"hsl(27, 73%, 34%)",onSurfacePrimary:"hsl(200 20% 80%)",onSurfaceSecondary:"#e6e6e6",onSurfaceTertiary:"#bfbfbf",onContainerPrimary:"#bfbfbf",onContainerSecondary:"#e6e6e6",onContainerTertiary:"#FAFAFA",onContainerSuccess:"#e6e6e6",onContainerWarning:"#e6e6e6",onContainerDanger:"#e6e6e6",shipFill:"rgb(107 134 148 / 80%)",shipStroke:"rgb(195 207 214 / 70%)",shipBorderSuccess:"rgb(110 204 51 / 100%)",shipBorderError:"rgb(223 32 32 / 100%)",hitCell:"hsl(27 60% 50% / 70%)",hitCellHighlight:"hsl(50 100% 50% / 80%)",missedCell:"hsl(211 50% 40% / 80%)",sunkShipHighlight:"rgb(255 213 0 / 80%)",sunkShipFill:"rgb(191 64 64 / 60%)",sunkShipStroke:"rgb(54 70 78 / 80%)",scoreGreen:"#1B5E20",scoreRed:"#BF360C"})});t.default=i},8829:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default={paddingMin:"1rem",paddingSm:"2rem",paddingLg:"5rem",durationTransitionDefault:250,dimensionBorderSm:"1px",dimensionBorder:"2px",dimensionIconSize:"2rem",boxShadow:"rgba(0, 0, 0, 0.4) 0px 20px 10px",borderStyle:"2px solid #000000",gameGridLineThickness:"0.1em",colors:{hero:"hsl(200, 100%, 50%)",heroComplementary:"hsl(27, 73%, 34%)",surfacePrimary:"hsl(200, 100%, 90%)",surfaceSecondary:"hsl(201, 53%, 74%)",surfaceTertiary:"hsl(0, 100%, 100%)",containerPrimary:"hsl(0, 100%, 100%)",containerSecondary:"hsl(229, 100%, 90%)",containerTertiary:"hsl(250, 73%, 65%)",containerSuccess:"hsl(229, 100%, 90%)",containerWarning:"hsl(50, 100%, 90%)",containerDanger:"hsl(0, 85%, 85%)",surfacePrimaryComp:"hsl(27, 73%, 34%)",onSurfacePrimary:"#000000",onSurfaceSecondary:"#212121",onSurfaceTertiary:"#424242",onContainerPrimary:"#424242",onContainerSecondary:"#212121",onContainerTertiary:"#FAFAFA",onContainerSuccess:"#212121",onContainerWarning:"#424242",onContainerDanger:"#212121",shipFill:"rgb(143 163 174 / 80%)",shipStroke:"rgb(54 70 78 / 80%)",shipBorderSuccess:"rgb(110 204 51 / 100%)",shipBorderError:"rgb(223 32 32 / 100%)",hitCell:"hsl(27 73% 50% / 70%)",hitCellHighlight:"hsl(50 100% 50% / 80%)",missedCell:"hsl(211 92% 30% / 70%)",sunkShipHighlight:"rgb(255 213 0 / 80%)",sunkShipFill:"rgb(191 64 64 / 60%)",sunkShipStroke:"rgb(54 70 78 / 80%)",scoreGreen:"#388E3C",scoreRed:"#E64A19"}}},1853:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PLACE_SHIPS=t.JOIN_ROOM=t.CREATE_ROOM=t.REGISTERED_LOGIN=t.GUEST_LOGIN=void 0;const r=n(1376);t.GUEST_LOGIN=(0,r.gql)("\n mutation guestLogin($username: String) {\n guestLogin(username: $username) {\n accessToken\n expiresAt\n username\n }\n }\n"),t.REGISTERED_LOGIN=(0,r.gql)("\n mutation registeredLogin($username: String!, $password: String!) {\n registeredLogin(username: $username, password: $password) {\n accessToken\n expiresAt\n username\n }\n }\n"),t.CREATE_ROOM=(0,r.gql)("\n mutation createRoom {\n createRoom {\n roomID\n inviteCode\n wsAuthCode\n }\n }\n"),t.JOIN_ROOM=(0,r.gql)("\n mutation joinRoom($inviteCode: String!) {\n joinRoom(inviteCode: $inviteCode) {\n roomID\n wsAuthCode\n }\n }\n"),t.PLACE_SHIPS=(0,r.gql)("\n mutation placeShips($roomId: ID!, $shipPlacements: [ShipPlacementInput!]!) {\n placeShips(roomID: $roomId, shipPlacements: $shipPlacements) {\n gameRoomStatus {\n currentPlayer\n opponent\n opponentShipsPlaced\n opponentSocketConnected\n player\n playerShipsPlaced\n playerSocketConnected\n }\n placedShips {\n orientation\n ship {\n shipID\n size\n type\n }\n position {\n x\n y\n }\n }\n }\n }\n")},5937:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GET_GAME_SETTINGS=t.CHECK_USERNAME=void 0;const r=n(1376);t.CHECK_USERNAME=(0,r.gql)("\n query checkUsername($username: String!) {\n checkUsername(username: $username) {\n taken\n username\n validationError\n }\n }\n"),t.GET_GAME_SETTINGS=(0,r.gql)("\n query GameSettings($gameId: ID!) {\n gameSettings(gameId: $gameId) {\n boardHeight\n boardWidth\n turnDuration\n availableShips {\n shipID\n size\n type\n }\n }\n}\n")},6616:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(4041);t.default=(e,t)=>{const[n,o]=(0,r.useState)(Array(e.length).fill(null));return(0,r.useEffect)((()=>{var t;const n=()=>{o(e.map((e=>{var t,n;return null!==(n=null===(t=e.current)||void 0===t?void 0:t.getBoundingClientRect())&&void 0!==n?n:null})))};return n(),null===(t=window.visualViewport)||void 0===t||t.addEventListener("resize",n),window.addEventListener("scrollend",n),()=>{var e;null===(e=window.visualViewport)||void 0===e||e.removeEventListener("resize",n),window.removeEventListener("scrollend",n)}}),t),n}},2500:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(4041),i=r(n(708)),a=["Place your ships by dragging them onto the grid.","Double-tap a ship to rotate it."];t.default=()=>{const[e,t]=(0,o.useState)(i.default.hasSeenGameHints()),[n,r]=(0,o.useState)(e?a.length:0),[s,l]=(0,o.useState)(e?null:a[n]);return{hint:s,nextHint:(0,o.useCallback)((()=>{if(e)return;const o=n{Object.defineProperty(t,"__esModule",{value:!0});const r=(0,n(4041).createContext)({componentContainerRef:{current:null},gridContainerRef:{current:null}});t.default=r},5592:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(8686),i=n(4041),a=n(1560),s=n(3864),l=r(n(6616)),c=n(1106),d=n(7243),u=n(9221),p=r(n(5308));t.default=({id:e,shipContainerRef:t})=>{const n=(0,o.useDispatch)(),r=(0,s.useTheme)(),h=(0,o.useSelector)((e=>e.shipPlacement.shipStates)),f=(0,o.useSelector)((({shipPlacement:e})=>e.grid)),m=(0,o.useSelector)((({shipPlacement:t})=>t.shipStates.find((({ship:t})=>t.shipID===e)))),{componentContainerRef:g,gridContainerRef:v}=(0,i.useContext)(p.default),[y,S,b]=(0,l.default)([t,g,v],[f,h]),x=(0,i.useMemo)((()=>({x:0,y:0,scale:1,zIndex:5,filter:"drop-shadow(rgba(0, 0, 0, 0.2) 0px 0px 0px)",cursor:"grab"})),[]),w=(0,i.useMemo)((()=>({stroke:r.colors.shipStroke})),[r.colors.shipStroke]),[_,j]=(0,a.useSpring)((()=>({from:x,config:e=>"zIndex"===e?{duration:0}:{mass:.5,tension:500,friction:15,precision:1e-4}})),[r]),[C,M]=(0,a.useSpring)((()=>({from:w,config:{mass:.5,tension:500,friction:15,precision:1e-4}})),[r,w]);(0,i.useEffect)((()=>{M.start({to:w})}),[M,w]);const P=(0,i.useRef)(null),R=(0,i.useRef)({x:0,y:0}),O=(0,i.useCallback)((e=>{e.currentTarget.setPointerCapture(e.pointerId),P.current=e.pointerId,R.current.x=e.clientX,R.current.y=e.clientY,j.start({to:{scale:1.2,zIndex:1e3,filter:`drop-shadow(${r.boxShadow})`,cursor:"grabbing"}})}),[j,r.boxShadow]),k=(0,i.useCallback)((t=>{if(t.currentTarget.releasePointerCapture(t.pointerId),P.current=null,void 0===m||null===y||null===S||null===b)return;const{dx:r,dy:o}=(0,u.calculateTranslation)(R.current,t,y,S),{gridPosition:i}=(0,u.calculateGridPosition)(f,y,b,r,o);"pointercancel"===t.type&&(i.x=-1,i.y=-1);const a=null!==m.position,s=!(0,u.isWithinGrid)(i,f),l=(0,c.canPlaceShip)(f,m,i);a?l?n((0,d.placeShip)({position:i,shipID:e})):s&&n((0,d.resetShip)(e)):l&&n((0,d.placeShip)({position:i,shipID:e})),j.start({to:x}),M.start({to:w})}),[e,n,m,f,y,S,b,j,x,M,w]),$=(0,i.useCallback)((e=>{if(null===P.current||void 0===m||null===y||null===S||null===b)return;let{dx:t,dy:n}=(0,u.calculateTranslation)(R.current,e,y,S);const{gridPosition:o,dxSnapped:i,dySnapped:a}=(0,u.calculateGridPosition)(f,y,b,t,n);let s=r.colors.shipStroke;(0,u.isWithinGrid)(o,f)&&(t=i,n=a,s=(0,c.canPlaceShip)(f,m,o)?r.colors.shipBorderSuccess:r.colors.shipBorderError),j.start({to:{x:t,y:n}}),M.start({to:{stroke:s}})}),[S,b,f,y,m,j,M,r.colors.shipStroke,r.colors.shipBorderSuccess,r.colors.shipBorderError]),T=(0,i.useCallback)((()=>{n((0,d.rotateShip)(e))}),[n,e]),I=(0,i.useMemo)((()=>({onPointerDown:O,onPointerUp:k,onPointerCancel:k,onPointerMove:$,onDoubleClick:T})),[O,$,k,T]);return void 0===m?null:{ship:m.ship,orientation:m.orientation,gridPosition:m.position,listeners:I,containerSpring:_,imageSpring:C}}},9221:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isWithinGrid=t.calculateGridPosition=t.calculateTranslation=void 0,t.calculateTranslation=(e,t,n,r)=>{let o=t.clientX-e.x,i=t.clientY-e.y;return n.left+or.right&&(o=r.right-n.right),n.top+ir.bottom&&(i=r.bottom-n.bottom),{dx:o,dy:i}},t.calculateGridPosition=(e,t,n,r,o)=>{const i=n.width/e.columns,a=t.left+r-n.left,s=t.top+o-n.top,l={x:Math.round(a/i),y:Math.round(s/i)};return{gridPosition:l,dxSnapped:i*l.x-t.left+n.left,dySnapped:i*l.y-t.top+n.top}},t.isWithinGrid=({x:e,y:t},n)=>e>=0&&e=0&&t{const[r,l]=(0,o.useState)(""),[c,d]=(0,o.useState)(!1),[u,p]=(0,o.useState)(e),[h,f]=(0,o.useState)(!1),[m,{data:g,loading:v}]=(0,a.useLazyQuery)(s.CHECK_USERNAME,{fetchPolicy:"no-cache"}),y=(0,o.useRef)((()=>{m({variables:{username:r}})}));(0,o.useEffect)((()=>{y.current=()=>{m({variables:{username:r}})}}),[m,r]);const S=(0,o.useMemo)((()=>i.default.debounce((()=>{var e;null===(e=y.current)||void 0===e||e.call(y)}),500)),[]);return(0,o.useEffect)((()=>{!1===v&&(d(!1),f(!(null==g?void 0:g.checkUsername.taken)&&!(null==g?void 0:g.checkUsername.validationError)))}),[v,g]),(0,o.useEffect)((()=>{var o;0===r.length?p(e):(null===(o=null==g?void 0:g.checkUsername)||void 0===o?void 0:o.taken)?p(n):(null==g?void 0:g.checkUsername.validationError)?p(g.checkUsername.validationError):v||p(t)}),[g,v,r,e,n,t]),{username:r,setUsername:e=>{l(e),e.length>0&&(d(!0),S())},checkIsPending:c,message:u,isValid:h}}},2749:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1085),i=r(n(4041)),a=r(n(5873)),s=n(8686),l=n(1376),c=r(n(3080)),d=n(6292),u=r(n(1729)),p=r(n(9660)),h=a.default.createRoot(document.getElementById("root")),f=(0,d.setupStore)();p.default.setStore(f);const m=(0,u.default)();p.default.setApolloClient(m),h.render((0,o.jsx)(i.default.StrictMode,{children:(0,o.jsx)(l.ApolloProvider,{client:m,children:(0,o.jsx)(s.Provider,{store:f,children:(0,o.jsx)(c.default,{})})})}))},5713:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.logout=t.checkUsername=t.guestLogin=void 0;const i=n(1690),a=o(n(708)),s=n(1853),l=n(5937),c=o(n(9660)),d=n(2009),u=n(7991),p=n(5855),h=n(303);t.guestLogin=(0,i.createAsyncThunk)("auth/guestLogin",((e,t)=>r(void 0,void 0,void 0,(function*(){var n,r;const o=yield null===(n=c.default.getApolloClient())||void 0===n?void 0:n.mutate({mutation:s.GUEST_LOGIN,fetchPolicy:"no-cache",variables:{username:e}});return(null===(r=null==o?void 0:o.data)||void 0===r?void 0:r.guestLogin)?(t.dispatch((0,d.PushTransientNotification)({type:u.NotificationType.Info,timeoutArg:5e3,message:"Guest login successful"})),o.data.guestLogin):t.rejectWithValue({error:"Guest login unsuccessful"})})))),t.checkUsername=(0,i.createAsyncThunk)("auth/checkUsername",(e=>r(void 0,void 0,void 0,(function*(){var t;return null===(t=c.default.getApolloClient())||void 0===t?void 0:t.query({query:l.CHECK_USERNAME,fetchPolicy:"no-cache",variables:{username:e}})})))),t.logout=(0,i.createAsyncThunk)("auth/logout",((e,t)=>{a.default.clearAccessToken(),t.dispatch((0,p.clearRoom)()),t.dispatch((0,h.closeWSConnection)())}));const f={loginResult:a.default.getAccessToken(),loginRequestPending:!1},m=(0,i.createSlice)({name:"auth",initialState:f,reducers:{},extraReducers:e=>{e.addCase(t.guestLogin.pending,(e=>{e.loginRequestPending=!0})),e.addCase(t.guestLogin.fulfilled,((e,t)=>{var n;e.loginRequestPending=!1,e.loginResult=null!==(n=t.payload)&&void 0!==n?n:null,t.payload&&a.default.saveAccessToken(t.payload)})),e.addCase(t.guestLogin.rejected,(e=>{e.loginRequestPending=!1})),e.addMatcher(t.logout.settled,(()=>({loginResult:null,loginRequestPending:!1})))}});t.default=m.reducer},5855:(e,t,n)=>{var r;Object.defineProperty(t,"__esModule",{value:!0}),t.rematch=t.clearRoom=t.opponentCellClicked=void 0;const o=n(1690),i=n(6588),a=n(7269),s=n(9190),l=n(303),c=n(6686),d=n(9178),u=e=>e.type===d.createGameRoom.fulfilled.type||e.type===d.joinGameRoom.fulfilled.type;t.opponentCellClicked=(0,o.createAsyncThunk)("gameRoom/opponentCellClicked",((e,t)=>{const n=t.getState().gameRoom;if((0,s.canHitOpponentCell)(n,e)){const n={code:i.ClientMessageCode.Shoot,position:{x:e.x,y:e.y}};t.dispatch((0,l.sendMessage)(n))}}));const p=(0,o.createSlice)({name:"activeGame",initialState:Object.assign({},a.initialState),reducers:{clearRoom:()=>a.initialState,rematch:s.processRematchAction},extraReducers:e=>{e.addCase(l.connectionOpened,(e=>{e.playerStatus=a.PlayerStatus.Connected})),e.addCase(l.messageReceived,((e,t)=>{(0,s.processMessageReceived)(e,t)})),e.addCase(c.submitPlacement.fulfilled,((e,t)=>{t.payload&&(e.playerShips=t.payload.placedShips,(0,s.processRoomStatus)(e,t.payload.gameRoomStatus))})),e.addCase(d.fetchGameSettings.pending,(e=>{e.requestStatus.loadingSettings=!0})),e.addCase(d.fetchGameSettings.fulfilled,((e,t)=>{e.requestStatus.loadingSettings=!1,e.gameSettings=t.payload})),e.addCase(d.fetchGameSettings.rejected,(e=>{e.requestStatus.loadingSettings=!1,e.gameSettings=void 0})),e.addCase(d.createGameRoom.pending,(e=>{e.requestStatus.loadingNewRoom=!0})),e.addCase(d.joinGameRoom.pending,(e=>{e.requestStatus.loadingJoinRoom=!0})),e.addCase(d.createGameRoom.rejected,(e=>{e.requestStatus.loadingNewRoom=!1})),e.addCase(d.joinGameRoom.rejected,(e=>{e.requestStatus.loadingJoinRoom=!1})),e.addMatcher(u,((e,t)=>{const{roomID:n,inviteCode:r}=t.payload;e.requestStatus.loadingNewRoom=!1,e.requestStatus.loadingJoinRoom=!1,e.roomID=n,e.inviteCode=r}))}});r=p.actions,t.clearRoom=r.clearRoom,t.rematch=r.rematch,t.default=p.reducer},7269:(e,t)=>{var n,r;Object.defineProperty(t,"__esModule",{value:!0}),t.initialState=t.GameIsFinished=t.GameIsInProgress=t.GameRoomIsReady=t.GameResult=t.PlayerStatus=void 0,function(e){e.Disconnected="Disconnected",e.Connected="Connected",e.Ready="Ready"}(n||(t.PlayerStatus=n={})),function(e){e.PlayerWon="PlayerWon",e.OpponentWon="OpponentWon",e.OpponentDisconnected="OpponentDisconnected"}(r||(t.GameResult=r={})),t.GameRoomIsReady=e=>void 0!==e.roomID&&void 0!==e.gameSettings&&void 0!==e.playerName&&void 0!==e.opponentName&&void 0!==e.currentPlayer&&void 0!==e.playerShips&&e.opponentStatus===n.Ready&&e.playerStatus===n.Ready,t.GameIsInProgress=e=>(0,t.GameRoomIsReady)(e)&&e.gameStarted&&null===e.gameResult,t.GameIsFinished=e=>(0,t.GameRoomIsReady)(e)&&null!==e.gameResult,t.initialState={roomID:void 0,gameSettings:void 0,playerStatus:n.Disconnected,opponentStatus:n.Disconnected,playerName:void 0,opponentName:void 0,currentPlayer:void 0,playerShips:void 0,inviteCode:void 0,gameStarted:!1,round:0,gameResult:null,playerScore:{hitCells:[],missedCells:[],inaccessibleCells:[],sunkenShips:[]},opponentScore:{hitCells:[],missedCells:[],inaccessibleCells:[],sunkenShips:[]},requestStatus:{loadingJoinRoom:!1,loadingNewRoom:!1,loadingSettings:!1}}},9178:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.joinGameRoom=t.createGameRoom=t.fetchGameSettings=void 0;const i=n(1690),a=n(1853),s=n(5937),l=o(n(9660)),c=n(303);t.fetchGameSettings=(0,i.createAsyncThunk)("gameRoom/fetchSettings",((e,t)=>r(void 0,void 0,void 0,(function*(){var n;const r=yield null===(n=l.default.getApolloClient())||void 0===n?void 0:n.query({query:s.GET_GAME_SETTINGS,variables:{gameId:e}});return(null==r?void 0:r.data.gameSettings)||t.rejectWithValue({error:"Error fetching game settings"})})))),t.createGameRoom=(0,i.createAsyncThunk)("gameRoom/create",((e,n)=>r(void 0,void 0,void 0,(function*(){var e,r,o;const i=yield null===(e=l.default.getApolloClient())||void 0===e?void 0:e.mutate({mutation:a.CREATE_ROOM}),{roomID:s,inviteCode:d,wsAuthCode:u}=null!==(o=null===(r=null==i?void 0:i.data)||void 0===r?void 0:r.createRoom)&&void 0!==o?o:{};return s&&d&&u?(n.dispatch((0,c.openWSConnection)({roomID:s,wsAuthCode:u})),n.dispatch((0,t.fetchGameSettings)(s)),{roomID:s,inviteCode:d}):n.rejectWithValue({error:"Error creating game room"})})))),t.joinGameRoom=(0,i.createAsyncThunk)("gameRoom/join",((e,n)=>r(void 0,void 0,void 0,(function*(){var r,o,i;const s=yield null===(r=l.default.getApolloClient())||void 0===r?void 0:r.mutate({mutation:a.JOIN_ROOM,variables:{inviteCode:e}}),{roomID:d,wsAuthCode:u}=null!==(i=null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.joinRoom)&&void 0!==i?i:{};return d&&u?(n.dispatch((0,c.openWSConnection)({roomID:d,wsAuthCode:u})),n.dispatch((0,t.fetchGameSettings)(d)),{roomID:d,inviteCode:void 0}):n.rejectWithValue({error:"Error joining game room"})}))))},9190:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.canHitOpponentCell=t.processRematchAction=t.processMessageReceived=t.processRoomStatus=void 0;const r=n(1487),o=n(6588),i=n(8450),a=n(7269),s=(e,t)=>e.x===t.x&&e.y===t.y,l=({x:e,y:t},{ship:n,position:{x:o,y:a},orientation:s})=>{switch(s){case r.ShipOrientation.Horizontal:return e>=o&&e=a&&t{const{position:{x:o,y:i},hit:a,shipSunk:c,currentPlayer:d}=e;if(t.currentPlayer=d,c){n.sunkenShips.push(c),n.hitCells=n.hitCells.filter((e=>!l(e,c)));let e=((e,t)=>{if(!t)return[];const{ship:n,orientation:o,position:{x:i,y:a}}=e,s=Math.max(0,i-1),c=Math.max(0,a-1),d=o===r.ShipOrientation.Horizontal?Math.min(i+n.size,t.boardWidth-1):Math.min(i+1,t.boardWidth-1),u=o===r.ShipOrientation.Vertical?Math.min(a+n.size,t.boardHeight-1):Math.min(a+1,t.boardHeight-1),p=[];for(let t=s;t<=d;t+=1)for(let n=c;n<=u;n+=1){const r={x:t,y:n};l(r,e)||p.push(r)}return p})(c,t.gameSettings);e=e.filter((e=>!n.missedCells.some((t=>s(t,e)))&&!n.inaccessibleCells.some((t=>s(t,e))))),n.inaccessibleCells=n.inaccessibleCells.concat(e)}else a?n.hitCells.push({x:o,y:i}):n.missedCells.push({x:o,y:i})};t.processRoomStatus=(e,t)=>{var n,r;e.playerName=t.player,e.opponentName=null!==(n=t.opponent)&&void 0!==n?n:void 0,e.currentPlayer=null!==(r=t.currentPlayer)&&void 0!==r?r:void 0,t.playerShipsPlaced&&t.playerSocketConnected&&(e.playerStatus=a.PlayerStatus.Ready),t.opponent&&(e.opponentStatus=a.PlayerStatus.Connected),t.opponent&&t.opponentShipsPlaced&&t.opponentSocketConnected&&(e.opponentStatus=a.PlayerStatus.Ready)},t.processMessageReceived=(e,{payload:n})=>{const{code:r}=n;switch(r){case o.ServerMessageCode.AuthenticatedResponse:break;case o.ServerMessageCode.RoomStatusResponse:(0,t.processRoomStatus)(e,n.roomStatus);break;case o.ServerMessageCode.Error:break;case o.ServerMessageCode.GameStarted:((e,t)=>{e.currentPlayer=t.playsFirst,e.gameStarted=!0})(e,n);break;case o.ServerMessageCode.OpponentMoveResult:case o.ServerMessageCode.OwnMoveResult:((e,t)=>{if(!(0,a.GameRoomIsReady)(e))return;e.round+=1;const{code:n}=t;switch(n){case o.ServerMessageCode.OpponentMoveResult:((e,t)=>{c(t,e,e.playerScore),t.gameWon&&(e.gameResult=a.GameResult.OpponentWon)})(e,t);break;case o.ServerMessageCode.OwnMoveResult:((e,t)=>{c(t,e,e.opponentScore),t.gameWon&&(e.gameResult=a.GameResult.PlayerWon)})(e,t);break;default:(0,i.assertNever)(n)}})(e,n);break;case o.ServerMessageCode.OpponentDisconnected:(e=>{(0,a.GameIsInProgress)(e)?(e.gameResult=a.GameResult.OpponentDisconnected,e.opponentStatus=a.PlayerStatus.Disconnected):Object.assign(e,Object.assign({},a.initialState))})(e);break;default:(0,i.assertNever)(r)}},t.processRematchAction=e=>{(0,a.GameIsInProgress)(e)||(e.playerShips=void 0,e.gameStarted=!1,e.round=0,e.gameResult=null,e.playerScore={hitCells:[],missedCells:[],inaccessibleCells:[],sunkenShips:[]},e.opponentScore={hitCells:[],missedCells:[],inaccessibleCells:[],sunkenShips:[]})},t.canHitOpponentCell=(e,t)=>{if(!(0,a.GameRoomIsReady)(e))return!1;if(e.currentPlayer!==e.playerName)return!1;const{opponentScore:n}=e;return!(n.hitCells.some((e=>s(e,t)))||n.missedCells.some((e=>s(e,t)))||n.sunkenShips.some((e=>l(t,e)))||n.inaccessibleCells.some((e=>s(e,t))))}},3393:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(303),o=n(6588),i=n(7991),a=n(2009),s=n(8450);t.default=({dispatch:e,getState:t})=>n=>l=>{if(r.messageReceived.match(l)){const n=l.payload,{code:r}=n,c=t();switch(r){case o.ServerMessageCode.Error:case o.ServerMessageCode.OpponentMoveResult:case o.ServerMessageCode.OwnMoveResult:case o.ServerMessageCode.RoomStatusResponse:case o.ServerMessageCode.AuthenticatedResponse:break;case o.ServerMessageCode.GameStarted:{const{playerName:t}=c.gameRoom,{playsFirst:r}=n,o=r===t?"Game started - make the first move":`Game started - ${r} makes the first move`;e((0,a.PushTransientNotification)({type:i.NotificationType.Info,message:o,timeoutArg:5e3}));break}case o.ServerMessageCode.OpponentDisconnected:c.gameRoom.gameStarted||e((0,a.PushTransientNotification)({type:i.NotificationType.Warning,message:"The opponent has disconnected",timeoutArg:5e3}));break;default:(0,s.assertNever)(r)}}return n(l)}},2009:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PushTransientNotification=t.PushPermanentNotification=t.dismissNotification=void 0;const r=n(1690),o=n(592);t.dismissNotification=(0,r.createAction)("notification/dismiss"),t.PushPermanentNotification=(0,r.createAsyncThunk)("notification/addPermanent",((e,t)=>{const{message:n,type:r}=e;return{id:t.requestId,type:r,message:n}})),t.PushTransientNotification=(0,r.createAsyncThunk)("notification/addTransient",((e,n)=>{const{message:r,type:o,timeoutArg:i}=e,a=Math.max(5e3,i),s={duration:a,timeoutID:setTimeout((()=>n.dispatch((0,t.dismissNotification)(n.requestId))),a)};return{id:n.requestId,type:o,message:r,transientInfo:s}}));const i=(0,r.createSlice)({name:"notification",initialState:{notifications:[]},reducers:{},extraReducers:e=>{e.addCase(t.PushTransientNotification.fulfilled,((e,t)=>{e.notifications.push(t.payload)})),e.addCase(t.PushPermanentNotification.fulfilled,((e,t)=>{e.notifications.push(t.payload)})),e.addCase(t.dismissNotification,((e,t)=>{(0,o.processRemoveNotification)(e,t)}))}});t.default=i.reducer},7991:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.NotificationType=void 0,function(e){e.Info="Info",e.Warning="Warning",e.Error="Error"}(n||(t.NotificationType=n={}))},592:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.processRemoveNotification=void 0,t.processRemoveNotification=(e,{payload:t})=>{const n=e.notifications.findIndex((e=>e.id===t));n<0||e.notifications.splice(n,1).forEach((e=>{e.transientInfo&&clearTimeout(e.transientInfo.timeoutID)}))},t.default={}},7243:(e,t,n)=>{var r;Object.defineProperty(t,"__esModule",{value:!0}),t.resetShips=t.rotateShip=t.resetShip=t.placeShip=void 0;const o=n(1690),i=n(1106),a=n(9178),s=(0,o.createSlice)({name:"shipPlacement",initialState:{placedIDs:[],nonPlacedIDs:[],shipStates:[],grid:{columns:0,rows:0,cellStates:[]}},reducers:{placeShip:i.processPlaceShipAction,resetShip:i.processResetShipAction,rotateShip:i.processRotateShipAction,resetShips:i.processResetShipsAction},extraReducers:e=>{e.addCase(a.fetchGameSettings.fulfilled,((e,t)=>(0,i.initializeState)(t.payload)))}});r=s.actions,t.placeShip=r.placeShip,t.resetShip=r.resetShip,t.rotateShip=r.rotateShip,t.resetShips=r.resetShips,t.default=s.reducer},6686:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.submitPlacement=void 0;const i=n(1690),a=n(1853),s=o(n(9660)),l=n(7243);t.submitPlacement=(0,i.createAsyncThunk)("shipPlacement/submit",((e,t)=>r(void 0,void 0,void 0,(function*(){var n,r,o;const{shipStates:i}=t.getState().shipPlacement;if(i.some((({position:e})=>null===e)))return t.rejectWithValue({error:"Cannot submit ship placement - not all ships placed"});const{gameSettings:c}=t.getState().gameRoom,d=null===(n=t.getState().auth.loginResult)||void 0===n?void 0:n.username;if(!c||!d)return t.rejectWithValue({error:"Cannot submit ship placement - missing game room state"});const u=i.map((e=>{var t,n,r,o;return{shipID:e.ship.shipID,orientation:e.orientation,position:{x:null!==(n=null===(t=e.position)||void 0===t?void 0:t.x)&&void 0!==n?n:0,y:null!==(o=null===(r=e.position)||void 0===r?void 0:r.y)&&void 0!==o?o:0}}})),p=yield null===(r=s.default.getApolloClient())||void 0===r?void 0:r.mutate({mutation:a.PLACE_SHIPS,variables:{roomId:e,shipPlacements:u}});return(null===(o=null==p?void 0:p.data)||void 0===o?void 0:o.placeShips)?(t.dispatch((0,l.resetShips)()),p.data.placeShips):t.rejectWithValue({error:"Ship placement submission failed"})})))),t.default={}},1106:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.initializeState=t.processResetShipsAction=t.processRotateShipAction=t.processResetShipAction=t.processPlaceShipAction=t.canPlaceShip=void 0;const r=n(1487),o=n(8450),i=(e,t,n)=>Math.max(e,Math.min(n,t));t.canPlaceShip=(e,t,{x:n,y:i},a=t.orientation)=>{const{columns:s,rows:l,cellStates:c}=e,{shipID:d,size:u}=t.ship;let p=0,h=0;switch(a){case r.ShipOrientation.Horizontal:p=1,h=u;break;case r.ShipOrientation.Vertical:p=u,h=1;break;default:(0,o.assertNever)(a)}if(n+h>s||n<0||i+p>l||i<0)return!1;const f=Math.max(0,n-1),m=Math.min(s-1,n+h),g=Math.max(0,i-1),v=Math.min(l-1,i+p);for(let e=g;e<=v;e+=1){const t=c[e];for(let e=f;e<=m;e+=1)if(null!==t[e]&&t[e]!==d)return!1}return!0};const a=({cellStates:e},{x:t,y:n},i,a,s)=>{switch(i){case r.ShipOrientation.Horizontal:{const r=e[n];for(let e=0;e{t.position&&a(e,t.position,t.orientation,t.ship.size,null)},l=(e,t,{x:n,y:r},o=null)=>{const i=e.shipStates[t];i.position&&s(e.grid,i);const l=Object.assign(Object.assign({},i),{position:{x:n,y:r},orientation:null!=o?o:i.orientation});var c,d;e.nonPlacedIDs=e.nonPlacedIDs.filter((e=>e!==l.ship.shipID)),e.placedIDs.findIndex((e=>e===l.ship.shipID))<0&&e.placedIDs.push(l.ship.shipID),e.shipStates[t]=l,c=e.grid,(d=l).position&&a(c,d.position,d.orientation,d.ship.size,d.ship.shipID)};t.processPlaceShipAction=(e,{payload:n})=>{const r=e.shipStates.findIndex((({ship:e})=>e.shipID===n.shipID));if(r<0)return;const o=e.shipStates[r];(0,t.canPlaceShip)(e.grid,o,n.position)&&l(e,r,n.position)},t.processResetShipAction=(e,{payload:t})=>{const n=e.shipStates.findIndex((({ship:e})=>e.shipID===t));n<0||((e,t)=>{const n=e.shipStates[t],r=Object.assign(Object.assign({},n),{position:null});e.placedIDs=e.placedIDs.filter((e=>e!==r.ship.shipID)),e.nonPlacedIDs.findIndex((e=>e===r.ship.shipID))<0&&e.nonPlacedIDs.push(r.ship.shipID),e.shipStates[t]=r,s(e.grid,n)})(e,n)},t.processRotateShipAction=(e,{payload:n})=>{const a=e.shipStates.findIndex((({ship:e})=>e.shipID===n));if(a<0)return;const c=e.shipStates[a],{ship:d,orientation:u,position:p}=c;let h=u;switch(u){case r.ShipOrientation.Horizontal:h=r.ShipOrientation.Vertical;break;case r.ShipOrientation.Vertical:h=r.ShipOrientation.Horizontal;break;default:(0,o.assertNever)(u)}const f={ship:d,orientation:h,position:null};if(p){const{rows:n,columns:m}=e.grid,g=Math.floor(d.size/2),v=Object.assign({},p);switch(u){case r.ShipOrientation.Horizontal:v.x=i(0,v.x+g,m-1),v.y=i(0,v.y-g,n-d.size);break;case r.ShipOrientation.Vertical:v.x=i(0,v.x-g,m-d.size),v.y=i(0,v.y+g,n-1);break;default:(0,o.assertNever)(u)}if((0,t.canPlaceShip)(e.grid,f,v,h))return void l(e,a,v,h);s(e.grid,c)}e.shipStates[a]=f},t.processResetShipsAction=e=>{let t=e.placedIDs.pop();for(;t;)e.nonPlacedIDs.includes(t)||e.nonPlacedIDs.push(t),t=e.placedIDs.pop();e.shipStates.forEach((e=>{e.position=null,e.orientation=r.ShipOrientation.Horizontal})),e.grid.cellStates.forEach((e=>{e.forEach(((t,n)=>{e[n]=null}))}))},t.initializeState=e=>{const t=e.availableShips.map((e=>({ship:e,position:null,orientation:r.ShipOrientation.Horizontal})));t.sort(((e,t)=>t.ship.size-e.ship.size));const n=t.map((e=>e.ship.shipID)),o=new Array(e.boardHeight);for(let t=0;t(0,o.configureStore)({reducer:p,preloadedState:e,middleware:e=>e().concat(c.default,u.default)}),t.useAppDispatch=i.useDispatch,t.useAppSelector=i.useSelector},303:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.messageReceived=t.sendMessage=t.connectionOpened=t.closeWSConnection=t.openWSConnection=void 0;const r=n(1690);t.openWSConnection=(0,r.createAction)("ws/connect"),t.closeWSConnection=(0,r.createAction)("ws/disconnect"),t.connectionOpened=(0,r.createAction)("ws/connected"),t.sendMessage=(0,r.createAction)("ws/sendMessage"),t.messageReceived=(0,r.createAction)("ws/messageReceived")},7152:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(n(1274)),i=n(6588),a=n(303),s=e=>{console.log("socket error",e)},l=e=>{console.log("socket closed",e.reason)};t.default=({dispatch:e,getState:t})=>{let n=null;return r=>c=>{if(a.openWSConnection.match(c)){if(null!==n)return r(c);const d=t().auth.loginResult,u=null==d?void 0:d.username;if(!u)return r(c);const{roomID:p,wsAuthCode:h}=c.payload,f=encodeURIComponent(u);n=((e,t,n)=>{const r={instance:new WebSocket(e),authenticated:!1};return r.instance.onopen=((e,t)=>()=>{t.instance.send(e);const n={code:i.ClientMessageCode.RoomStatusRequest};t.instance.send(JSON.stringify(n))})(t,r),r.instance.onmessage=((e,t)=>n=>{const r=o.default.ParseServerMessage(n.data);r&&(r.code===i.ServerMessageCode.AuthenticatedResponse?(t.authenticated=!0,e((0,a.connectionOpened)())):e((0,a.messageReceived)(r)))})(n,r),r.instance.onerror=s,r.instance.onclose=l,r})(`/ws/game/game/${p}/${f}`,h,e)}else if(a.sendMessage.match(c)){if(!n)return r(c);if(!n.authenticated)return r(c);const{payload:e}=c;n.instance.send(JSON.stringify(e))}else a.closeWSConnection.match(c)&&null!==n&&(n.instance.close(),n=null);return r(c)}}},9660:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0});class r{constructor(){}}n=r,r.instance=void 0,r.setApolloClient=e=>{void 0===n.instance&&(n.instance=new n),n.instance.apolloClient=e},r.getApolloClient=()=>{var e;return null===(e=n.instance)||void 0===e?void 0:e.apolloClient},r.setStore=e=>{void 0===n.instance&&(n.instance=new n),n.instance.store=e},r.getStore=()=>{var e;return null===(e=n.instance)||void 0===e?void 0:e.store},t.default=r},1729:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(1376),i=r(n(9660));t.default=()=>{const e=new o.HttpLink({uri:"/api/"}),t=new o.ApolloLink(((e,t)=>{var n,r,o;const a=null===(o=null===(r=null===(n=i.default.getStore())||void 0===n?void 0:n.getState().auth)||void 0===r?void 0:r.loginResult)||void 0===o?void 0:o.accessToken;return a?(e.setContext((({headers:e={}})=>({headers:Object.assign(Object.assign({},e),{authorization:`Bearer ${a}`})}))),t(e)):t(e)}));return new o.ApolloClient({link:(0,o.concat)(t,e),cache:new o.InMemoryCache,defaultOptions:{mutate:{errorPolicy:"all"},query:{errorPolicy:"all"},watchQuery:{errorPolicy:"all"}}})}},708:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(8450),o="KEY_AUTH_TOKEN",i="KEY_THEME",a="KEY_GAME_HINTS_SEEN";t.default={saveAccessToken:e=>{try{const t=JSON.stringify(e);return localStorage.setItem(o,t),!0}catch(e){return!1}},getAccessToken:()=>{const e=localStorage.getItem(o);if(null===e)return null;let t=null;try{t=JSON.parse(e)}catch(e){return localStorage.removeItem(o),null}if((e=>!!(0,r.isObject)(e)&&"username"in e&&!!(0,r.isString)(e.username)&&"accessToken"in e&&!!(0,r.isString)(e.accessToken)&&"expiresAt"in e&&!!(0,r.isString)(e.expiresAt))(t)){const e=Number.parseInt(t.expiresAt,10)||0;if(Number.isNaN(e))return null;if(e-Date.now()>=36e5)return t}return localStorage.removeItem(o),null},clearAccessToken:()=>{localStorage.removeItem(o)},saveThemePreference:e=>{localStorage.setItem(i,e)},getThemePreference:()=>{const e=localStorage.getItem(i);if("light"===e||"dark"===e||"system"===e)return e},hasSeenGameHints:()=>null!==localStorage.getItem(a),setGameHintsSeen:()=>localStorage.setItem(a,"true")}},1274:(e,t,n)=>{n.r(t),n.d(t,{default:()=>c});var r=n(5250),o=n(8450),i=n(6588),a=n(1487);const s=e=>{const t=e;return r.isInteger(t.x)&&r.isInteger(t.y)},l=e=>{const t=e;if(!s(t.position))return!1;if(!r.isBoolean(t.hit)||!r.isBoolean(t.gameWon))return!1;if(!r.isString(t.currentPlayer))return!1;const{shipSunk:n}=t;return!(void 0!==n&&!(e=>{const t=e;return!!s(t.position)&&!!Object.values(a.ShipOrientation).includes(t.orientation)&&!!(e=>{const t=e;return!!r.isString(t.shipID)&&!!r.isInteger(t.size)&&!!Object.values(a.ShipClassName).includes(t.type)})(t.ship)})(n))},c={ParseClientMessage:e=>{if(!r.isString(e))return;let t=null;try{t=JSON.parse(e)}catch(e){return}if("object"!=typeof t)return;if(!t||!("code"in t))return;if(!Object.values(i.ClientMessageCode).includes(t.code))return;const n=t.code;switch(n){case i.ClientMessageCode.Shoot:return(e=>{const t=e;return!!s(t.position)&&!(!t.code||t.code!==i.ClientMessageCode.Shoot)})(t)?t:void 0;case i.ClientMessageCode.RoomStatusRequest:return{code:n};default:return(0,o.assertNever)(n)}},ParseServerMessage:e=>{if(!r.isString(e))return;let t=null;try{t=JSON.parse(e)}catch(e){return}if(!r.isObject(t))return;if(!("code"in t))return;const n=t.code;if(Object.values(i.ServerMessageCode).includes(n))switch(n){case i.ServerMessageCode.Error:return(e=>{const t=e;return t.code===i.ServerMessageCode.Error&&r.isString(t.message)})(t)?t:void 0;case i.ServerMessageCode.OpponentMoveResult:return(e=>"code"in e&&e.code===i.ServerMessageCode.OpponentMoveResult&&l(e))(t)?t:void 0;case i.ServerMessageCode.OwnMoveResult:return(e=>"code"in e&&e.code===i.ServerMessageCode.OwnMoveResult&&l(e))(t)?t:void 0;case i.ServerMessageCode.RoomStatusResponse:return(e=>{const{code:t,roomStatus:n}=e;return t===i.ServerMessageCode.RoomStatusResponse&&(e=>{const{currentPlayer:t,opponent:n,opponentShipsPlaced:o,opponentSocketConnected:i,player:a,playerShipsPlaced:s,playerSocketConnected:l}=e;return!(t&&!r.isString(t)||n&&!r.isString(n)||!(r.isString(a)&&r.isBoolean(s)&&r.isBoolean(l)&&r.isBoolean(o)&&r.isBoolean(i)))})(n)})(t)?t:void 0;case i.ServerMessageCode.AuthenticatedResponse:return(e=>{const{code:t}=e;return t===i.ServerMessageCode.AuthenticatedResponse})(t)?t:void 0;case i.ServerMessageCode.GameStarted:return(e=>{const{code:t,playsFirst:n}=e;return t===i.ServerMessageCode.GameStarted&&r.isString(n)})(t)?t:void 0;case i.ServerMessageCode.OpponentDisconnected:return(e=>{const{code:t}=e;return t===i.ServerMessageCode.OpponentDisconnected})(t)?t:void 0;default:return(0,o.assertNever)(n)}}}},6588:(e,t,n)=>{var r,o;n.r(t),n.d(t,{ClientMessageCode:()=>r,ServerMessageCode:()=>o}),function(e){e.Shoot="Shoot",e.RoomStatusRequest="RoomStatusRequest"}(r||(r={})),function(e){e.Error="Error",e.OpponentMoveResult="OpponentMoveResult",e.OwnMoveResult="OwnMoveResult",e.RoomStatusResponse="RoomStatusResponse",e.AuthenticatedResponse="AuthenticatedResponse",e.GameStarted="GameStarted",e.OpponentDisconnected="OpponentDisconnected"}(o||(o={}))},1487:(e,t,n)=>{var r,o;n.r(t),n.d(t,{ShipClassName:()=>r,ShipOrientation:()=>o}),function(e){e.Battleship="BATTLESHIP",e.Carrier="CARRIER",e.Cruiser="CRUISER",e.Destroyer="DESTROYER",e.Submarine="SUBMARINE"}(r||(r={})),function(e){e.Horizontal="HORIZONTAL",e.Vertical="VERTICAL"}(o||(o={}))},8450:(e,t,n)=>{n.r(t),n.d(t,{assertNever:()=>s,isInteger:()=>i,isObject:()=>r,isParsableAsInt:()=>a,isString:()=>o});const r=e=>"object"==typeof e,o=e=>"string"==typeof e||e instanceof String,i=e=>"number"==typeof e||e instanceof Number,a=e=>o(e)?!isNaN(parseInt(e)):i(e),s=e=>{throw new Error(`Unhandled discriminated union or enum member: ${JSON.stringify(e)}`)}}},e=>{e.O(0,[96],(()=>e(e.s=2749))),e.O()}]); //# sourceMappingURL=maind38fefc6e6ba0f1c3225.js.map