1import{o as e}from"./rolldown-runtime-CIY_5nX3.js";import{t as n}from"./react-FULpMJoD.js";import{n as s,t as a}from"./objectSpread2-BFiCZz2a.js";import{t as o}from"./asyncToGenerator-BPBW7q7J.js";import{Fa as i,Pa as r,Zi as l,da as c,ec as d,f as m,gc as h,gs as p,js as u,mt as j}from"./shared-CdsUmFMV.js";import{t as x}from"./jsx-runtime-BPCteR4x.js";import{Dn as y,I as f,a as b,en as g,gn as _,kn as v,n as C}from"./buttons-CzOFSBHW.js";import{t as k}from"./useTranslation-CUymA54J.js";import{F as w,a as D,d as T,f as F,i as $,n as W,r as E,s as N,u as S,x as P}from"./icons-list-loader-BdfGv1dg.js";import{C as R,F as I,p as L}from"./page-DShDq_oP.js";import{a as A,i as M,p as V,r as z}from"./detention-consent.utils-9sqBO8Su.js";var B=e(n()),G=x();s();var O=["en","es","fr"];function X(){const{t:t}=k(),{showToast:e}=v(),{showConfirm:n}=h(),s=l("active"),x=l("hmap"),X=l("context","EXPLICIT"),Z=X.top_level?x:s,q=Z.brand_id,{hmapPath:H}=j(),J=X.top_level?`/access-portal${H}/detention-emergency-contact-consent`:"/detention-emergency-contact-consent",{canViewDetentionConsent:K,canManageDetentionConsent:Q}=r(),[U,Y]=(0,B.useState)(!1);(0,B.useEffect)(()=>{Q(Z.brand_id,Z.brand_type).then(Y)},[Z.brand_id,Z.brand_type]);const ee=(0,B.useCallback)(()=>K(Z.brand_id,Z.brand_type),[Z.brand_id,Z.brand_type]),{consents:ne,load:te,deleteConsent:se,loading:ae,error:oe}=V();(0,B.useEffect)(()=>{q&&!isNaN(q)&&te(q).catch(()=>{e(t("Failed to load consents"),"danger")})},[q]);const ie=s=>{var a;n({title:t("Delete consent?"),content:t("Are you sure you want to delete this consent ?"),confirmCTALabel:t("Delete"),onConfirm:(a=o(function*(){try{yield se(q,s.id),e(t("Consent deleted"),"success")}catch(n){e(t("Failed to delete consent"),"danger")}}),function(){return a.apply(this,arguments)})})},[re,le]=(0,B.useState)(null),[ce,de]=(0,B.useState)(null),me=(0,B.useRef)(new Map),he=(0,B.useRef)(null),pe=(ue=o(function*(n){if(null!==re){de(n);try{const{generated_file_url:e}=yield i.exportConsent(q,re,n);u(e,!0),le(null)}catch(s){e(t("Failed to download consent"),"danger")}finally{de(null)}}}),function(e){return ue.apply(this,arguments)});var ue;return!q||isNaN(q)?(0,G.jsx)(R,{layout:"fluid",children:(0,G.jsx)(W,{columns:7,rows:5,"aria-label":t("Detention emergency contact consents")})}):(0,G.jsxs)(m,{checker:ee,children:[U&&ne.length>0&&(0,G.jsx)(L,{children:(0,G.jsx)(P,{color:"primary",to:`${J}/management`,children:t("Create new consent")})}),(0,G.jsxs)(R,{layout:"fluid",children:[ae?(0,G.jsx)(W,{columns:7,rows:5,"aria-label":t("Detention emergency contact consents")}):oe?(0,G.jsx)(p,{variant:"subtle",color:"danger",children:t("Failed to load consents. Refresh the page to try again.")}):0===ne.length?(0,G.jsx)(g,{icon:(0,G.jsx)(w,{icon:d}),title:t("No documents found"),description:t("Detention emergency contacts or consent documents yet"),actionProps:U?{label:t("Create new consent"),to:`${J}/management`,color:"primary",variant:"solid"}:void 0}):(0,G.jsx)(F,{children:(0,G.jsxs)(T,{label:t("Detention emergency contact consents"),children:[(0,G.jsx)(S,{children:(0,G.jsxs)(N,{children:[(0,G.jsx)(E,{stickyTop:!0,stickyStart:!0,children:t("Form name")}),(0,G.jsx)(E,{stickyTop:!0,children:t("Locations")}),(0,G.jsx)(E,{stickyTop:!0,children:t("Recurrence")}),(0,G.jsx)(E,{stickyTop:!0,children:t("Created by")}),(0,G.jsx)(E,{stickyTop:!0,children:t("Created on")}),(0,G.jsx)(E,{stickyTop:!0,children:t("Effective on")}),(0,G.jsx)(E,{stickyTop:!0,stickyEnd:!0})]})}),(0,G.jsx)($,{children:ne.map(e=>{var n;const s=e.brands.map(e=>e.name).filter(e=>Boolean(e)),o=e.monthly_recurrence?z(e.monthly_recurrence,t):"-",i=e.created_by?`${e.created_by.first_name} ${e.created_by.last_name}`:"";return(0,G.jsxs)(N,{children:[(0,G.jsx)(D,{stickyStart:!0,style:{minWidth:"250px"},children:e.name}),(0,G.jsxs)(D,{style:{minWidth:"200px"},children:[null!==(n=s[0])&&void 0!==n?n:"-",s.length>1&&(0,G.jsx)(y,{content:s.slice(1).join(", "),children:e=>(0,G.jsx)(I,a(a({},e),{},{color:"light",variant:"solid",shape:"pill",sizing:"xs",className:"ms-1",badgeContent:"+"+(s.length-1)}))})]}),(0,G.jsx)(D,{style:{minWidth:"160px"},children:o}),(0,G.jsx)(D,{style:{minWidth:"180px"},children:i}),(0,G.jsx)(D,{style:{minWidth:"160px"},children:f(e.created_on)}),(0,G.jsx)(D,{style:{minWidth:"160px"},children:f(e.effective_date)}),(0,G.jsx)(D,{stickyEnd:!0,children:(0,G.jsx)("div",{ref:(r=e.id,e=>{e?me.current.set(r,e):me.current.delete(r)}),className:"d-inline-block",children:(0,G.jsx)(C,{dropdownIconVariant:"ellipsis",ariaLabel:t("Actions"),sizing:"xs",color:"light",children:({closeMenu:n})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(_,{label:t("View"),to:`${J}/management?consent_id=${e.id}&mode=view`}
1),U&&!M(e)&&(0,G.jsx)(_,{label:t("Edit"),to:`${J}/management?consent_id=${e.id}`}),(0,G.jsx)(_,{label:t("Download as PDF"),onClick:()=>{n(),(e=>{var n;he.current=null!==(n=me.current.get(e))&&void 0!==n?n:null,le(e)})(e.id)}}),U&&!M(e)&&(A(e)||!e.has_response)&&(0,G.jsx)(_,{label:t("Delete"),onClick:()=>ie(e)})]})})})})]},e.id);var r})})]})}),(0,G.jsx)(b,{isOpen:null!==re,elmRef:he,onClose:()=>{ce||le(null)},matchWidth:!1,placement:"bottom-end",style:{minWidth:"180px"},children:O.map(e=>(0,G.jsx)(_,{label:t(c[e].label),disabled:null!==ce,onClick:()=>pe(e)},e))})]})]})}export{X as DetentionConsentsList,X as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.