import{a3 as e,k as a,ay as t,aT as i}from"./vendor-element-plus.js?ver=3.1.8";import{c0 as o,b$ as s,aQ as n,W as c,X as l,Z as m,ab as r,a5 as d,a9 as p,aa as y,a6 as u,Y as _,a8 as h,$ as f,J as w,az as v,ay as k,a0 as g}from"./vendor.js?ver=3.1.8";import{i as b,j as C}from"./data_config.js?ver=3.1.8";import{C as $,a as D}from"./CompanyEditForm.js?ver=3.1.8";import{_ as S,I as q}from"./fc-bits-ui.js?ver=3.1.8";import{B as E}from"./BaseCard.js?ver=3.1.8";const x={name:"CompanyInfoSide",components:{BaseCard:E,Icons:q,CustomFieldsForm:D,CompanyEditForm:$,Edit:e},emits:["companyUpdated","companyCreated","cancel","drawerStateChanged"],props:{company:{type:Object,default:()=>null},photo_holder:{type:String,default:"fcrm_photo_holder_mini"},is_drawer:{type:Boolean,default:!1},hide_drawer_footer:{type:Boolean,default:!1},intended_contact_id:{type:Number,default:null}},data:()=>({direction:"rtl",model:{},isDirty:!1,appReady:!1,updating:!1,isHeaderEditing:!1,showSummaryEditDrawer:!1}),watch:{model:{handler(e,a){this.appReady&&(this.isDirty=!0)},deep:!0},isDirty(){this.emitDrawerState()},updating(){this.emitDrawerState()}},computed:{domainName(){return C(this.company.website)},ownerDisplayName(){return this.company.owner&&(this.company.owner.full_name||this.company.owner.email)||"--"},quickStats(){return[{label:this.$t("Owner"),value:"--"!==this.ownerDisplayName?this.ownerDisplayName:"",icon:"owner"},{label:this.$t("Industry"),value:this.company.industry,icon:"industry"},{label:this.$t("Type"),value:this.company.type,icon:"type"},{label:this.$t("Employees"),value:this.company.employees_number&&"0"!=this.company.employees_number?this.company.employees_number:"",icon:"employees"}].filter(e=>e.value)},profileAddressLines(){const e=[[this.company.city,this.company.state].filter(Boolean).join(", "),this.company.postal_code].filter(Boolean).join(" ");return[this.company.address_line_1,this.company.address_line_2,e,this.company.country?this.getCountryName(this.company.country):""].filter(Boolean)},socialLinks(){return[{label:this.$t("LinkedIn"),url:this.company.linkedin_url,icon:"linkedin"},{label:this.$t("X"),url:this.company.twitter_url,icon:"x"},{label:this.$t("Facebook"),url:this.company.facebook_url,icon:"facebook"}].filter(e=>e.url)}},mounted(){window.fcAdmin&&window.fcAdmin.is_rtl&&(this.direction="ltr")},methods:{updateAvatar(e){this.company.id?this.updateProperty("logo",e):this.model.logo=e},updateProperty(e,a,t){this.$put("companies/companies-property",{property:e,companies:[this.company.id],value:a}).then(i=>{this.$notify.success(i.message),this.company[e]=a,"logo"===e&&(this.model.logo=a),t&&t(i)}).catch(e=>{this.handleError(e)}).finally(()=>{this.updating=!1})},applyCompanySaveResponse(e){this.each(this.model,(e,a)=>{this.company[a]=e}),e.update_data&&this.each(e.update_data,(e,a)=>{this.company[a]=e}),e.company&&(this.each(e.company,(e,a)=>{this.company[a]=e}),this.model.logo=this.company.logo),e.updated_logo&&(this.company.logo=e.updated_logo,this.model.logo=e.updated_logo),this.syncCustomValues(e.company)},syncCustomValues(e){const a=o(this.model.custom_values)&&!s(this.model.custom_values)?this.model.custom_values:{};o(this.company.meta)&&!s(this.company.meta)||(this.company.meta={}),this.company.meta.custom_values=a,e&&(o(e.meta)&&!s(e.meta)||(e.meta={}),e.meta.custom_values=a)},updateInfo(){this.updating=!0;const e=!this.company.id;e&&(this.company.id=0,this.intended_contact_id&&(this.model.intended_contact_id=this.intended_contact_id)),this.$put(`companies/${this.company.id}`,this.model).then(a=>{this.$notify.success(a.message),this.applyCompanySaveResponse(a),e?this.$emit("companyCreated",a.company):this.$emit("companyUpdated",a.company)}).catch(e=>{this.handleError(e)}).finally(()=>{this.updating=!1})},openSummaryEditDrawer(){this.showSummaryEditDrawer=!0},closeSummaryEditDrawer(){this.showSummaryEditDrawer=!1},saveSummaryFromDrawer(){this.updating=!0;const e=!this.company.id;e&&(this.company.id=0,this.intended_contact_id&&(this.model.intended_contact_id=this.intended_contact_id)),this.model.logo=this.company.logo,this.$put(`companies/${this.company.id}`,this.model).then(a=>{this.$notify.success(a.message),this.applyCompanySaveResponse(a),e?this.$emit("companyCreated",a.company):this.$emit("companyUpdated",a.company),this.isDirty=!1,this.showSummaryEditDrawer=!1}).catch(e=>{this.handleError(e)}).finally(()=>{this.updating=!1})},getFormattedAddress:b,getCountryName(e){var a;if(!e)return"";const t=null==(a=this.appVars.countries)?void 0:a.find(a=>a.code===e);return t?t.title:e},reFetchLogo(){this.updating=!0,this.updateProperty("refetch_logo",this.company.website,e=>{e.updated_logo&&(this.company.logo=e.updated_logo,this.model.logo=e.updated_logo)})},handleCancel(){this.is_drawer&&this.$emit("cancel")},emitDrawerState(){this.is_drawer&&this.$emit("drawerStateChanged",{isDirty:this.isDirty,updating:this.updating})}},created(){var e,a;const t=this.company;this.model={owner_id:t.owner_id,name:t.name,logo:t.logo,email:t.email,phone:t.phone,website:t.website,industry:t.industry,type:t.type,address_line_1:t.address_line_1,address_line_2:t.address_line_2,city:t.city,state:t.state,employees_number:t.employees_number&&"0"!=t.employees_number?t.employees_number:"",postal_code:t.postal_code,country:t.country,description:t.description,linkedin_url:t.linkedin_url,twitter_url:t.twitter_url,facebook_url:t.facebook_url,custom_values:o(null==(e=t.meta)?void 0:e.custom_values)&&!s(null==(a=t.meta)?void 0:a.custom_values)?t.meta.custom_values:{}},this.$nextTick(()=>{this.appReady=!0,this.emitDrawerState()})}},A={key:0,class:"fcrm_company_drawer_main"},F={class:"fcrm_company_create_body"},L={key:0,class:"fcrm_company_drawer_footer"},N={class:"fcrm_company_drawer_footer_actions"},j={key:1,class:"fcrm_view_mode"},B={class:"fcrm_view_sections"},I={class:"icon"},z={class:"fcrm_view_section"},V={class:"fcrm_view_section_body"},U={class:"fcrm_company_quick_view"},R={class:"fcrm_company_quick_hero"},P={key:0,width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true"},H={class:"fcrm_company_quick_identity"},T={class:"fcrm_company_quick_contacts"},O=["href"],W=["href"],X={key:0,class:"fcrm_company_quick_stats"},Z={class:"icon"},G={class:"fcrm_company_quick_stat_text"},J={key:1,class:"fcrm_company_quick_stat"},M={class:"icon"},Q={class:"fcrm_company_quick_stat_text"},Y=["href"],K={class:"fcrm_company_quick_panel fcrm_pb_0"},ee={class:"fcrm_company_quick_panel_head"},ae={key:0,class:"fcrm_company_quick_description"},te={key:1,class:"fcrm_company_quick_empty"},ie={class:"fcrm_company_quick_panel fcrm_pb_0"},oe={class:"fcrm_company_quick_panel_head"},se={key:0,class:"fcrm_company_quick_address"},ne={key:1,class:"fcrm_company_quick_empty"},ce={class:"fcrm_company_quick_panel fcrm_pb_0"},le={class:"fcrm_company_quick_panel_head"},me={key:0,class:"fcrm_company_quick_socials"},re=["href"],de={key:0,class:"icon"},pe={key:1,class:"fcrm_company_quick_empty"},ye={class:"fcrm_company_quick_custom"},ue={class:"fcrm_company_quick_panel_head"},_e={class:"icon"},he={class:"fcrm_view_cf_wrap"},fe={key:0,class:"fcrm_drawer_content"},we={class:"fcrm_drawer_body fcrm_company_summary_body"},ve={class:"fcrm_company_summary_footer_actions"},ke={key:0,class:"fcrm_view_save_wrap"};const ge=S(x,[["render",function(e,o,s,b,C,$){const D=n("CustomFieldsForm"),S=n("company-edit-form"),q=a,E=n("Icons"),x=n("BaseCard"),ge=i,be=n("router-link"),Ce=t;return c(),l("div",{class:g([{fcrm_company_in_drawer:s.is_drawer,fcrm_company_unsaved:C.isDirty||!s.company.id},"fcrm_company_info_wrapper"])},[!s.is_drawer||s.company.id&&!C.isHeaderEditing?(c(),l("div",j,[m("div",B,[r(x,{"no-body-padding":!0},{title:d(()=>[m("h4",null,y(e.$t("Company Summary")),1)]),header_action:d(()=>[r(q,{size:"small",onClick:o[1]||(o[1]=e=>$.openSummaryEditDrawer())},{default:d(()=>[m("span",I,[r(E,{"icon-name":"EditPen"})]),p(" "+y(e.$t("Edit")),1)],void 0,!0),_:1})]),body:d(()=>[m("div",z,[m("div",V,[m("div",U,[m("section",R,[m("div",{class:"fcrm_company_quick_logo",style:f({backgroundImage:s.company.logo?"url("+s.company.logo+")":""})},[s.company.logo?h("",!0):(c(),l("svg",P,[...o[8]||(o[8]=[m("path",{d:"M12 2L2 7V22H22V7L12 2Z",fill:"white",opacity:"0.3"},null,-1),m("rect",{x:"5",y:"10",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"9",y:"10",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"13",y:"10",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"17",y:"10",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"5",y:"14",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"9",y:"14",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"13",y:"14",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"17",y:"14",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"5",y:"18",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"9",y:"18",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"13",y:"18",width:"2.5",height:"2.5",fill:"white"},null,-1),m("rect",{x:"17",y:"18",width:"2.5",height:"2.5",fill:"white"},null,-1)])]))],4),m("div",H,[m("h3",null,y(s.company.name),1),m("div",T,[s.company.email?(c(),l("a",{key:0,href:"mailto:"+s.company.email},y(s.company.email),9,O)):h("",!0),s.company.phone?(c(),l("a",{key:1,href:"tel:"+s.company.phone},y(s.company.phone),9,W)):h("",!0)])])]),s.company.website||$.quickStats.length?(c(),l("section",X,[$.quickStats?(c(!0),l(w,{key:0},v($.quickStats,e=>(c(),l("div",{key:e.label,class:"fcrm_company_quick_stat"},[m("span",Z,["owner"===e.icon?(c(),_(E,{key:0,"icon-name":"user"})):"industry"===e.icon?(c(),_(E,{key:1,"icon-name":"building"})):"type"===e.icon?(c(),_(E,{key:2,"icon-name":"briefcase"})):(c(),_(E,{key:3,"icon-name":"users"}))]),m("div",G,[m("span",null,y(e.label)+":",1),m("strong",null,y(e.value),1)])]))),128)):h("",!0),s.company.website?(c(),l("div",J,[m("span",M,[r(E,{"icon-name":"glob"})]),m("div",Q,[m("span",null,y(e.$t("Website:")),1),m("strong",null,[s.company.website?(c(),l("a",{key:0,href:s.company.website,target:"_blank",rel:"noopener"},y($.domainName||s.company.website),9,Y)):h("",!0)])])])):h("",!0)])):h("",!0),m("section",K,[m("div",ee,[m("h4",null,y(e.$t("About")),1)]),s.company.description?(c(),l("p",ae,y(s.company.description),1)):(c(),l("p",te,y(e.$t("No description added")),1))]),m("section",ie,[m("div",oe,[m("h4",null,y(e.$t("Address")),1)]),$.profileAddressLines.length?(c(),l("div",se,[(c(!0),l(w,null,v($.profileAddressLines,(e,a)=>(c(),l("p",{key:a},y(e),1))),128))])):(c(),l("p",ne,y(e.$t("No address added")),1))]),m("section",ce,[m("div",le,[m("h4",null,y(e.$t("Social Links")),1)]),$.socialLinks.length?(c(),l("div",me,[(c(!0),l(w,null,v($.socialLinks,e=>(c(),l("a",{key:e.label,href:e.url,target:"_blank",rel:"noopener",class:"el-button"},[m("span",null,[e.icon?(c(),l("span",de,["linkedin"===e.icon?(c(),_(E,{key:0,"icon-name":"linkedin"})):"x"===e.icon?(c(),_(E,{key:1,"icon-name":"x"})):(c(),_(E,{key:2,"icon-name":"facebook"}))])):h("",!0),p(" "+y(e.label),1)])],8,re))),128))])):(c(),l("p",pe,y(e.$t("No social links added")),1))])])])])]),_:1}),m("section",ye,[m("div",ue,[m("h4",null,y(e.$t("Custom Data")),1),r(q,{link:"",size:"small",onClick:o[2]||(o[2]=a=>e.$refs.companyCustomFields.openConfig())},{default:d(()=>[m("span",_e,[r(E,{"icon-name":"EditPen"})]),p(" "+y(e.$t("Configure")),1)],void 0),_:1})]),m("div",he,[r(D,{ref:"companyCustomFields",show_header:!1,custom_values:C.model.custom_values},null,8,["custom_values"]),C.isDirty?u((c(),_(q,{key:0,disabled:C.updating,type:"primary",onClick:o[3]||(o[3]=e=>$.updateInfo())},{default:d(()=>[p(y(s.company.id?e.$t("Update info"):e.$t("Create Company")),1)],void 0),_:1},8,["disabled"])),[[Ce,C.updating]]):h("",!0)])])]),r(ge,{direction:C.direction,class:"fcrm_company_summary_edit_drawer","with-header":!0,size:e.globalDrawerSize,"append-to-body":!0,title:e.$t("Edit Company"),onClose:o[6]||(o[6]=e=>$.closeSummaryEditDrawer()),modelValue:C.showSummaryEditDrawer,"onUpdate:modelValue":o[7]||(o[7]=e=>C.showSummaryEditDrawer=e)},k({default:d(()=>[C.showSummaryEditDrawer?(c(),l("div",fe,[m("div",we,[r(S,{model:C.model,company:s.company,onAvatarChanged:$.updateAvatar,class:"fcrm_pt_20"},{"custom-fields":d(()=>[r(D,{custom_values:C.model.custom_values},null,8,["custom_values"])]),_:1},8,["model","company","onAvatarChanged"])])])):h("",!0)],void 0),_:2},[C.showSummaryEditDrawer?{name:"footer",fn:d(()=>[m("div",ve,[r(q,{onClick:o[4]||(o[4]=e=>$.closeSummaryEditDrawer())},{default:d(()=>[p(y(e.$t("Cancel")),1)],void 0,!0),_:1}),r(q,{onClick:o[5]||(o[5]=e=>$.saveSummaryFromDrawer()),type:"primary",loading:C.updating},{default:d(()=>[p(y(e.$t("Update info")),1)],void 0,!0),_:1},8,["loading"])])]),key:"0"}:void 0]),1032,["direction","size","title","modelValue"]),C.isDirty?(c(),l("div",ke,[s.is_drawer&&s.company.id?(c(),_(be,{key:0,to:{name:"view_company",params:{company_id:s.company.id}},class:"fcrm_view_link"},{default:d(()=>[p(y(e.$t("Go to company record")),1)],void 0),_:1},8,["to"])):h("",!0)])):h("",!0)])):(c(),l("div",A,[m("div",F,[r(S,{mode:"create",model:C.model,company:s.company,onAvatarChanged:$.updateAvatar,class:"fcrm_pt_20"},{"custom-fields":d(()=>[r(D,{custom_values:C.model.custom_values},null,8,["custom_values"])]),_:1},8,["model","company","onAvatarChanged"])]),s.hide_drawer_footer?h("",!0):(c(),l("div",L,[m("div",N,[r(q,{size:"small",onClick:$.handleCancel},{default:d(()=>[p(y(e.$t("Cancel")),1)],void 0),_:1},8,["onClick"]),u((c(),_(q,{disabled:C.updating||!C.isDirty,type:"primary",size:"small",onClick:o[0]||(o[0]=e=>$.updateInfo())},{default:d(()=>[p(y(s.company.id?e.$t("Update info"):e.$t("Create Company")),1)],void 0),_:1},8,["disabled"])),[[Ce,C.updating]])])]))]))],2)}]]);export{ge as C};