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-BlAQ7A1q.chunk.mjs";import{l as V,_ as j,r as i,o as n,c as r,e as b,f as g,h as F,a as l,t as R,F as k,i as w,j as z,d as G,L as q}from"./modulepreload-polyfill-CUNWF7kj.chunk.mjs";import{N as H}from"./index-BxnMnX_w.chunk.mjs";const{profileEnabled:B}=V("user_status","profileEnabled",!1),K={name:"ReadOnlyContactDetails",components:{ContactDetailsProperty:x,NcEmptyContent:N,IconContact:I,NcLoadingIcon:H},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:B,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("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,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(s=>new M(s.data,e)));this.contact=o.find(e=>e.hasEmail(a))}catch(a){z.error("Error fetching contact:",{error: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"}}},Q={class:"display-contact-details"},U={key:0,class:"recipient-details-loading"},J={key:2,class:"recipient-details-content"},W={class:"contact-title"},X=["innerHTML"],Y={class:"contact-details-wrapper"};function Z(a,o,e,c,s,u){const v=i("NcLoadingIcon"),A=i("IconContact"),D=i("NcEmptyContent"),E=i("ContactDetailsProperty");return n(),r("div",Q,[s.loading?(n(),r("div",U,[b(v)])):s.contact?(n(),r("div",J,[l("div",W,[l("h6",null,R(s.contact.fullName),1),l("span",{innerHTML:u.formattedSubtitle},null,8,X)]),l("div",Y,[(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 tt=j(K,[["render",Z],["__scopeId","data-v-6337267c"]]);window.OCA??={},window.OCA.Contacts={async mountContactDetails(a,o){const e=G(tt,{contactEmailAddress:o}),c=$();return e.use(c),e.use(T),e.mixin(q),e.mount(a),{$destroy:()=>e.unmount()}}};
//# sourceMappingURL=contacts-oca.mjs.map
