import{r as l,j as e,K as Z,u as ee,a as ae,m as te,S as se}from"./app-DBtZ8h0a.js";import{B as M}from"./button-DYdrlfXL.js";import{I as F}from"./InputGroup-y7VQa4RO.js";import{c as E}from"./createLucideIcon-ivHVH1Cm.js";import{C as le}from"./circle-alert-DuosJsOu.js";import{C as ne}from"./ConfirmDialog -DCn9hvXC.js";import{S as ie}from"./SelectInput-C3GOCL2Z.js";import{d as y}from"./dayjs.min-D6tasAYA.js";import{u as re}from"./use-mobile-B8pMEbRn.js";import{c as H}from"./utils-B0kY8eQi.js";import{C as oe,S as de}from"./status-badge-GaLEC-Oa.js";import{F as ce}from"./file-text-DqIsb-_X.js";import{S as me}from"./send-CXaFA6Wz.js";/* empty css            */import"./index-ClrXUyoj.js";import"./iconBase-DFNKp9Em.js";import"./Combination-T3b6BNU6.js";import"./index-BW9zw9n8.js";import"./index-Bpge5JtW.js";import"./check-Bm3f6cJs.js";import"./badge-DYD95X8f.js";import"./clock-CF6ZwmLW.js";import"./circle-check-big-CjF5UNvc.js";/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ue=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],ge=E("Plus",ue);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const pe=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],xe=E("Trash2",pe);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const he=[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]],fe=E("Upload",he),V=l.forwardRef(({name:r,label:v,preview:m,showError:u=!1,errorMessage:c="",processing:h=!1,required:f=!1,handleRemoveImage:T,handleFileChange:g,className:B=""},n)=>{const p=()=>{!h&&typeof n!="function"&&(n!=null&&n.current)&&n.current.click()},P=C=>{g(C,r)},w=()=>{T(r),typeof n!="function"&&(n!=null&&n.current)&&(n.current.value="")};return e.jsxs("div",{className:`space-y-2 ${B}`,children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:[v," ",f&&"*"]}),e.jsxs("div",{className:"flex flex-col space-y-2",children:[m?e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:m,alt:`Preview ${v}`,className:"max-w-full h-auto max-h-64 rounded border border-gray-200"}),e.jsx("div",{className:"absolute inset-0 bg-black/50 bg-opacity-0 group-hover:bg-opacity-30 transition-all duration-200 flex items-center justify-center opacity-0 group-hover:opacity-100",children:e.jsx("button",{type:"button",className:"bg-red-500 text-white rounded-full p-2 hover:bg-red-600 transition-colors",onClick:w,disabled:h,children:e.jsx(xe,{className:"h-5 w-5"})})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:p,className:`flex flex-col items-center justify-center px-4 py-8 bg-white rounded-md border-2 border-dashed ${u?"border-red-300":"border-gray-300"} cursor-pointer hover:bg-gray-50 transition-colors`,"aria-invalid":u,children:[e.jsx(fe,{className:"h-12 w-12 text-gray-400"}),e.jsxs("span",{className:"mt-2 text-sm font-medium text-gray-700",children:["Upload ",v]}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:"Format: JPG/PNG, maksimal 2MB"})]}),e.jsx("input",{ref:n,id:r,name:r,type:"file",accept:"image/jpeg, image/png, image/jpg",className:"hidden",onChange:P,disabled:h})]}),u&&e.jsxs("p",{className:"text-xs text-red-500 mt-1 flex items-center gap-2",children:[e.jsx(le,{className:"text-red-500 w-5 h-5"}),e.jsx("span",{children:c})]})]})]})});V.displayName="InputFile";const Ue=({nouid:r})=>{const{data:v,jenis:m=[]}=Z().props,u=re(),{log:c,error:h}=ee(),{APP_DEBUG:f}=ae(),[T,g]=l.useState(!1),[B,n]=l.useState(!1),[p,P]=l.useState(null),[w,C]=l.useState(v.izin||[]),[j,I]=l.useState(null),[o,d]=l.useState({}),S=l.useRef(null),{data:s,setData:k,reset:D,post:A,processing:_}=te({jen:f?2:0,tgl_mulai:f?y().format("YYYY-MM-DD"):"",tgl_akhir:f?y().format("YYYY-MM-DD"):"",ket:f?"TEST MODE TEST MODE":"",dok:null}),G=l.useMemo(()=>m.map(a=>({value:a.id.toString(),label:a.title})),[m]),R=l.useCallback(()=>{const a={};let t=!0;return s.jen||(a.jen="Jenis izin harus dipilih",t=!1),s.tgl_mulai||(a.tgl_mulai="Tanggal mulai harus diisi",t=!1),s.tgl_akhir?y(s.tgl_akhir).isBefore(y(s.tgl_mulai))&&(a.tgl_akhir="Tanggal selesai tidak boleh sebelum tanggal mulai",t=!1):(a.tgl_akhir="Tanggal selesai harus diisi",t=!1),s.ket?s.ket.length<10&&(a.ket="Keterangan minimal 10 karakter",t=!1):(a.ket="Keterangan harus diisi",t=!1),!s.dok&&!j&&(a.dok="Dokumen pendukung diperlukan",t=!1,setTimeout(()=>{var i;(i=S.current)==null||i.focus()},0)),d(a),t||h("Validation errors",a),t},[s,j,h]),U=l.useCallback(a=>{var $;const t=($=a.target.files)==null?void 0:$[0];if(!t)return;const i=["image/jpeg","image/png"],Y=2*1024*1024;if(!i.includes(t.type)){d(x=>({...x,dok:"Format file harus JPG atau PNG"}));return}if(t.size>Y){d(x=>({...x,dok:"Ukuran file maksimal 2MB"}));return}d(x=>({...x,dok:void 0}));const b=new FileReader;b.onload=x=>{var q;I((q=x.target)==null?void 0:q.result),k("dok",t)},b.readAsDataURL(t)},[k]),O=l.useCallback(()=>{I(null),k("dok",null),d(a=>({...a,dok:void 0})),S.current&&(S.current.value="")},[k]),N=l.useCallback((a,t)=>{k(i=>({...i,[a]:t})),o[a]&&d(i=>({...i,[a]:void 0}))},[k,o]),J=l.useCallback(async a=>{if(a.preventDefault(),!!R()){g(!0);try{await A(route("izin.store",r),{onSuccess:()=>{const t=m.find(b=>b.id===s.jen),i=(t==null?void 0:t.title)||"Unknown",Y={id:Math.random().toString(36).substring(2,9),...s,dok:j||null,sta:"menunggu",created_at:new Date,title:i};C(b=>[...b,Y]),D(),I(null),d({}),c("Pengajuan izin berhasil",Y)},onError:t=>{d(t),c("Gagal mengajukan izin",{errors:t,data:s})},onFinish:()=>{g(!1)}})}catch(t){console.error("Submission error:",t),g(!1),c("Error sistem saat mengajukan izin",{error:t})}}},[s,j,R,r,D,c,A,m]),K=l.useCallback(a=>{P(a),n(!0)},[]),L=l.useCallback(()=>{p&&se.post(route("izin.cancel",r),{id:p},{onSuccess:()=>{C(a=>a.map(t=>t.id===p?{...t,sta:"dibatalkan"}:t)),n(!1),c("Izin dibatalkan",{idIzin:p})}})},[p,c,r]),z=l.useCallback((a,t=!1)=>y(a).format(t?"DD MMMM YYYY HH:mm":"DD MMMM YYYY"),[]),Q=l.useMemo(()=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 bg-gray-50 rounded-lg",children:[e.jsx(ce,{className:"w-10 h-10 text-gray-400 mb-3"}),e.jsx("h3",{className:"text-lg font-medium text-gray-500 mb-1",children:"Belum ada pengajuan izin"}),e.jsx("p",{className:"text-gray-400 text-center max-w-md px-4",children:'Anda belum membuat permohonan izin. Klik tombol "Ajukan Izin Baru" untuk membuat pengajuan.'})]}),[]),W=l.useCallback(a=>e.jsxs("div",{className:"border rounded-lg p-3 shadow-sm hover:shadow-md transition-shadow bg-white space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h3",{className:"font-semibold text-lg text-gray-800 capitalize",children:a.title||"Izin Tidak Diketahui"})}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[e.jsx(oe,{className:"inline mr-1 w-4 h-4"}),z(a.tgl_mulai)," - ",z(a.tgl_akhir)]})]}),e.jsx(de,{status:a.sta})]}),e.jsxs("div",{className:H("mt-4 flex justify-between gap-2 items-end",u&&"flex-col-reverse items-start"),children:[e.jsxs("span",{className:"text-xs text-start text-gray-400",children:["Diajukan pada: ",z(a.created_at,!0)]}),e.jsxs("div",{className:H("flex-1 flex w-full gap-2 justify-end",u&&"w-full"),children:[a.sta==="menunggu"&&e.jsx(M,{variant:"destructive",size:"sm",onClick:()=>K(a.id),className:"hover:bg-red-600 transition-colors",children:"Batalkan"}),e.jsx(M,{size:"sm",onClick:()=>{},children:"Detail"})]})]})]},a.id),[z,K,u]),X=l.useMemo(()=>e.jsxs("form",{onSubmit:J,className:"bg-white rounded-lg shadow-sm p-6",children:[e.jsx("div",{className:"flex items-center justify-center mb-6",children:e.jsx("h2",{className:"text-xl font-bold text-blue-800",children:"Formulir Pengajuan Izin"})}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(ie,{name:"jen",label:"Jenis Izin",value:s.jen.toString(),onChange:a=>N("jen",parseInt(a)),options:G,placeholder:"Pilih jenis izin",errors:o,required:!0}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(F,{label:"Tanggal Mulai",type:s.jen===3?"datetime-local":"date",name:"tgl_mulai",value:s.tgl_mulai,min:y().format("YYYY-MM-DD"),onChange:a=>N("tgl_mulai",a),errors:o,required:!0}),e.jsx(F,{label:"Tanggal Selesai",type:s.jen===3?"datetime-local":"date",name:"tgl_akhir",value:s.tgl_akhir,onChange:a=>N("tgl_akhir",a),min:s.tgl_mulai,errors:o,required:!0})]}),e.jsx(F,{label:"Keterangan",type:"textarea",name:"ket",value:s.ket,onChange:a=>N("ket",a),placeholder:"Berikan penjelasan detail alasan izin...",rows:4,errors:o,required:!0}),e.jsx(V,{ref:S,name:"dok",label:"Dokumen Pendukung",preview:j??void 0,showError:!!o.dok,errorMessage:o.dok,handleRemoveImage:O,handleFileChange:U}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"Format: JPG, PNG (Maks. 2MB)"}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-gray-100",children:[e.jsx(M,{variant:"destructive",type:"button",onClick:()=>{D(),d({}),I(null),g(!1)},disabled:_,children:"Batal"}),e.jsxs(M,{type:"submit",className:"bg-blue-600 hover:bg-blue-700",disabled:_,children:[e.jsx(me,{className:"mr-2 w-4 h-4"}),_?"Mengajukan...":"Ajukan Izin"]})]})]})]}),[s,o,U,N,O,J,j,D,G,_]);return e.jsxs("div",{className:"max-w-4xl mx-auto p-2",children:[T?X:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsxs(M,{onClick:()=>g(!0),className:"bg-blue-600 hover:bg-blue-700",children:[e.jsx(ge,{className:"mr-2",size:16})," Ajukan Izin Baru"]})}),w.length===0?Q:e.jsx("div",{className:"space-y-4",children:w.map(W)})]}),e.jsx(ne,{open:B,onOpenChange:n,title:"Batalkan Izin",description:"Apakah anda yakin ingin membatalkan izin ini?",confirmText:"Ya",cancelText:"Tidak",onConfirm:L})]})};export{Ue as default};
