UNPKG

ocearo-ui

Version:

Ocean Robot UI: Sailing made smarter

1 lines 3.04 kB
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[610],{48610:function(e,t,l){l.r(t);var i=l(57437),n=l(53082),s=l(2265);let a={MIN:10,MAX:90},o={RISING:{BACKGROUND:"bg-oGreen",TEXT:"text-oGreen"},FALLING:{BACKGROUND:"bg-oYellow",TEXT:"text-oYellow"}},c={NIGHT:"text-oNight",DAY:"text-white"};t.default=()=>{let{nightMode:e,getSignalKValue:t}=(0,n.yC)(),[l,r]=(0,s.useState)(240),[m,u]=(0,s.useState)({level:null,high:null,low:null,timeLow:null,timeHigh:null,coefficient:null,isRising:null}),d=(0,s.useCallback)(e=>{if(!e)return null;let[t,l]=e.split(":").map(Number);return 60*t+l},[]),h=(0,s.useCallback)((e,t,l)=>{let i=d(e),n=d(t),s=d(l);return!!i&&!!n&&!!s&&(n<s?i>=n&&i<=s:i>=n||i<=s)},[d]),x=(0,s.useCallback)((e,t,l)=>l<=t||!e?0:Math.min(100,Math.max(0,(e-t)/(l-t)*100)),[]);(0,s.useEffect)(()=>{let e=()=>{let e=window.innerHeight;r(e<640?Math.min(.25*e,240):Math.min(.35*e,240))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,s.useEffect)(()=>{let e=new Date().toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1}),l={level:t("environment.tide.heightNow"),high:t("environment.tide.heightHigh"),low:t("environment.tide.heightLow"),timeLow:t("environment.tide.timeLow"),timeHigh:t("environment.tide.timeHigh"),coefficient:t("environment.tide.coeffNow")};Object.values(l).every(e=>null!=e)&&u({...l,isRising:h(e,l.timeLow,l.timeHigh)})},[t,h]);let{level:f,high:v,low:N,timeLow:w,timeHigh:g,coefficient:b,isRising:j}=m,p=e?c.NIGHT:c.DAY,G=j?o.RISING:o.FALLING,L=(0,s.useMemo)(()=>x(f,N,v),[f,N,v,x]);if(Object.values(m).some(e=>null===e))return null;let y=L>a.MIN&&L<a.MAX;return(0,i.jsxs)("div",{className:"flex flex-col items-center",children:[(0,i.jsx)("div",{className:"text-sm ".concat(p),children:"La Rochelle"}),(0,i.jsxs)("div",{className:"text-sm mb-2 ".concat(p," flex items-center gap-1"),children:[g,(0,i.jsx)("span",{className:"inline-block transform ".concat(!j&&"rotate-180"," ").concat(G.TEXT),children:"▲"}),(0,i.jsx)("span",{children:b})]}),(0,i.jsxs)("div",{className:"relative flex flex-col w-8",style:{height:l},children:[(0,i.jsxs)("span",{className:"absolute ".concat(p," text-sm font-medium"),style:{top:"0%",left:"60%"},children:[v,"m"]}),y&&(0,i.jsxs)("span",{className:"absolute ".concat(p," text-sm font-medium transition-opacity duration-300"),style:{bottom:"".concat(L,"%"),left:"60%"},children:[f.toFixed(2),"m"]}),(0,i.jsxs)("span",{className:"absolute ".concat(p," text-sm font-medium"),style:{bottom:"0%",left:"60%"},children:[N,"m"]}),(0,i.jsx)("div",{className:"flex flex-col justify-end bg-oGray rounded-3xl w-2 overflow-hidden",style:{height:l},children:(0,i.jsx)("div",{role:"progressbar",className:"".concat(G.BACKGROUND," w-2 rounded-3xl transition-all duration-500"),"aria-valuenow":L,"aria-valuemin":"0","aria-valuemax":"100","aria-label":"Tide level: ".concat(f.toFixed(2)," meters"),style:{height:"".concat(L,"%")}})})]}),(0,i.jsx)("div",{className:"text-sm mt-2 ".concat(p),children:w})]})}}}]);