import{I as P,a as I,N,C as x,r as p,v as L,n as y,b as M,c as f,u as _,e as C,m as S,d as $,s as T}from"./style-BSeD2-8B.chunk.mjs";import{l as V,_ as j,r as i,c as r,o as s,f as b,h as g,i as F,a as l,t as R,F as k,j as w,e as z,L as G}from"./modulepreload-polyfill-DS8mCOmY.chunk.mjs";import{N as q}from"./index-BgGcM4Fs.chunk.mjs";const{profileEnabled:H}=V("user_status","profileEnabled",!1),B={name:"ReadOnlyContactDetails",components:{ContactDetailsProperty:x,NcEmptyContent:N,IconContact:I,NcLoadingIcon:q},mixins:[P],props:{contactEmailAddress:{type:String,required:!0},desc:{type:String,required:!1,default:""}},data(){return{contactDetailsSelector:".contact-details",excludeFromBirthdayKey:"x-nc-exclude-from-birthday-calendar",bus:S(),showMenuPopover:!1,profileEnabled:H,contact:void 0,localContact:void 0,loading:!0}},computed:{formattedSubtitle(){const a=this.contact.title,o=this.contact.org;return a&&o?t("contacts","{title} at {organization}",{title:a,organization:o}):a?C(a):o?C(o):""},addressbooks(){return this.$store.getters.getAddressbooks},sortedProperties(){return!this.localContact||!this.localContact.properties?[]:this.localContact.properties.toSorted((a,o)=>{const e=a.name.split(".").pop(),c=o.name.split(".").pop();return p.fieldOrder.indexOf(e)-p.fieldOrder.indexOf(c)})},groupedProperties(){return this.sortedProperties?this.sortedProperties.reduce((a,o)=>(this.canDisplay(o)&&(a[o.name]||(a[o.name]=[]),a[o.name].push(o)),a),{}):{}},addressbookIsReadOnly(){return this.contact.addressbook?.readOnly},addressbook(){return this.contact.addressbook.id},groupsModel(){return{readableName:t("mail","Contact groups"),icon:"icon-contacts-dark"}}},watch:{contact:{handler(a){this.updateLocalContact(a)},immediate:!0}},async beforeMount(){await f.connect({enableCardDAV:!0}),_().setCurrentUserPrincipal(f),await this.$store.dispatch("getAddressbooks"),await this.fetchContact()},methods:{async fetchContact(){try{const a=this.contactEmailAddress,o=(await Promise.all(this.addressbooks.map(async e=>[e.dav,await e.dav.addressbookQuery([{name:[y.IETF_CARDDAV,"prop-filter"],attributes:[["name","EMAIL"]],children:[{name:[y.IETF_CARDDAV,"text-match"],value:a}]}])]))).flatMap(([e,c])=>c.map(n=>new M(n.data,e)));this.contact=o.find(e=>e.email===a)}catch(a){console.error("Error fetching contact:",a)}finally{this.loading=!1}},updateGroups(a){this.newGroupsValue=a},async updateLocalContact(a){if(!a){this.localContact=void 0;return}const o=Object.assign(Object.create(Object.getPrototypeOf(a)),a);L(o),this.localContact=o,this.newGroupsValue=[...this.localContact.groups]},canDisplay(a){const o=p.properties[a.name.split(".").pop()],e=o&&o.force?o.force:a.getDefaultType();return o&&e!=="unknown"}}},K={class:"display-contact-details"},Q={key:0,class:"recipient-details-loading"},U={key:2,class:"recipient-details-content"},J={class:"contact-title"},W=["innerHTML"],X={class:"contact-details-wrapper"};function Y(a,o,e,c,n,u){const v=i("NcLoadingIcon"),A=i("IconContact"),D=i("NcEmptyContent"),O=i("ContactDetailsProperty");return s(),r("div",K,[n.loading?(s(),r("div",Q,[g(v)])):n.contact?(s(),r("div",U,[l("div",J,[l("h6",null,R(n.contact.fullName),1),l("span",{innerHTML:u.formattedSubtitle},null,8,W)]),l("div",X,[(s(!0),r(k,null,w(u.groupedProperties,(m,E)=>(s(),r("div",{key:E},[(s(!0),r(k,null,w(m,(h,d)=>(s(),b(O,{key:`${d}-${n.contact.key}-${h.name}`,"is-first-property":d===0,"is-last-property":d===m.length-1,property:h,contact:n.contact,"local-contact":n.localContact,contacts:[n.contact],"is-read-only":!0,bus:n.bus},null,8,["is-first-property","is-last-property","property","contact","local-contact","contacts","bus"]))),128))]))),128))])])):(s(),b(D,{key:1,class:"empty-content",name:a.t("mail","No data for this contact"),description:a.t("mail","No data for this contact on their profile")},{icon:F(()=>[g(A,{size:20})]),_:1},8,["name","description"]))])}const Z=j(B,[["render",Y],["__scopeId","data-v-aa0f2781"]]);window.OCA??={},window.OCA.Contacts={async mountContactDetails(a,o){const e=z(Z,{contactEmailAddress:o}),c=$();return e.use(c),e.use(T),e.mixin(G),e.mount(a),{$destroy:()=>e.unmount()}}};
//# sourceMappingURL=contacts-oca.mjs.map
