import{ew as _,R as k,b as H,aw as Z,o as B,a4 as $,bi as s,j as e,ar as G,az as J,ax as y}from"./app-BgLa5dit.js";import{A as c}from"./CsH2Nu4a.chunk.js";import{D as K}from"./nLtuAPO5.chunk.js";import{u as Q}from"./DBvERro4.chunk.js";import{C as X}from"./xRXwFbQr.chunk.js";import{C as ee}from"./YSGwxiQJ.chunk.js";import{C as te}from"./Ceer3EzR.chunk.js";import{C as u,a as ae}from"./CmeGmsFm.chunk.js";import{C as se}from"./MzD4y3tN.chunk.js";import{A as ie}from"./uachN0F4.chunk.js";import{C as re}from"./BO07ARJN.chunk.js";import"./Zwjmkasg.chunk.js";import"./C9Rwpp7a.chunk.js";import"./-hEPHVQE.chunk.js";import"./DJ0pq8J_.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";import"./Bs6fQ2wT.chunk.js";import"./BUT90D7O.chunk.js";import"./C1fMRwzQ.chunk.js";import"./u6fIQ8Ti.chunk.js";const oe="_select_p17fs_1",ne={select:oe},p=new Date,le=new Date;function ce(){var D,T;const d=_(),[f,h]=k.useState(),{hasPermissions:g}=H(),t=Z(),x=B(ie.accessPolicies()),{customerFormationTemplates:C,isLoading:N}=Q(t.values.region,t.values.country,t.values.province),Y=!x.hasCompleted||N,E=C.find(a=>a.name===t.values.cft),i=u.getAllowedAccessPolicies({canManageAll:g($.CustomerAccessPolicyManageAll),policies:x.data,cft:E}),o=i==null?void 0:i.find(a=>a.id===t.values.trialId),v=u.mapPolicyType(o==null?void 0:o.type),F=v===c.Cft,P=((T=(D=o==null?void 0:o.argumentsSchema)==null?void 0:D.nextCft)==null?void 0:T.allowedValues)??[],I=C.filter(a=>P.includes(a.name))??[],S=i.find(a=>a.id===t.values.trialId)&&v!==c.Static,M=!!t.values.trialing&&!!t.values.accountId;function A(a){var w;const r=i==null?void 0:i.find(m=>m.id===a),n=u.mapPolicyType(r==null?void 0:r.type),l=(w=r==null?void 0:r.metadata)==null?void 0:w.duration,j=l?parseInt(l.split(".")[0],10):0,L=j?s.getUtcISOString(s.add(p,j,"day")):null,O=i.find(m=>m.id===a)&&n!==c.Static,W=n===c.Cft;t.setValues({...t.values,trialId:a,trialEndDate:L,trialEndDateRequired:O,trialNextCft:"",trialNextCftRequired:W})}function R(a){if(!a.target.value||!s.formatIsValid(a.target.value,"YYYY-MM-DD",!0)){d();return}const[r,n,l]=a.target.value.split("-").map(Number);p.setUTCFullYear(r,n-1,l),t.setFieldValue("trialEndDate",p.toISOString())}function b(a){t.setFieldValue("trialNextCft",a)}function V(a){h(a)}function z(){h(null)}const U=s.diffBetween(t.values.trialEndDate,le,"days"),q=s.format(t.values.trialEndDate,"DD MMM YYYY");return e.jsxs("div",{className:"crm-studio-wizard-form",children:[e.jsx(ee,{}),e.jsx("h1",{className:"h2 mb-3",children:"Is the customer on a pilot?"}),Y?e.jsx("div",{className:"d-flex justify-content-center align-items-center mb-4",children:e.jsx(G,{as:"div",animation:"border",role:"status"})}):e.jsxs(J,{children:[e.jsx(X,{fieldName:"hasTrial",disabled:M,onSelectNo:()=>{t.setValues({...t.values,hasTrial:!1,trialId:"",trialEndDate:null,trialEndDateRequired:!1,trialNextCft:"",trialNextCftRequired:!1})}}),t.values.hasTrial&&e.jsx("div",{className:ne.select,children:e.jsxs(y,{as:"select",label:"Access Policy",name:"trialId",id:"trialId",onChange:a=>A(a.target.value),children:[e.jsx("option",{value:"",children:"Select a policy"}),i.map(a=>e.jsx("option",{value:a.id,children:[a.description]},a.id))]})}),S&&e.jsxs("div",{children:[e.jsx("h2",{className:"h6",children:`This trial will last ${U} days and expire on ${q}`}),e.jsxs("div",{className:"d-flex",children:[e.jsx(K,{id:"policy-end-time",required:!0,value:t.values.trialEndDate?s.formatUtc(new Date(t.values.trialEndDate).getTime(),"YYYY-MM-DD"):"",min:s.formatToISODate(s.add(new Date,1,"day")),onChange:R}),t.values.trialEndDate&&e.jsxs("div",{className:"ms-3",children:[e.jsxs("p",{className:"mb-0",children:[s.format(t.values.trialEndDate,"D/M/YYYY, h:mm:ss a"),"  (",Intl.DateTimeFormat().resolvedOptions().timeZone," ",s.format(t.values.trialEndDate,"Z"),")"]}),e.jsxs("p",{className:"text-secondary",children:[s.formatUtc(new Date(t.values.trialEndDate).getTime(),"D/M/YYYY, h:mm:ss a"),"  (UTC ",s.formatUtc(new Date(t.values.trialEndDate).getTime(),"Z"),")"]})]})]})]}),F&&e.jsx(e.Fragment,{children:e.jsx(y,{type:"radio",name:"policy-next-cft",id:"policy-next-cft",children:()=>e.jsxs("div",{children:[e.jsx("h2",{className:"h5 mt-4",children:"Choose next CFT"}),e.jsx("label",{className:"mt-2 form-label d-block",htmlFor:"policy-next-cft",children:"This CFT will be applied to the customer when their trial expires"}),e.jsx(te,{customerFormationTemplates:I,onChangeCft:b,selectedCft:t.values.trialNextCft,showTemplatePreview:V})]})})})]}),f&&e.jsx(se,{previewTemplate:f,closeTemplatePreview:z})]})}function Se(d){return e.jsx(re,{queryParams:d.queryParams,currentStepId:ae.CUSTOMER_TRIAL,children:e.jsx(ce,{})})}export{Se as CustomerWizardTrialView};
//# sourceMappingURL=NdiWekSn.chunk.js.map
