import{k as L,l as F,ew as V,R as c,o,c2 as _,g as q,h as m,i as l,j as t,Y as u,bi as a}from"./app-BgLa5dit.js";import{A as Z}from"./B6D3K4Nu.chunk.js";import{S as H}from"./BixyE8L-.chunk.js";import{A as D}from"./CsH2Nu4a.chunk.js";import{D as B}from"./nLtuAPO5.chunk.js";import{C as G}from"./C2cKa2R1.chunk.js";import{C as J,a as W}from"./8iu0vnCW.chunk.js";import{A as p}from"./uachN0F4.chunk.js";import{C as P}from"./q-IBKcuF.chunk.js";import{S as $}from"./DeGPZXe2.chunk.js";import{m as z}from"./CgJlvU9K.chunk.js";import"./3nM7jLnE.chunk.js";import"./CPXlV0fg.chunk.js";import"./ChrB5FYK.chunk.js";import"./DR2FaZH9.chunk.js";import"./KUnagq9Z.chunk.js";import"./DULWIWQR.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.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 Yt(e){var y,I,S,j;const E=L(),h=F(),f=V(),s=c.useRef(null),[C,g]=c.useState(!1),Y=o(P.customer(e.customerId)),i=o(p.customerAccessPolicy(e.customerId)),N=o(p.accessPolicies()),d=o($.customerSettings(e.customerId)),n=o(P.getCustomerProducts(e.customerId)),O=z((y=i.data)==null?void 0:y.type),A=[D.Timed,D.Cft].includes(O);function R(r){if(!r.target.value||!a.formatIsValid(r.target.value,"YYYY-MM-DD",!0))return;const[U,k,w]=r.target.value.split("-").map(Number),b=new Date(s.current.getTime());b.setUTCFullYear(U,k-1,w),s.current=b,g(!0),f()}function v(){const r=p.setTrialEndDate(e.customerId,s.current.toISOString());E(r).then(()=>{g(!1),h.success("Successfully updated the pilot end date")}).catch(()=>h.error(`Just your ol' fashioned "Something went wrong"`))}const x=d.data?(I=d.data[H.PolicyEndTime])==null?void 0:I.value:null;c.useEffect(()=>{s.current=new Date(x),f()},[x]);const M=Y.hasCompleted&&i.hasCompleted&&N.hasCompleted&&d.hasCompleted&&n.hasCompleted,T=(S=n==null?void 0:n.data)==null?void 0:S.some(r=>r.id===_.Online);return c.useEffect(()=>{T&&q.trigger({application:l.CRM_STUDIO,action:m.CrmStudio.CUSTOMER_OVERVIEW,args:[e.customerId]},{replace:!0})},[T,e.customerId]),t.jsx(J,{view:W.Customers,children:t.jsx(G,{title:"Pilot",currentTabId:"pilot",id:e.customerId,loading:!M,children:i.data?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-1",children:[t.jsx("label",{children:"Name:"})," ",i.data.id]}),t.jsxs("div",{className:"mb-1",children:[t.jsx("label",{children:"Description:"})," ",i.data.description]}),(j=i.data.arguments)!=null&&j.nextCft?t.jsxs("div",{className:"mb-1",children:[t.jsx("label",{children:"Next CFT:"})," ",i.data.arguments.nextCft]}):null,t.jsx(u,{appLink:{application:l.CRM_STUDIO,action:m.CrmStudio.EDIT_PILOT,args:[e.customerId]},className:"btn btn-outline-dark me-2",children:"Change pilot"}),t.jsx(u,{appLink:{application:l.CRM_STUDIO,action:m.CrmStudio.REMOVE_PILOT,args:[e.customerId]},className:"btn btn-link text-danger me-3",children:"End pilot"}),A&&s.current&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"mt-4 h5",children:"Pilot end date"}),t.jsxs("div",{className:"mb-3",children:[t.jsxs("p",{className:"mb-0",children:[a.format(s.current,"D/M/YYYY, h:mm:ss a"),"  (",Intl.DateTimeFormat().resolvedOptions().timeZone," ",a.format(s.current,"Z"),")"]}),t.jsxs("p",{className:"text-secondary",children:[a.formatUtc(s.current.getTime(),"D/M/YYYY, h:mm:ss a"),"  (UTC ",a.formatUtc(s.current.getTime(),"Z"),")"]}),t.jsx(B,{containerClassName:"d-flex",id:"policy-end-time",value:a.formatUtc(s.current.getTime(),"YYYY-MM-DD"),min:a.formatToISODate(a.add(new Date,1,"day")),onChange:R})]}),t.jsx("button",{className:`btn btn-outline-dark ${C?"":"disabled"}`,disabled:!C,onClick:v,children:"Update end time"})]})]}):t.jsxs("div",{className:"d-flex flex-column align-items-start gap-4",children:[t.jsx(Z,{variant:"warning",children:"This customer is currently not on a pilot."}),t.jsx(u,{appLink:{application:l.CRM_STUDIO,action:m.CrmStudio.EDIT_PILOT,args:[e.customerId]},className:"btn btn-dark",children:"Start a pilot"})]})})})}export{Yt as CustomerPilotView};
//# sourceMappingURL=Dbn_6gMU.chunk.js.map
