import{aw as v,ej as C,j as e,az as F,cD as L,H as h,k as P,o as g,e8 as f,l as w,e9 as A,G as y,aR as S}from"./app-BgLa5dit.js";import{O as G}from"./B-fq6xxv.chunk.js";import{E as M}from"./D-bfnq46.chunk.js";import{g as U}from"./DdbSDhh9.chunk.js";import{T as V}from"./lZO4aq5x.chunk.js";import"./C8_78Eqq.chunk.js";const x=C(),R={traffic:()=>x.accessor(n=>n,{id:"traffic",header:"Traffic from content region",cell:n=>{const o=n.getValue().trafficFrom.name;return e.jsx(e.Fragment,{children:o})},size:500}),actions:(n,o)=>x.accessor(a=>a,{id:"destination",header:"Dashboard region",cell:a=>{const s=a.getValue().destination.contentRegion,i=a.row.original.canUpdate,c=n.find(t=>t.contentRegion===h.GLOBAL);return e.jsx("div",{children:e.jsxs("select",{className:"form-select",value:s??"",disabled:!i,onChange:t=>{const l=t.target.value||null;o(a.row.index,l)},children:[e.jsx("option",{value:"",disabled:!0,children:"Select region"}),!c&&e.jsx("option",{value:null,children:"None"}),n.map(t=>e.jsx("option",{value:t.contentRegion,children:t.name},t.contentRegion))]})})},size:500})},k={table:"striped-list no-full-width pb-3",cell:"p-2",row:"striped-row rounded p-2"};function B(n){const{values:o,setFieldValue:a,isSubmitting:s,dirty:i}=v();function c(l,u){a(`mappings[${l}].destination.contentRegion`,u)}const t=[R.traffic(),R.actions(n.availableContentRegions,c)];return e.jsx(F,{children:e.jsxs("div",{className:"mt-3",children:[e.jsx(V,{data:o.mappings,columns:t,theme:k}),e.jsx(L,{className:"mt-3",type:"submit",disabled:!i||s,variant:"dark",children:"Save"})]})})}function _(n){var j;const o=P(),a=g(S.currentUser()),s=g(f.getContentPartner(n.contentPartnerId)),i=g(s.data&&f.getRegionsMapping(s.data._slug.value)),c=w(),t=U();async function l(r){const p=r.mappings.filter(d=>{var m;return d.canUpdate&&((m=d.destination)==null?void 0:m.contentRegion)!==void 0});try{await o(f.updateRegionsMapping(s.data._slug.value,p)),c.success("Successfully updated regions mapping")}catch{c.error("Failed to update regions mapping")}}const u=s.hasCompleted&&i.hasCompleted,b={mappings:[...((j=i.data)==null?void 0:j.mappings)||[]].sort((r,p)=>{const d=r.trafficFrom.contentRegion===h.GLOBAL,m=p.trafficFrom.contentRegion===h.GLOBAL;return d!==m?d?1:-1:r.trafficFrom.name.localeCompare(p.trafficFrom.name)})};return e.jsxs(e.Fragment,{children:[!!a.data&&e.jsx(M,{contentPartnerId:n.contentPartnerId,activeAction:t.viewRegionsMapping(n.contentPartnerId).action,currentUser:a.data}),(()=>{var r;return u?e.jsxs(e.Fragment,{children:[e.jsx(G,{object:{name:`${(r=s.data)==null?void 0:r.name} dashboard regions mapping`}}),e.jsx(y,{initialValues:b,onSubmit:l,children:e.jsx(B,{availableContentRegions:i.data.availableContentRegions})})]}):e.jsx(A,{})})()]})}export{_ as RegionsMappingView};
//# sourceMappingURL=CIsXjD20.chunk.js.map
