/*! third party licenses: js/vendor.LICENSE.txt */
import{l as h,n as y,V as s}from"./index-BIQI5yO2.chunk.mjs";import{z as f,h as C,k as b,J as g,u as d,N as l,R as w,a7 as p,r as v,K as O,a3 as k,a4 as A,a5 as D,w as E,a6 as P}from"./style-YTC9qpVd.chunk.mjs";import{o as _,q as x,M as N}from"./index-cVq2Y4_O.chunk.mjs";const u="contacts",m="7.0.0",{profileEnabled:I}=h("user_status","profileEnabled",!1),M={name:"ReadOnlyContactDetails",components:{ContactDetailsProperty:f,NcEmptyContent:_,IconContact:C,NcLoadingIcon:x},mixins:[b],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:g(),showMenuPopover:!1,profileEnabled:I,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||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(),r=o.name.split(".").pop();return d.fieldOrder.indexOf(e)-d.fieldOrder.indexOf(r)})},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 l.connect({enableCardDAV:!0}),w().setCurrentUserPrincipal(l),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:[p.IETF_CARDDAV,"prop-filter"],attributes:[["name","EMAIL"]],children:[{name:[p.IETF_CARDDAV,"text-match"],value:a}]}])]))).flatMap(([e,r])=>r.map(c=>new v(c.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);O(o),this.localContact=o,this.newGroupsValue=[...this.localContact.groups]},canDisplay(a){const o=d.properties[a.name.split(".").pop()],e=o&&o.force?o.force:a.getDefaultType();return o&&e!=="unknown"}}};var S=function(){var a=this,o=a._self._c;return o("div",{staticClass:"display-contact-details"},[a.loading?o("div",{staticClass:"recipient-details-loading"},[o("NcLoadingIcon")],1):a.contact?o("div",{staticClass:"recipient-details-content"},[o("div",{staticClass:"contact-title"},[o("h6",[a._v(a._s(a.contact.fullName))]),o("span",{domProps:{innerHTML:a._s(a.formattedSubtitle)}})]),o("div",{staticClass:"contact-details-wrapper"},a._l(a.groupedProperties,function(e,r){return o("div",{key:r},a._l(e,function(c,i){return o("ContactDetailsProperty",{key:`${i}-${a.contact.key}-${c.name}`,attrs:{"is-first-property":i===0,"is-last-property":i===e.length-1,property:c,contact:a.contact,"local-contact":a.localContact,contacts:[a.contact],"is-read-only":!0,bus:a.bus}})}),1)}),0)]):o("NcEmptyContent",{staticClass:"empty-content",attrs:{name:a.t("mail","No data for this contact"),description:a.t("mail","No data for this contact on their profile")},scopedSlots:a._u([{key:"icon",fn:function(){return[o("IconContact",{attrs:{size:20}})]},proxy:!0}])})],1)},V=[],L=y(M,S,V,!1,null,"19ba1512");const $=L.exports;function R(a,o){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($);return new r({pinia:e,store:P,propsData:{contactEmailAddress:o}}).$mount(a)}window.OCA??={},window.OCA.Contacts={async mountContactDetails(a,o){return R(a,o)}};
