import{r as n,j as e,c as S}from"./index-8bmEFR-X.js";import{B as _}from"./Back-DwJpuVlK.js";import{u as b,w as u,a as C,p as q,q as y,E as A}from"./index-LdZ0ypXi.js";import{c as E,g as w}from"./index-CVxls_2e.js";import{T as B}from"./index-CAz3TTh0.js";import{E as z}from"./EquipmentStatus-DNbjT3Dj.js";import"./tslib.es6-CFMGCLkz.js";import"./render-to-body-B48wKqLN.js";import"./config-provider-mqFn8hqY.js";const R="_page_c6195_1",I="_calendar_c6195_12",k={page:R,calendar:I},H=w("left"),L=w("right"),P=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],W=["周日","周一","周二","周三","周四","周五","周六"];function F(){const r=b(),[i,h]=n.useState(()=>Date.now()/1e3),[j,v]=n.useMemo(()=>{const s=Math.round(u(i,0).getTime()/1e3),t=s+7*86400;return[s,t]},[i]),d=n.useMemo(()=>[...new Array(7).keys()].map(s=>u(i,s)),[i]),{value:f}=C(r,j,v),{value:x,loading:T}=q(r,j,v),g=n.useMemo(()=>{const s=[...x];return f.forEach(t=>{x.some(a=>{var c;return((c=a.user)==null?void 0:c.id)===t.id&&a.startTime===t.startTime&&a.endTime===t.endTime})||s.push(t)}),s},[f,x]),M=n.useMemo(()=>{const s=[];return g.forEach(t=>{d.forEach((a,c)=>{const l=Math.round(a.getTime()/1e3),o=l+86400;(t.startTime>=l&&t.startTime<o||t.endTime>=l&&t.endTime<o||t.startTime<o&&t.endTime>=o)&&s.push({id:t.id,user:t.user,startTime:Math.max(t.startTime,l),endTime:Math.min(t.endTime,o),day:c,booking:t})})}),s},[g,d]),p=n.useRef(null),[m,D]=n.useState([0,0]),N=new Date;return n.useEffect(()=>{function s(){const t=(p.current.clientWidth-128)/7,a=p.current.clientHeight/24;D([t,a])}return window.addEventListener("resize",s),s(),()=>{window.removeEventListener("resize",s)}},[]),n.useEffect(()=>{if(!T)return;const{close:s}=B.show({content:"加载中...",icon:"loading",duration:0});return()=>{s()}},[T]),e.jsxs("div",{className:k.calendar,children:[e.jsxs("div",{className:"calendar-navbar",children:[e.jsx("div",{className:"title",children:r==null?void 0:r.name}),e.jsx(z,{}),e.jsx("div",{style:{flex:1}}),e.jsx("div",{className:"button",onClick:()=>h(i-86400*7),children:e.jsx(H,{})}),e.jsx("div",{className:"button",onClick:()=>h(Math.round(Date.now()/1e3)),children:"今天"}),e.jsx("div",{className:"button",onClick:()=>h(i+86400*7),children:e.jsx(L,{})})]}),e.jsxs("div",{className:"calendar-table",children:[e.jsxs("div",{className:"header",children:[e.jsx("div",{className:"time",children:P[u(i,0).getMonth()]}),d.map((s,t)=>e.jsxs("div",{className:E("day",y(N,s)&&"today"),children:[e.jsx("div",{className:"part-day",children:W[s.getDay()]}),e.jsx("div",{style:{flex:1}}),e.jsx("div",{className:"part-date",children:s.getDate()})]},t))]}),e.jsx("div",{className:"body",children:e.jsxs("div",{className:"body-inner",children:[e.jsx("div",{ref:p,children:[...new Array(24).keys()].map(s=>e.jsxs("div",{className:"hour",children:[e.jsx("div",{className:"time",children:`${s}:00`}),[...new Array(7).keys()].map(t=>{const a=u(i,t);return e.jsx("div",{className:E("day",y(N,a)&&"today")},t)})]},s))}),M.map((s,t)=>{const a=(s.startTime-d[s.day].getTime()/1e3)*m[1]/3600,c=(s.endTime-s.startTime)*m[1]/3600;return e.jsx("div",{className:"block",style:{left:132+s.day*m[0],width:m[0]-4,top:a,height:c},children:s.booking.user.name},t)})]})})]})]})}function X(){const{equipmentId:r}=S();return r?e.jsxs(e.Fragment,{children:[e.jsx(_,{}),e.jsxs("div",{className:k.page,children:[e.jsx("div",{className:"page-title",children:"预约日历"}),e.jsx(A,{equipmentId:r,children:e.jsx(F,{})})]})]}):null}export{X as default};
