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-hzRJFdl5.chunk.mjs";import{l as V,_ as j,r as i,o as n,c as r,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-CCS5MV5L.chunk.mjs";import{N as q}from"./index-B6CnDUoY.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,e=this.contact.org;return a&&e?t("contacts","{title} at {organization}",{title:a,organization:e}):a?C(a):e?C(e):""},addressbooks(){return this.$store.getters.getAddressbooks},sortedProperties(){return!this.localContact||!this.localContact.properties?[]:this.localContact.properties.toSorted((a,e)=>{const o=a.name.split(".").pop(),c=e.name.split(".").pop();return p.fieldOrder.indexOf(o)-p.fieldOrder.indexOf(c)})},groupedProperties(){return this.sortedProperties?this.sortedProperties.reduce((a,e)=>(this.canDisplay(e)&&(a[e.name]||(a[e.name]=[]),a[e.name].push(e)),a),{}):{}},addressbookIsReadOnly(){return this.contact.addressbook?.readOnly},addressbook(){return this.contact.addressbook.id},groupsModel(){return{readableName:t("contacts","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,e=(await Promise.all(this.addressbooks.map(async o=>[o.dav,await o.dav.addressbookQuery([{name:[y.IETF_CARDDAV,"prop-filter"],attributes:[["name","EMAIL"]],children:[{name:[y.IETF_CARDDAV,"text-match"],value:a}]}])]))).flatMap(([o,c])=>c.map(s=>new M(s.data,o)));this.contact=e.find(o=>o.hasEmail(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 e=Object.assign(Object.create(Object.getPrototypeOf(a)),a);L(e),this.localContact=e,this.newGroupsValue=[...this.localContact.groups]},canDisplay(a){const e=p.properties[a.name.split(".").pop()],o=e&&e.force?e.force:a.getDefaultType();return e&&o!=="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,e,o,c,s,u){const v=i("NcLoadingIcon"),A=i("IconContact"),D=i("NcEmptyContent"),E=i("ContactDetailsProperty");return n(),r("div",K,[s.loading?(n(),r("div",Q,[b(v)])):s.contact?(n(),r("div",U,[l("div",J,[l("h6",null,R(s.contact.fullName),1),l("span",{innerHTML:u.formattedSubtitle},null,8,W)]),l("div",X,[(n(!0),r(k,null,w(u.groupedProperties,(m,O)=>(n(),r("div",{key:O},[(n(!0),r(k,null,w(m,(h,d)=>(n(),g(E,{key:`${d}-${s.contact.key}-${h.name}`,"is-first-property":d===0,"is-last-property":d===m.length-1,property:h,contact:s.contact,"local-contact":s.localContact,contacts:[s.contact],"is-read-only":!0,bus:s.bus},null,8,["is-first-property","is-last-property","property","contact","local-contact","contacts","bus"]))),128))]))),128))])])):(n(),g(D,{key:1,class:"empty-content",name:a.t("contacts","No data for this contact"),description:a.t("contacts","No data for this contact on their profile")},{icon:F(()=>[b(A,{size:20})]),_:1},8,["name","description"]))])}const Z=j(B,[["render",Y],["__scopeId","data-v-d8147076"]]);window.OCA??={},window.OCA.Contacts={async mountContactDetails(a,e){const o=z(Z,{contactEmailAddress:e}),c=$();return o.use(c),o.use(T),o.mixin(G),o.mount(a),{$destroy:()=>o.unmount()}}};
//# sourceMappingURL=contacts-oca.mjs.map
