import{aw as c,aT as u,j as n,az as x,T as g,at as f,b4 as p,dj as h,aA as d}from"./app-BgLa5dit.js";import{D as j}from"./C4BcftDO.chunk.js";function b(e){const a=c(),i=u.useRef(null),r=a.values.domains??[],o=e.organisationDomains??[],l=r.length>0||o.length>0;function s(){i.current&&i.current.value.trim()&&(a.setFieldValue("domains",[...r||[],i.current.value]),i.current.value="")}return n.jsx(x,{children:n.jsxs("div",{className:"mt-4 crm-studio-wizard-form",children:[n.jsxs("div",{className:"d-flex no-wrap mb-3",children:[n.jsx("input",{className:"form-control",placeholder:"Enter domain address",type:"text",ref:i,onKeyDown:t=>{t.key==="Enter"&&(s(),t.stopPropagation(),t.preventDefault())}}),n.jsx("button",{className:"btn btn-outline-dark ms-2 flex-shrink-0",onClick:s,children:"Add domain"})]}),l&&n.jsxs(n.Fragment,{children:[n.jsx(j,{disableCollapse:!0,heading:"Domains",children:n.jsxs("div",{className:"px-3 pt-3",children:[o.map(t=>n.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[n.jsx("div",{className:"d-flex align-items-center gap-2",children:n.jsx("span",{children:t})}),n.jsx(g,{title:"This domain is managed by an organisation",spanHack:!0,children:n.jsx("div",{className:"alert bg-light-orange px-2 py-0 m-0 rounded-5 text-primary cursor-default",children:"Organisation domain"})})]},t)),r.map(t=>n.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[n.jsx("div",{className:"d-flex align-items-center gap-2",children:n.jsx("span",{children:t})}),n.jsx(f,{svg:p,onClick:()=>{a.setFieldValue("domains",r.filter(m=>m!==t))}})]},t))]})}),a.errors.domains&&n.jsx("div",{className:"text-danger mb-3",children:a.errors.domains})]}),n.jsx(h,{disabled:e.isSaving||!a.dirty||!!a.errors.domains,showSpinner:e.isSaving,className:"btn btn-dark",variant:"dark",onClick:()=>{e.onSave(a.values)},children:"Save changes"})]})})}const v="^(?!-)(?:[A-Za-z0-9-]+(?<!-)|[A-Za-z0-9-]+(?<!-)(?:\\.[A-Za-z0-9-]+(?<!-))*\\.[A-Za-z]{2,})$",C=d.object().shape({domains:d.array().of(d.string().default("")).test("is-valid-domain","Invalid domain format",function(e){if(!e)return!0;const a=new RegExp(v);return e.every(r=>r&&a.test(r.trim()))?!0:this.createError({message:"Please enter a valid domain (e.g. example.com)"})}).test("no-duplicate-domains","Duplicate domains are not allowed",(e=[])=>new Set(e).size===e.length)}),y={getDomainChanges(e,a){const i=new Set((e||[]).map(s=>s.domain.toLowerCase())),r=new Set(a.map(s=>s.toLowerCase())),o=a.filter(s=>!i.has(s.toLowerCase())),l=(e||[]).filter(s=>!r.has(s.domain.toLowerCase()));return{additions:o,deletions:l}},filterOrganisationDomains(e){return(e==null?void 0:e.filter(a=>a.ownerType==="Organisation"))??[]},filterCustomerDomains(e){return(e==null?void 0:e.filter(a=>a.ownerType==="Customer"))??[]}};export{C as D,b as a,y as b};
//# sourceMappingURL=C3CE5EQd.chunk.js.map
