const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./AdminPageWrapper-CE0JnInN.mjs","./AdminToolbar-DYTQfbLP.mjs","./CmnEfQIC.js","./entry.Czs9t7YV.css","./AdminButtonElement-BgARiw82.mjs","./AdminButtonElement.BRDNsFha.css","./AdminFormSelect-CJPfN7ok.mjs","./WebSearchFilterCount-BAo3tYv2.mjs","./WebSearchFilterCount.Dg-IpFLX.css","./vue-select-X0cl5iEg.mjs","./vue-select.Bsn8s1tw.css","./FieldBase_String-DIrYardi.mjs","./FieldBase-BNePpS9o.mjs","./AdminFormSelect.CLXsa__g.css","./WebSearchField-CImNmY9x.mjs","./WebSearchField.B0k4fZ6M.css","./Modal-CZRoBy2z.mjs","./Modal.BoAUBYby.css","./AdminToolbar.zexZRxD0.css","./AdminPageTitle-CPIx4trP.mjs","./AdminPageTitle.DCYMXW2Y.css","./AdminPageWrapper.DYQy1xNV.css"])))=>i.map(i=>d[i]);
import{_ as w,o as d,c as p,a as g,d as _,y as L,F as A,x as D,l as b,f as S,A as k,H as E,g as U,s as I,bV as v,q as C,b as B,K as q,L as M,t as P}from"./CmnEfQIC.js";import V from"./AdminForm-CeowrVBG.mjs";import{u as F,_ as $}from"./AdminButtonElement-BgARiw82.mjs";import H from"./AdminPod-D3XNJic3.mjs";import{_ as R}from"./AdminProgressBar-CHUCFDtU.mjs";import{_ as N}from"./Modal-CZRoBy2z.mjs";import{P as W}from"./papaparse.min-D3DSYzL0.mjs";import{u as z}from"./useCsv-DHWPJRba.mjs";import"./AdminFormFieldGroup-CyIOZpcq.mjs";import"./clone-BmrnTZfT.mjs";import"./_Uint8Array-BPt7-PLz.mjs";const O={props:{messages:{type:Array},type:{type:String}}},K={key:0,class:"messages"},j={key:0},G={key:1},J=["innerHTML"],Q={key:0,class:"message"},X=["innerHTML"];function Y(t,o,e,r,s,n){const l=S;return e.messages.length?(d(),p("div",K,[g("div",{class:L(["header",e.type])},[_(l,{icon:e.type==="error"?"mdi:alert":"mdi:success","icon-color":e.type==="error"?"ba3329":"green",class:"icon",width:16},null,8,["icon","icon-color"]),e.type==="error"?(d(),p("span",j,"There were errors submitting some items.")):(d(),p("span",G,"The following items successfully submitted."))],2),(d(!0),p(A,null,D(e.messages,a=>(d(),p("div",{key:a,class:"content"},[g("strong",{innerHTML:a.title},null,8,J),a.message?(d(),p("div",Q,[g("div",null,[g("em",{innerHTML:a.message},null,8,X)])])):b("",!0)]))),128))])):b("",!0)}const Z=w(O,[["render",Y],["__scopeId","data-v-1acbc9ba"]]),ee=q(()=>M(()=>import("./AdminPageWrapper-CE0JnInN.mjs"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]),import.meta.url).then(t=>t.default||t)),te={data(){return{processing:!1,bulkErrors:[],bulkSuccess:[],type:"Promotion",fileContents:"",showProgress:!1,progress:{}}},computed:{notes(){const t=[{name:"ID",text:"The CMS ID of the content item (optional)."},{name:"Client",text:"A string represented the Client that will be returned in the output csv."},{name:"Title",text:"The content headline."},{name:"Teaser Text",text:"The teaser text of the content item."},{name:"Tags",text:"A comma delimited list of taxonomy terms to attach to the content item."},{name:"Image URL",text:"A publicly available url of an image to be used as the content's primary image."}];return this.type==="Promotion"&&t.push({name:"URL",text:"The URL the Promotion redirects to."}),t},adminStyles(){return F()}},methods:{updateFileContents(t,o){this.fileContents=o.file},async submitImportForm(){this.showProgress=!0,this.processing=!0,this.bulkErrors=[],this.bulkSuccess=[];const o=W.parse(this.fileContents,{header:!0}).data.filter(r=>r.Title&&(r==null?void 0:r.Status)!=="PASS"),e=[];{const r=[],s=[];let n=0;const l=o.length;this.progress={currentItem:n,totalItems:l,passed:s,failed:r};const a=await this.$gql.queryStream("getWebsiteSectionsHierarchy"),u=a.data.items.find(c=>c.name==="Resources"),m=a.data.items.find(c=>c.name==="Home"),y=(u==null?void 0:u.id)??(m==null?void 0:m.id),h=5;for(let c=1;c<=Math.ceil(o.length/h);c++){const i=o.slice((c-1)*h,c*h),x=[];for(const T in i){const f=i[T];x.push(this.processItem(f,y))}await Promise.all(x).then(T=>{T.forEach(f=>{f.error?(r.push(f.data.message),this.bulkErrors.push(f.data)):(e.push(f.data.item),this.bulkSuccess.push(f.data),s.push(f.title)),n+=1})}),this.progress={currentItem:n,totalItems:l,passed:s,failed:r}}e.length&&this.csvExport(e),this.bulkErrors.length===0?k.success("All items submitted succesfully."):k.error("Some items did not import successfully.")}this.processing=!1},async processItem(t,o){var a,u,m,y,h,c;const e={blueConic:!0,primarySection:o};if(t!=null&&t.ID){const i=await this.$gql.query("getContent",{id:parseInt(t.ID)});if(!i.error&&((a=i==null?void 0:i.data)!=null&&a.id))e.id=parseInt(t.ID);else return{error:!0,data:{title:t.Title,message:`Content item ${t.ID} not found.`}}}const r=t.Tags?await this.getTagIds(t.Tags.split(",")):[];e.name={value:t.Title},e.teaser=t["Teaser Text"]?{value:t["Teaser Text"]}:null,e.taxonomy=r?{action:"set",values:r}:null,e.body={value:""},e.bodyBlocks=[],e.status=1,e.primarySection=o,e.linkUrl=t.URL,e.crawlUrl=t.URL,t.ID?e.id=parseInt(t.ID):e.published=new Date().getTime();const s=await this.$gql.query("crawlPage",{crawlUrl:e.crawlUrl});(u=s==null?void 0:s.data)!=null&&u.body&&(e.body={value:(m=s==null?void 0:s.data)==null?void 0:m.body}),e.body.value&&(e.bodyBlocks=[{type:"text",settings:{text:e.body.value}}]),(y=s==null?void 0:s.data)!=null&&y.teaser&&(e.teaser={value:(h=s==null?void 0:s.data)==null?void 0:h.teaser});const n=t["Image URL"]??((c=s==null?void 0:s.data)==null?void 0:c.primaryImage);if(n){const i=await this.createAsset(n);i.error||(e.images={action:"set",values:[i.data.id]},e.primaryImage=i.data.id)}const l=await this.$gql.mutate("content/setPromotion",{input:e});return l.error?{error:!0,data:{title:t.Title,message:l.message}}:{error:!1,data:{title:`${t.Title}<br/><a target="_blank" href="/${l.data.id}">VIEW</a> | <a target="_blank" href="/admin/edit-content/${l.data.id}">EDIT</a> | ${e.body.value?'<span style="color:green;">CRAWLED</span>':'<span style="color:red;">NOT CRAWLED</span>'}`,item:{...t,ID:l.data.id},client:t.Client,message:""}}},csvExport(t){const o=E(Date.now(),"MM-dd-yyyy");z.createFile(t,["ID","Client","Title","Teaser Text","Tags","Image URL","URL"],`Bulk-Promotions-Import-Results-${this.$ss.general.rootDomain}-${o}.csv`)},async getTagIds(t){var r;const o=U("allTags",()=>({})),e=[];for(let s=0;s<t.length;s+=1){const n=t[s].trim();if((r=o.value)!=null&&r[n])e.push(o.value[n]);else{const l={phrase:n,limit:100,includeTypes:["Tag"],position:"exact"},a=await this.$gql.queryStream("matchTaxonomyStream",l);if(a.data.items.length)e.push(a.data.items[0].id),o.value[n]=a.data.items[0].id;else{const u={name:n,type:"Tag"},m=await this.$gql.mutate("setTaxonomy",u);m.error||(e.push(parseInt(m.data.id)),o.value[n]=m.data.id)}}}return e},async createAsset(t){const o=t.split("?")[0].split("/").slice(-1)[0].split(".")[0];return await this.$gql.mutate("setAssetImage",{input:{name:o,sourceURL:t,approvedWebsite:!0}})},closeProgress(){this.showProgress=!1}}},se={class:"bulk-content-update"},oe={class:"pod"},ne={class:"notes"},ae={class:"name"},re={class:"actions"},ie={key:1,class:"bulk-website-schedule-actions"};function le(t,o,e,r,s,n){const l=V,a=$,u=Z,m=H,y=ee,h=R,c=N;return d(),p("div",se,[_(y,{title:"Bulk Promotion Update","title-icon":"mdi:database",processing:s.processing},{contentrightmid:I(()=>[g("div",oe,[_(m,null,{default:I(()=>[o[0]||(v(-1,!0),(o[0]=_(l,{fields:{file:{type:"file_input",label:"File (CSV)"}},onChangeValue:n.updateFileContents},null,8,["onChangeValue"])).cacheIndex=0,v(1),o[0]),g("div",ne,[o[1]||(o[1]=C(" Expected file format:")),o[2]||(o[2]=g("br",null,null,-1)),o[3]||(o[3]=g("br",null,null,-1)),(d(!0),p(A,null,D(n.notes,i=>(d(),p("div",{key:i,class:"note"},[g("div",ae,P(i.name),1),C(" "+P(i.text),1)]))),128))]),g("div",re,[_(a,{color:n.adminStyles.primaryColor,label:"Import",disabled:!s.fileContents||!s.type,onClick:n.submitImportForm},null,8,["color","disabled","onClick"])]),_(u,{type:"error",messages:s.bulkErrors},null,8,["messages"]),_(u,{type:"success",messages:s.bulkSuccess},null,8,["messages"])]),_:1})])]),_:1},8,["processing"]),_(c,{show:s.progress.totalItems>0&&s.showProgress,"max-width":"500px",title:"Updating Content","allow-close":!1,"on-close":n.closeProgress,"overflow-y":"auto"},{default:I(()=>[s.progress.totalItems>0?(d(),B(h,{key:0,"current-item":s.progress.currentItem,"total-items":s.progress.totalItems,passed:s.progress.passed,failed:s.progress.failed},null,8,["current-item","total-items","passed","failed"])):b("",!0),s.progress.totalItems===s.progress.currentItem?(d(),p("div",ie,[_(a,{label:"Done",onClick:n.closeProgress},null,8,["onClick"])])):b("",!0)]),_:1},8,["show","on-close"])])}const Te=w(te,[["render",le]]);export{Te as default};