import{j as s,ag as r,o as h,es as j,aT as R,aX as p,Y as N,et as v,T as y,at as S,Z as w,bQ as O,h as f,i as g,b as E,R as b,g as U,a4 as T}from"./app-BgLa5dit.js";import{C as I}from"./itQZri94.chunk.js";import{O as k}from"./Vn1DtJ-y.chunk.js";import{g as M,a as L}from"./C6-eluIr.chunk.js";import{O as V}from"./DNClpFKN.chunk.js";import{g as C,u as A,R as P}from"./DR2FaZH9.chunk.js";import{C as _}from"./q-IBKcuF.chunk.js";function D(e){var a;if(p.isType(e,r.Organisation)){const{id:n,name:i}=e;return{name:i,appLink:{application:g.CRM_STUDIO,action:f.CrmStudio.ORGANISATION_OVERVIEW,args:[n]}}}if(p.isType(e,r.Customer)){const n=e;return{name:n.name||((a=n.organisation)==null?void 0:a.name)||n.crmId,appLink:{application:g.CRM_STUDIO,action:f.CrmStudio.CUSTOMER_OVERVIEW,args:[n.id]}}}if(p.isType(e,r.User)){const n=e;return{name:n.name+" "+n.surname||n.username,appLink:{application:g.CRM_STUDIO,action:f.CrmStudio.USER_OVERVIEW,args:[n.id]}}}}function H({entity:e,isPinned:a,onTogglePin:n}){var u;const[i,o]=R.useState(!1),{name:l,appLink:t}=D(e),d=p.isType(e,r.Customer)?e:null,x=p.isType(e,r.Organisation)?e:null,c=p.isType(e,r.User)?e:null,m=c?M(c):null;return s.jsx("div",{className:"col-12 col-md-4 d-flex",children:s.jsxs("div",{className:"position-relative flex-fill d-flex",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[s.jsxs(N,{appLink:t,className:"card p-3 flex-fill d-flex flex-column gap-1 text-decoration-none",children:[d&&s.jsxs("div",{className:"d-flex flex-column gap-1",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center w-100",children:[s.jsx(I,{customerType:d.customerType}),((u=d.country)==null?void 0:u.code)&&s.jsx(v,{countryCode:d.country.code})]}),s.jsx("div",{className:"d-flex align-items-center w-100",children:e.id}),s.jsx("div",{className:"w-100 fw-semibold",children:l})]}),x&&s.jsxs(s.Fragment,{children:[s.jsx(k,{type:x.orgType}),s.jsx("div",{className:"d-flex align-items-center w-100",children:e.id}),s.jsx("div",{className:"w-100 fw-semibold",children:l})]}),c&&s.jsxs("div",{className:"d-flex flex-column gap-1",children:[s.jsx("div",{className:"d-flex justify-content-between align-items-center w-100",children:s.jsx("div",{className:L(m),children:m})}),s.jsx("div",{className:`d-flex align-items-center w-100 text-truncate ellipse ${c.email?"":"opacity-50"}`,children:c.email||"No email"}),s.jsx("div",{className:"w-100 fw-semibold text-truncate ellipse",children:l})]})]}),(a||i)&&s.jsx(y,{title:a?"Unpin":"Pin",spanHack:!0,children:s.jsx(S,{svg:O,svgSize:w.Small,className:`position-absolute top-0 end-0 p-1 m-1 ${a?" text-primary":""}`,onClick:n})})]})})}function B({id:e,entityType:a,isPinned:n,onTogglePin:i}){const o=a===C(r.Customer),l=a===C(r.Organisation),t=a===C(r.User),d=h(o&&e?_.customer(e):null),x=h(l&&e?V.getOrganisation(e):null),c=h(t&&e?j.user(e):null);let m,u=!1;return o?(m=d.data,u=!d.hasCompleted):l?(m=x.data,u=!x.hasCompleted):t&&(m=c.data,u=!c.hasCompleted),u||!m?null:s.jsx(H,{entity:m,isPinned:n,onTogglePin:i})}function X({entityType:e}){const a=C(e),{items:n,handleReset:i,handleTogglePin:o}=A(a),l=n.some(t=>!t.pinned);return n.length?s.jsxs("div",{className:"col-12 mb-3",children:[s.jsxs("div",{className:"mb-2 d-flex align-items-center justify-content-between",children:[s.jsx("span",{className:"fw-semibold text-md",children:"Recently Viewed"}),l&&s.jsx("button",{className:"btn btn-link btn-sm p-0 text-secondary",onClick:i,children:"Reset all"})]}),s.jsx("div",{className:"row g-2",children:n.slice(0,P).map(t=>s.jsx(B,{id:t.id,entityType:a,isPinned:!!t.pinned,onTogglePin:()=>o(t.id)},t.id))})]}):null}function F(e){switch(e){case"customer":return T.CrmStudioCustomer;case"user":return T.CrmStudioUser;case"organisation":return T.CrmStudioOrganisation;default:return null}}function Y(e){const{hasPermissions:a,isLoading:n}=E(),i=F(e);return b.useEffect(()=>{if(n)return;!a(i)&&U.trigger({application:g.CRM_STUDIO,action:f.CrmStudio.HOME},{replace:!0})},[n]),{isLoading:n}}export{X as R,Y as u};
//# sourceMappingURL=D2PVoBDN.chunk.js.map
