import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{p as t,t as n}from"./vendor-react-iIHq6SOl.js";import{a as r}from"./main-DgxOmW_I.js";import{t as i}from"./AdminLayout-Cj-1ee3V.js";var a=e(t(),1),o=async()=>(await r.get(`/admin/tanggal-diblokir`)).data,s=async e=>(await r.post(`/admin/tanggal-diblokir`,e)).data,c=async e=>(await r.delete(`/admin/tanggal-diblokir/${e}`)).data,l=n(),u=[`Januari`,`Februari`,`Maret`,`April`,`Mei`,`Juni`,`Juli`,`Agustus`,`September`,`Oktober`,`November`,`Desember`];function d(e){if(!e)return`-`;try{let t=new Date(e);return`${t.getDate()} ${u[t.getMonth()]} ${t.getFullYear()}`}catch{return e}}function f(){let[e,t]=(0,a.useState)([]),[n,r]=(0,a.useState)(!0),[f,p]=(0,a.useState)(null),[m,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)(``),[v,y]=(0,a.useState)(``),[b,x]=(0,a.useState)(!1),S=new Date,[C,w]=(0,a.useState)(new Date(S.getFullYear(),S.getMonth(),1)),[T,E]=(0,a.useState)(``),D=(e,t=`success`)=>{p({msg:e,type:t}),setTimeout(()=>p(null),3500)},O=async()=>{r(!0);try{let e=await o();t(e.data||e||[])}catch{D(`Gagal memuat data`,`error`)}finally{r(!1)}};(0,a.useEffect)(()=>{O()},[]);let k=new Set(e.map(e=>e.tanggal?.split(`T`)[0]||e.tanggal)),A=e=>{E(e),_(e),h(!0)},j=async e=>{if(e.preventDefault(),!g){D(`Tanggal wajib dipilih`,`error`);return}x(!0);try{await s({tanggal:g,keterangan:v}),D(`Tanggal berhasil diblokir!`),h(!1),_(``),y(``),E(``),O()}catch{D(`Gagal memblokir tanggal`,`error`)}finally{x(!1)}},M=async e=>{if(confirm(`Yakin ingin membuka blokir tanggal ini?`))try{await c(e),D(`Blokir tanggal berhasil dibuka!`),O()}catch{D(`Gagal membuka blokir`,`error`)}},N=C.getFullYear(),P=C.getMonth(),F=new Date(N,P,1).getDay(),I=new Date(N,P+1,0).getDate(),L=e=>{let t=new Date(e+`T00:00:00`),n=t.getDay();return n===0||n===6?`weekend`:t<S&&t.toDateString()!==S.toDateString()?`past`:k.has(e)?`blocked`:`available`},R=(e,t)=>{let n={width:`38px`,height:`38px`,borderRadius:`9px`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`13px`,fontWeight:`600`,cursor:`default`,margin:`2px`,transition:`all 0.15s`};return t?{...n,background:`#0028B3`,color:`white`,cursor:`pointer`,boxShadow:`0 2px 8px rgba(0,40,179,0.3)`}:e===`blocked`?{...n,background:`#FEE2E2`,color:`#B91C1C`,border:`1px solid #FCA5A5`,cursor:`pointer`}:e===`available`?{...n,background:`#C5DBFF`,color:`#001178`,cursor:`pointer`}:{...n,background:`transparent`,color:`#CBD5E1`}};return(0,l.jsxs)(i,{children:[(0,l.jsx)(`style`,{children:`
        .kalender-grid {
          display: grid;
          grid-template-columns: 1fr 380px;
          gap: 20px;
          align-items: start;
        }
        @media (max-width: 900px) {
          .kalender-grid { grid-template-columns: 1fr; }
        }
      `}),f&&(0,l.jsx)(`div`,{style:{position:`fixed`,bottom:`24px`,right:`24px`,padding:`12px 20px`,borderRadius:`10px`,color:`white`,fontSize:`13.5px`,fontWeight:`600`,zIndex:9999,boxShadow:`var(--shadow-lg)`,background:f.type===`error`?`#B91C1C`:`#001178`},children:f.msg}),(0,l.jsxs)(`div`,{style:{marginBottom:`24px`,display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,flexWrap:`wrap`,gap:`12px`},children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{style:{fontSize:`22px`,fontWeight:`800`,color:`#001178`,letterSpacing:`-0.3px`},children:`Kelola Kalender`}),(0,l.jsx)(`p`,{style:{fontSize:`13.5px`,color:`#64748B`,marginTop:`3px`},children:`Blokir atau buka tanggal untuk kunjungan kerja`})]}),(0,l.jsx)(`button`,{onClick:()=>{h(!0),_(``),E(``)},style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`10px 18px`,minHeight:`42px`,border:`none`,borderRadius:`8px`,background:`#0028B3`,color:`white`,cursor:`pointer`,fontSize:`13px`,fontWeight:`700`,fontFamily:`inherit`,boxShadow:`0 2px 8px rgba(0,40,179,0.2)`},children:`+ Blokir Tanggal`})]}),(0,l.jsxs)(`div`,{className:`kalender-grid`,children:[(0,l.jsxs)(`div`,{style:{background:`white`,borderRadius:`16px`,boxShadow:`var(--shadow-sm)`,border:`1px solid rgba(228, 231, 237, 0.8)`,overflow:`hidden`},children:[(0,l.jsxs)(`div`,{style:{padding:`16px 20px`,borderBottom:`1px solid #E4E7ED`,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,l.jsx)(`button`,{onClick:()=>{let e=new Date(C);e.setMonth(e.getMonth()-1),w(e)},style:{width:`36px`,height:`36px`,borderRadius:`8px`,border:`1px solid #CBD5E1`,background:`white`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`16px`,color:`#334155`},children:`‹`}),(0,l.jsxs)(`span`,{style:{fontSize:`16px`,fontWeight:`800`,color:`#0F172A`},children:[u[P],` `,N]}),(0,l.jsx)(`button`,{onClick:()=>{let e=new Date(C);e.setMonth(e.getMonth()+1),w(e)},style:{width:`36px`,height:`36px`,borderRadius:`8px`,border:`1px solid #CBD5E1`,background:`white`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`16px`,color:`#334155`},children:`›`})]}),(0,l.jsxs)(`div`,{style:{padding:`20px`},children:[(0,l.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(7,1fr)`,gap:`4px`,marginBottom:`6px`},children:[`Min`,`Sen`,`Sel`,`Rab`,`Kam`,`Jum`,`Sab`].map(e=>(0,l.jsx)(`div`,{style:{textAlign:`center`,fontSize:`11px`,fontWeight:`700`,color:`#64748B`,padding:`6px 0`,textTransform:`uppercase`,letterSpacing:`0.5px`},children:e},e))}),(0,l.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(7,1fr)`,gap:`4px`},children:[Array.from({length:F},(e,t)=>(0,l.jsx)(`div`,{},`e`+t)),Array.from({length:I},(e,t)=>{let n=t+1,r=`${N}-${String(P+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`,i=L(r),a=T===r,o=i===`available`||i===`blocked`;return(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,alignItems:`center`},children:(0,l.jsx)(`div`,{style:R(i,a),title:i===`blocked`?`Klik untuk buka blokir`:i===`available`?`Klik untuk blokir`:``,onClick:()=>{o&&(i===`blocked`?confirm(`Buka blokir tanggal ${d(r)}?`)&&M(r):A(r))},children:n})},r)})]}),(0,l.jsx)(`div`,{style:{display:`flex`,gap:`16px`,flexWrap:`wrap`,marginTop:`18px`,paddingTop:`14px`,borderTop:`1px solid #E4E7ED`},children:[{color:`#C5DBFF`,border:`1px solid #1883FF`,label:`Tersedia`},{color:`#FEE2E2`,border:`1px solid #FCA5A5`,label:`Diblokir`},{color:`transparent`,border:`none`,label:`Weekend/Lalu`,textColor:`#94A3B8`}].map(e=>(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`7px`},children:[(0,l.jsx)(`div`,{style:{width:`14px`,height:`14px`,borderRadius:`4px`,background:e.color,border:e.border||`1px solid #E2E8F0`,flexShrink:0}}),(0,l.jsx)(`span`,{style:{fontSize:`12px`,color:e.textColor||`#475569`,fontWeight:`600`},children:e.label})]},e.label))})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`16px`},children:[m&&(0,l.jsxs)(`div`,{style:{background:`white`,borderRadius:`16px`,boxShadow:`var(--shadow-md)`,border:`1.5px solid #0028B3`,overflow:`hidden`},children:[(0,l.jsxs)(`div`,{style:{padding:`16px 20px`,background:`#0028B3`,color:`white`},children:[(0,l.jsx)(`div`,{style:{fontSize:`15px`,fontWeight:`700`},children:`Blokir Tanggal`}),(0,l.jsx)(`div`,{style:{fontSize:`12px`,opacity:.85,marginTop:`2px`},children:`Tanggal yang diblokir tidak dapat dipilih pemohon`})]}),(0,l.jsxs)(`form`,{onSubmit:j,style:{padding:`18px 20px`,display:`flex`,flexDirection:`column`,gap:`14px`},children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`label`,{style:{fontSize:`11px`,fontWeight:`700`,color:`#64748B`,textTransform:`uppercase`,letterSpacing:`0.5px`,display:`block`,marginBottom:`6px`},children:`Tanggal *`}),(0,l.jsx)(`input`,{type:`date`,value:g,onChange:e=>_(e.target.value),required:!0,style:{width:`100%`,padding:`10px 12px`,minHeight:`42px`,border:`1px solid #D9DEE5`,borderRadius:`8px`,fontSize:`13.5px`,fontFamily:`inherit`,boxSizing:`border-box`}})]}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`label`,{style:{fontSize:`11px`,fontWeight:`700`,color:`#64748B`,textTransform:`uppercase`,letterSpacing:`0.5px`,display:`block`,marginBottom:`6px`},children:`Keterangan / Alasan`}),(0,l.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`Contoh: Libur Nasional / Rapat Internal`,style:{width:`100%`,padding:`10px 12px`,minHeight:`42px`,border:`1px solid #D9DEE5`,borderRadius:`8px`,fontSize:`13.5px`,fontFamily:`inherit`,boxSizing:`border-box`}})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,gap:`10px`,marginTop:`4px`},children:[(0,l.jsx)(`button`,{type:`button`,onClick:()=>h(!1),style:{flex:`none`,background:`white`,border:`1px solid #CBD5E1`,borderRadius:`8px`,padding:`10px 18px`,minHeight:`42px`,fontSize:`13px`,fontWeight:`600`,cursor:`pointer`,fontFamily:`inherit`},children:`Batal`}),(0,l.jsx)(`button`,{type:`submit`,disabled:b,style:{flex:1,background:b?`#94A3B8`:`#0028B3`,color:`white`,border:`none`,borderRadius:`8px`,padding:`10px`,minHeight:`42px`,fontSize:`13px`,fontWeight:`700`,cursor:`pointer`,fontFamily:`inherit`,boxShadow:`0 2px 8px rgba(0,40,179,0.2)`},children:b?`Menyimpan...`:`Blokir Tanggal`})]})]})]}),(0,l.jsxs)(`div`,{style:{background:`white`,borderRadius:`16px`,boxShadow:`var(--shadow-sm)`,border:`1px solid rgba(228, 231, 237, 0.8)`,overflow:`hidden`},children:[(0,l.jsxs)(`div`,{style:{padding:`16px 20px`,borderBottom:`1px solid #E4E7ED`,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,l.jsx)(`div`,{style:{fontSize:`15px`,fontWeight:`700`,color:`#0F172A`},children:`Daftar Tanggal Diblokir`}),(0,l.jsxs)(`span`,{style:{background:`#FEE2E2`,color:`#B91C1C`,border:`1px solid #FCA5A5`,borderRadius:`20px`,padding:`3px 12px`,fontSize:`11.5px`,fontWeight:`700`},children:[e.length,` tanggal`]})]}),n?(0,l.jsx)(`div`,{style:{padding:`28px`,textAlign:`center`,color:`#64748B`,fontSize:`13.5px`},children:`Memuat data...`}):e.length===0?(0,l.jsxs)(`div`,{style:{padding:`32px 20px`,textAlign:`center`,color:`#64748B`},children:[(0,l.jsx)(`div`,{style:{fontSize:`32px`,marginBottom:`8px`},children:`📅`}),(0,l.jsx)(`div`,{style:{fontSize:`13.5px`},children:`Belum ada tanggal yang diblokir.`})]}):(0,l.jsx)(`div`,{style:{maxHeight:`380px`,overflowY:`auto`},children:e.map((e,t)=>{let n=e.tanggal?.split(`T`)[0]||e.tanggal;return(0,l.jsxs)(`div`,{style:{padding:`14px 20px`,borderTop:t>0?`1px solid #F1F5F9`:`none`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`10px`},children:[(0,l.jsxs)(`div`,{style:{minWidth:0},children:[(0,l.jsx)(`div`,{style:{fontSize:`13.5px`,fontWeight:`700`,color:`#B91C1C`},children:d(n)}),(0,l.jsx)(`div`,{style:{fontSize:`12px`,color:`#64748B`,marginTop:`2px`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.keterangan||`Tidak ada keterangan`}),(0,l.jsxs)(`div`,{style:{fontSize:`11px`,color:`#94A3B8`,marginTop:`2px`},children:[`oleh `,e.diblokir_oleh||`Admin`]})]}),(0,l.jsx)(`button`,{onClick:()=>M(n),style:{flexShrink:0,background:`#FEF2F2`,border:`1px solid #FECACA`,borderRadius:`8px`,padding:`7px 12px`,fontSize:`11.5px`,fontWeight:`700`,color:`#B91C1C`,cursor:`pointer`,fontFamily:`inherit`},children:`Buka`})]},t)})})]})]})]})]})}export{f as default};