/*! third party licenses: js/vendor.LICENSE.txt */
import{l as h,n as y,V as s}from"./index-C7ej39AH.chunk.mjs";import{y as f,h as C,k as g,J as b,r as d,Q as l,T as w,a7 as p,p as v,K as O,a3 as k,a4 as A,a5 as D,u as E,a6 as P}from"./style-B0qoSIp8.chunk.mjs";import{m as _,o as x,K as N}from"./index-DUKigbdu.chunk.mjs";const u="contacts",m="7.2.2",{profileEnabled:I}=h("user_status","profileEnabled",!1),S={name:"ReadOnlyContactDetails",components:{ContactDetailsProperty:f,NcEmptyContent:_,IconContact:C,NcLoadingIcon:x},mixins:[g],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:b(),showMenuPopover:!1,profileEnabled:I,contact:void 0,localContact:void 0,loading:!0}},computed:{formattedSubtitle(){const o=this.contact.title,a=this.contact.org;return o&&a?t("contacts","{title} at {organization}",{title:o,organization:a}):o||a||""},addressbooks(){return this.$store.getters.getAddressbooks},sortedProperties(){return!this.localContact||!this.localContact.properties?[]:this.localContact.properties.toSorted((o,a)=>{const e=o.name.split(".").pop(),r=a.name.split(".").pop();return d.fieldOrder.indexOf(e)-d.fieldOrder.indexOf(r)})},groupedProperties(){return this.sortedProperties?this.sortedProperties.reduce((o,a)=>(this.canDisplay(a)&&(o[a.name]||(o[a.name]=[]),o[a.name].push(a)),o),{}):{}},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(o){this.updateLocalContact(o)},immediate:!0}},async beforeMount(){await l.connect({enableCardDAV:!0}),w().setCurrentUserPrincipal(l),await this.$store.dispatch("getAddressbooks"),await this.fetchContact()},methods:{async fetchContact(){try{const o=this.contactEmailAddress,a=(await Promise.all(this.addressbooks.map(async e=>[e.dav,await e.dav.addressbookQuery([{name:[p.IETF_CARDDAV,"prop-filter"],attributes:[["name","EMAIL"]],children:[{name:[p.IETF_CARDDAV,"text-match"],value:o}]}])]))).flatMap(([e,r])=>r.map(c=>new v(c.data,e)));this.contact=a.find(e=>e.email===o)}catch(o){console.error("Error fetching contact:",o)}finally{this.loading=!1}},updateGroups(o){this.newGroupsValue=o},async updateLocalContact(o){if(!o){this.localContact=void 0;return}const a=Object.assign(Object.create(Object.getPrototypeOf(o)),o);O(a),this.localContact=a,this.newGroupsValue=[...this.localContact.groups]},canDisplay(o){const a=d.properties[o.name.split(".").pop()],e=a&&a.force?a.force:o.getDefaultType();return a&&e!=="unknown"}}};var V=function(){var o=this,a=o._self._c;return a("div",{staticClass:"display-contact-details"},[o.loading?a("div",{staticClass:"recipient-details-loading"},[a("NcLoadingIcon")],1):o.contact?a("div",{staticClass:"recipient-details-content"},[a("div",{staticClass:"contact-title"},[a("h6",[o._v(o._s(o.contact.fullName))]),a("span",{domProps:{innerHTML:o._s(o.formattedSubtitle)}})]),a("div",{staticClass:"contact-details-wrapper"},o._l(o.groupedProperties,function(e,r){return a("div",{key:r},o._l(e,function(c,i){return a("ContactDetailsProperty",{key:`${i}-${o.contact.key}-${c.name}`,attrs:{"is-first-property":i===0,"is-last-property":i===e.length-1,property:c,contact:o.contact,"local-contact":o.localContact,contacts:[o.contact],"is-read-only":!0,bus:o.bus}})}),1)}),0)]):a("NcEmptyContent",{staticClass:"empty-content",attrs:{name:o.t("mail","No data for this contact"),description:o.t("mail","No data for this contact on their profile")},scopedSlots:o._u([{key:"icon",fn:function(){return[a("IconContact",{attrs:{size:20}})]},proxy:!0}])})],1)},L=[],M=y(S,V,L,!1,null,"4efee661");const T=M.exports;function $(o,a){s.use(k);const e=A();s.directive("ClickOutside",D),s.directive("Tooltip",N),s.prototype.t=t,s.prototype.n=n,s.prototype.appName=u,s.prototype.appVersion=m,s.prototype.logger=E,s.prototype.OC=window.OC,s.prototype.OCA=window.OCA;const r=s.extend(T);return new r({pinia:e,store:P,propsData:{contactEmailAddress:a}}).$mount(o)}window.OCA??={},window.OCA.Contacts={async mountContactDetails(o,a){return $(o,a)}};
//# sourceMappingURL=contacts-oca.mjs.map
