import{r,j as e}from"./app-DBtZ8h0a.js";import{c as u}from"./utils-B0kY8eQi.js";import{I}from"./InputGroup-y7VQa4RO.js";import{C as q}from"./circle-alert-DuosJsOu.js";import{X as z}from"./x-CfYMzEXa.js";const B={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-2xl",full:"w-full mx-6"},Q=({title:a="",size:l="md",isOpen:s,onClose:c,children:N,closeOnOverlayClick:k=!0,closeOnEsc:h=!0,overlayClassName:E="",className:C="",header:M=!0,footer:p,onConfirm:b,cancelText:L="Batal",confirmText:R="Setuju",confirmDisabled:j=!1,confirmClassName:$="bg-primary text-primary-foreground hover:bg-primary/90",error:n,onScrollToBottom:o,agreement:x})=>{const[m,i]=r.useState(!1),[g,w]=r.useState(!1),v=r.useRef(null),A=r.useCallback(()=>{const t=!!n,d=!!x,f=!!o;return!!(j||t||d&&!m||f&&!g)},[j,n,x,m,o,g]);r.useEffect(()=>{const t=v.current;if(!t||!s)return;const d=()=>{const f=t.scrollTop+t.clientHeight>=t.scrollHeight-10;w(f),f&&o&&o()};return t.addEventListener("scroll",d),()=>t.removeEventListener("scroll",d)},[s,o]),r.useEffect(()=>{if(!s||!h)return;const t=d=>{d.key==="Escape"&&(c(),i(!1))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[s,h,c]);const H=t=>{k&&t.target===t.currentTarget&&(c(),i(!1))};if(r.useEffect(()=>{s||(i(!1),w(!1))},[s]),!s)return null;const y=()=>{c(),i(!1)};return e.jsx("div",{className:`fixed inset-0 z-50 min-h-screen flex items-center justify-center bg-black/50 backdrop-blur-sm ${E}`,onClick:H,children:e.jsxs("div",{className:u(`relative bg-secondary text-secondary-foreground rounded-lg shadow-lg flex flex-col max-h-[90vh] ${B[l]}`,C),children:[M&&e.jsx(S,{onClose:y,children:a}),e.jsx(D,{className:"flex-1 overflow-auto",ref:v,children:N}),x&&e.jsxs("div",{className:"flex gap-2 px-4 text-sm",children:[e.jsx(I,{name:"agreement",type:"checkbox",checked:m,onChange:t=>i(!!t),classNameInput:u("h-5 w-5 form-checkbox rounded accent-blue-500",!m&&"animate-pulse bg-accent-primary",n&&"accent-red-500")}),x]}),(p||b)&&e.jsxs(F,{className:u(n&&"justify-between"),children:[n&&e.jsxs("p",{className:"flex items-center gap-2 text-xs text-red-500 mt-1",children:[e.jsx(q,{className:"text-red-500 w-4 h-4"}),n]}),p||e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:y,className:"px-4 py-2 text-white text-sm font-medium rounded-md bg-red-500 hover:bg-red-400",children:L}),e.jsx("button",{onClick:b,disabled:A(),className:u("px-4 py-2 text-sm font-medium rounded-md disabled:opacity-50 disabled:cursor-not-allowed",$),children:R})]})]})]})})},S=({children:a,className:l="",showCloseButton:s=!0,onClose:c})=>e.jsxs("div",{className:`flex justify-between items-center p-2 border-b ${l}`,children:[e.jsx("h3",{className:"text-xl font-semibold",children:a}),s&&e.jsx("button",{onClick:c,className:" absolute top-2 right-2 text-red-500 hover:text-accent-foreground text-2xl","aria-label":"Close",children:e.jsx(z,{})})]}),D=r.forwardRef(({children:a,className:l=""},s)=>e.jsx("div",{ref:s,className:`p-2 overflow-auto ${l}`,children:a})),F=({children:a,className:l=""})=>e.jsx("div",{className:u("px-2 py-2 border-t flex justify-end space-x-2 ",l),children:a});export{Q as M};
