import{r as n,j as e,c as S}from"./index-Db5TLbgN.js";import{B as _}from"./Back-BtvH7PRT.js";import{u as b,w as u,a as C,p as q,q as y,E as A}from"./index-CB_FsW6Y.js";import{c as E,g as w}from"./index-N8sl9VKn.js";import{T as B}from"./index-BCwoBjcn.js";import{E as z}from"./EquipmentStatus-BEWGrB6F.js";import"./tslib.es6-e2qAPn_M.js";import"./config-provider-Di0gwp82.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),[p,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,p,v),{value:x,loading:T}=q(r,p,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 m=Math.round(a.getTime()/1e3),o=m+86400;(t.startTime>=m&&t.startTime<o||t.endTime>=m&&t.endTime<o||t.startTime<o&&t.endTime>=o)&&s.push({id:t.id,user:t.user,startTime:Math.max(t.startTime,m),endTime:Math.min(t.endTime,o),day:c,booking:t})})}),s},[g,d]),j=n.useRef(null),[l,D]=n.useState([0,0]),N=new Date;return n.useEffect(()=>{function s(){const t=(j.current.clientWidth-128)/7,a=j.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:j,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)*l[1]/3600,c=(s.endTime-s.startTime)*l[1]/3600;return e.jsx("div",{className:"block",style:{left:132+s.day*l[0],width:l[0]-4,top:a,height:c},children:s.booking.user.name},t)})]})})]})]})}function V(){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{V as default};
