var S=Object.defineProperty;var $=(t,s,n)=>s in t?S(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var p=(t,s,n)=>$(t,typeof s!="symbol"?s+"":s,n);import{R as D,i as E}from"./index-BH4jUAKp.js";import{V as N,A as O,f as A,e as u,C as j,_ as U,g as w,h as r,i as _,j as l,m as k,o as V,k as x,l as g,t as f,F as b,z as I,p as R,x as c}from"./index-BLqts8WY.js";import{Q as T}from"./QuickNav-DgCyvgDx.js";import{E as B}from"./EntityIcon-CF1RwQI5.js";import{O as F}from"./OfferDialog-BFpCo0de.js";import{l as J,J as P,H as Q,K as M}from"./index-MyY_xqVN.js";import"./concat-BK8PKeDS.js";import"./sort-Dh4GzQVc.js";import"./index-CsfPLOYu.js";var H=Object.defineProperty,q=Object.getOwnPropertyDescriptor,z=(t,s,n,d)=>{for(var e=d>1?void 0:d?q(s,n):s,i=t.length-1,a;i>=0;i--)(a=t[i])&&(e=(d?a(s,n,e):a(e))||e);return d&&e&&H(s,n,e),e};let v=class extends N{constructor(){super(...arguments);p(this,"$notify");p(this,"AppString",O);p(this,"libsUtil",J);p(this,"R",D);p(this,"activeDid","");p(this,"apiServer","");p(this,"contactsExisting",{});p(this,"contactsImporting",[]);p(this,"contactsSelected",[]);p(this,"contactDifferences",{});p(this,"importing",!1);p(this,"makeVisible",!0);p(this,"sameCount",0)}async created(){var i;const n=await A();this.activeDid=n.activeDid||"",this.apiServer=n.apiServer||"";const d=this.$route.query.contacts;d&&await this.setContactsSelected(JSON.parse(d));const e=(i=window.location.pathname.match(/\/contact-import\/(ey.+)$/))==null?void 0:i[1];if(e){const a=await P(e);await this.setContactsSelected(a.payload.contacts)}}async setContactsSelected(n){this.contactsImporting=n,this.contactsSelected=new Array(this.contactsImporting.length).fill(!0),await u.open();const d=await u.contacts.toArray();for(let e=0;em.did===i.did);if(a){this.contactsExisting[i.did]=a;const m={};Object.keys(i).forEach(o=>{i[o]!==a[o]&&(m[o]={old:a[o],new:i[o]})}),this.contactDifferences[i.did]=m,E(m)&&this.sameCount++,this.contactsSelected[e]=!1}}}async importContacts(){this.importing=!0;let n=0,d=0;for(let e=0;ei.name).join(", ")}`},-1)}this.importing=!1,this.$notify({group:"alert",type:"success",title:"Imported",text:`${n} contact${n==1?"":"s"} imported.`+(d?` ${d} updated.`:"")},3e3),this.$router.push({name:"contacts"})}};v=z([j({components:{EntityIcon:B,OfferDialog:F,QuickNav:T}})],v);const K={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},L={class:"text-lg text-center font-light relative px-7"},Y={key:0,class:"flex justify-center"},G={key:1},W={key:0},X={key:1},Z={key:2,class:"border-t border-slate-300"},tt={key:0,class:"grow overflow-hidden border-b border-slate-300 pt-2.5 pb-4"},et={class:"text-base font-semibold"},st=["onUpdate:modelValue"],it={key:0,class:"text-orange-500"},ot={key:1,class:"text-green-500"},nt={class:"text-sm truncate"},at={key:0},ct={class:"border p-1"},rt={class:"border p-1"},lt={class:"border p-1"},dt={key:3};function pt(t,s,n,d,e,i){const a=w("QuickNav"),m=w("fa");return c(),r(b,null,[_(a,{selected:"Contacts"}),l("section",K,[l("div",L,[l("h1",{class:"text-lg text-center px-2 py-1 absolute -left-2 -top-1",onClick:s[0]||(s[0]=o=>t.$router.back())},[_(m,{icon:"chevron-left",class:"fa-fw"})])]),s[5]||(s[5]=l("h1",{id:"ViewHeading",class:"text-4xl text-center font-light pt-4 mb-8"}," Contact Import ",-1)),t.contactsImporting.length>t.sameCount?(c(),r("span",Y,[k(l("input",{type:"checkbox","onUpdate:modelValue":s[1]||(s[1]=o=>t.makeVisible=o),class:"mr-2"},null,512),[[V,t.makeVisible]]),s[3]||(s[3]=x(" Make my activity visible to these contacts. "))])):g("",!0),t.sameCount>0?(c(),r("div",G,[t.sameCount==1?(c(),r("span",W,"One contact is the same as an existing contact")):(c(),r("span",X,f(t.sameCount)+" contacts are the same as existing contacts",1))])):g("",!0),t.contactsImporting.length>t.sameCount?(c(),r("ul",Z,[(c(!0),r(b,null,I(t.contactsImporting,(o,y)=>(c(),r("li",{key:o.did},[!t.contactsExisting[o.did]||!t.R.isEmpty(t.contactDifferences[o.did])?(c(),r("div",tt,[l("h2",et,[k(l("input",{type:"checkbox","onUpdate:modelValue":h=>t.contactsSelected[y]=h},null,8,st),[[V,t.contactsSelected[y]]]),x(" "+f(o.name||t.AppString.NO_CONTACT_NAME)+" - ",1),t.contactsExisting[o.did]?(c(),r("span",it,"Existing")):(c(),r("span",ot,"New"))]),l("div",nt,f(o.did),1),t.contactDifferences[o.did]?(c(),r("div",at,[l("div",null,[s[4]||(s[4]=l("div",{class:"grid grid-cols-3 gap-2"},[l("div",{class:"font-bold"},"Field"),l("div",{class:"font-bold"},"Old Value"),l("div",{class:"font-bold"},"New Value")],-1)),(c(!0),r(b,null,I(t.contactDifferences[o.did],(h,C)=>(c(),r("div",{key:C,class:"grid grid-cols-3 border"},[l("div",ct,f(C),1),l("div",rt,f(h.old),1),l("div",lt,f(h.new),1)]))),128))])])):g("",!0)])):g("",!0)]))),128)),t.importing?(c(),R(m,{key:0,icon:"spinner",class:"animate-spin"})):(c(),r("button",{key:1,class:"bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-sm text-white mt-2 px-2 py-1.5 rounded",onClick:s[2]||(s[2]=(...o)=>t.importContacts&&t.importContacts(...o))}," Import Selected Contacts "))])):(c(),r("p",dt,"There are no contacts to import."))])],64)}const kt=U(v,[["render",pt]]);export{kt as default};