import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{P as n,st as r}from"./api-CycUopBp.js";var i=e(t(),1);function a({contentTypeId:e,objectId:t,enabled:a=!0}){let[o,s]=(0,i.useState)([]),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(!1),[f,p]=(0,i.useState)(null),m=(0,i.useCallback)(async()=>{if(a){d(!0),p(null);try{let r=await n(e,t);s(r.results),l(r.workflow_configured)}catch(e){let t=e instanceof Error?e.message:`Failed to load approval history`;p(t),s([]),l(!1)}finally{d(!1)}}},[e,t,a]);(0,i.useEffect)(()=>{a&&m()},[m,a]);let h=(0,i.useCallback)(async(e,t,n)=>{try{return await r(e,{decision:t,comment:n}),await m(),{success:!0,error:null}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Failed to submit decision`}}},[m]),g=o.find(e=>e.status===`pending`),_=o.length>0;return{approvalHistory:o,currentRequest:g,latestRequest:o[0],hasApprovalEnabled:_,workflowConfigured:c,canApprove:g?.can_approve??!1,canReject:g?.can_reject??!1,isLoading:u,error:f,loadApprovalHistory:m,submitDecision:h}}export{a as t};