import{k as R,l as k,ew as U,R as l,o as r,j as e,Y as d,h as u,i as p,bi as s}from"./app-BgLa5dit.js";import{S as O}from"./BixyE8L-.chunk.js";import{A as S}from"./CsH2Nu4a.chunk.js";import{D as w}from"./nLtuAPO5.chunk.js";import{A as h}from"./uachN0F4.chunk.js";import{C as F}from"./q-IBKcuF.chunk.js";import{S as L}from"./DeGPZXe2.chunk.js";import{m as q}from"./CgJlvU9K.chunk.js";import"./DUpYPoLs.chunk.js";import"./EZim8aq-.chunk.js";import"./BD9MrUJP.chunk.js";import"./s6cGcwlA.chunk.js";import"./Zwjmkasg.chunk.js";import"./4qGb1BIY.chunk.js";import"./DnXDEnAR.chunk.js";import"./DpUpv6rY.chunk.js";import"./CG7zbly5.chunk.js";import"./m4aqaK_l.chunk.js";import"./MEkA24R1.chunk.js";import"./C53kfXmd.chunk.js";function oe(a){var g,j,C;const D=R(),f=k(),o=U(),t=l.useRef(null),[y,x]=l.useState(!1),i=r(F.customer(a.customerId)),c=r(h.customerAccessPolicy(a.customerId)),I=r(h.accessPolicies()),m=r(L.customerSettings(a.customerId)),Y=q((g=c.data)==null?void 0:g.type),N=[S.Timed,S.Cft].includes(Y);function E(n){if(!n.target.value||!s.formatIsValid(n.target.value,"YYYY-MM-DD",!0)){o();return}const[v,A,M]=n.target.value.split("-").map(Number),b=new Date(t.current.getTime());b.setUTCFullYear(v,A-1,M),t.current=b,x(!0),o()}function P(){const n=h.setTrialEndDate(a.customerId,t.current.toISOString());D(n).then(()=>{x(!1),f.success("Successfully updated the policy end date")}).catch(()=>f.error(`Just your ol' fashioned "Something went wrong"`))}const T=m.data?(j=m.data[O.PolicyEndTime])==null?void 0:j.value:null;return l.useEffect(()=>{t.current=new Date(T),o()},[T]),i.hasCompleted&&c.hasCompleted&&I.hasCompleted&&m.hasCompleted?c.data?e.jsxs("div",{children:[e.jsxs("h3",{className:"h6 mb-3",children:[i.data.name," (",i.data.crmId,")"]}),e.jsx("h4",{children:"Access policy"}),e.jsxs("div",{className:"mb-1",children:[e.jsx("label",{children:"Name:"})," ",c.data.id]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("label",{children:"Description:"})," ",c.data.description]}),(C=c.data.arguments)!=null&&C.nextCft?e.jsxs("div",{className:"mb-1",children:[e.jsx("label",{children:"Next CFT:"})," ",c.data.arguments.nextCft]}):null,e.jsx(d,{appLink:{application:p.CUSTOMERS,action:u.Customers.EDIT_PILOT,args:[a.customerId]},className:"btn btn-outline-dark",children:"Change policy"}),e.jsx(d,{appLink:{application:p.CUSTOMERS,action:u.Customers.REMOVE_PILOT,args:[a.customerId]},className:"btn btn-link text-danger me-3",children:"Remove policy"}),N&&t.current&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"mt-4",children:"Policy end date"}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("p",{className:"mb-0",children:[s.format(t.current,"D/M/YYYY, h:mm:ss a"),"  (",Intl.DateTimeFormat().resolvedOptions().timeZone," ",s.format(t.current,"Z"),")"]}),e.jsxs("p",{className:"text-secondary",children:[s.formatUtc(t.current.getTime(),"D/M/YYYY, h:mm:ss a"),"  (UTC ",s.formatUtc(t.current.getTime(),"Z"),")"]}),e.jsx(w,{id:"policy-end-time",required:!0,value:s.formatUtc(t.current.getTime(),"YYYY-MM-DD"),min:s.formatToISODate(s.add(new Date,1,"day")),onChange:E})]}),e.jsx("button",{className:`btn btn-outline-dark ${y?"":"disabled"}`,disabled:!y,onClick:P,children:"Update end time"})]})]}):e.jsxs("div",{children:[e.jsxs("h3",{className:"h6",children:[i.data.name," (",i.data.crmId,")"]}),e.jsx("p",{children:"This customer does not currently have an access policy."}),e.jsx(d,{appLink:{application:p.CUSTOMERS,action:u.Customers.EDIT_PILOT,args:[a.customerId]},className:"btn btn-outline-dark",children:"Select a policy"})]}):e.jsx(e.Fragment,{})}export{oe as AccessPolicyManagementView};
//# sourceMappingURL=_tdE-CCo.chunk.js.map
