import{r,j as a}from"./app-Bup04Qnx.js";import{W as w}from"./WithModal-CbKxT3eW.js";const y=({isOpen:i,onClose:d,onCapture:f,id:h="camera_modal"})=>{const s=r.useRef(null),n=r.useRef(null),[c,u]=r.useState(null),[l,m]=r.useState(null),x=async()=>{try{m(null);const e=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"},audio:!1});u(e),s.current&&(s.current.srcObject=e)}catch(e){console.error("Error accessing camera:",e),m("Gagal mengakses kamera. Pastikan izin kamera diberikan.")}},o=r.useCallback(()=>{c&&(c.getTracks().forEach(e=>e.stop()),u(null))},[c]);r.useEffect(()=>(i?x():o(),()=>{o()}),[i]);const b=()=>{if(s.current&&n.current){const e=s.current,t=n.current,p=t.getContext("2d");t.width=e.videoWidth,t.height=e.videoHeight,p.drawImage(e,0,0,t.width,t.height),t.toBlob(v=>{const j=new File([v],`capture_${Date.now()}.png`,{type:"image/png"});f(j),d()},"image/png")}},g=()=>{o(),d()};return a.jsx(w,{type:h,backdrop:!0,onClick:g,modalBoxSize:"max-w-lg",boxClassName:"modal-box p-0",children:a.jsxs("div",{className:"w-full",children:[a.jsx("div",{className:"relative w-full h-[400px] flex items-center justify-center bg-black",children:l?a.jsx("div",{className:"text-error text-center p-4",children:l}):a.jsx("video",{ref:s,autoPlay:!0,playsInline:!0,className:"w-full h-full object-cover"})}),a.jsx("div",{className:"p-4 bg-base-100 flex justify-center",children:!l&&a.jsx("button",{className:"btn btn-circle btn-outline btn-primary btn-lg border-4",onClick:b,"aria-label":"Capture Photo",children:a.jsx("div",{className:"w-12 h-12 bg-primary rounded-full border-2 border-white"})})}),a.jsx("canvas",{ref:n,className:"hidden"})]})})};export{y as C};
