1import{A as H,r as l,j as t,H as U,M as F,T as s,B as c,d as L,I as P,a as p}from"./app-CZw4zvFM.js";import{D as _}from"./DataTable-CJe1YVPD.js";import{u as M}from"./usePermissions-XmrYeZ7o.js";import{A as v}from"./AppLayout-4zxD2vZm.js";import{D as o}from"./index-CMlAdN8Z.js";import{T as D}from"./index-GHo0gMzn.js";import{S as z}from"./index-D7FWo8t1.js";/* empty css */import"./Table-h9VaYrIX.js";import"./index-B8SovKPY.js";import"./Overflow-uTMTJwUS.js";import"./index-DUZSKLIY.js";import"./move-1krGBtlZ.js";import"./DownOutlined-CTtnvDxu.js";import"./SearchOutlined-C9JuSteG.js";import"./index-BMl25Uzj.js";import"./FileOutlined-Be1gfnhV.js";import"./FolderOpenOutlined-DvOf-kRu.js";import"./HolderOutlined-DIYjOBfk.js";import"./index-6ZORLKDC.js";import"./CaretDownFilled-DBJPTnyl.js";import"./index-ZUebQvBO.js";import"./useBubbleLock-BClqePJl.js";import"./index-DABuY6qb.js";import"./dropdown-BPhbloOu.js";import"./EllipsisOutlined-B7OjL6qX.js";import"./index-BPfpx2jp.js";import"./useForm-D-jYjTVi.js";import"./useBreakpoint-PA8SwT4Z.js";import"./Pagination-CC4nssQR.js";import"./Input-DSSJiXAe.js";import"./CaretUpOutlined-IMJ8VlKe.js";import"./index-75SXKuUs.js";import"./EyeOutlined-CvZlSzKJ.js";import"./index-m7vRUi73.js";import"./dayjs.min-CEkUtFVV.js";import"./useUser-CIeVw0r0.js";import"./react-BuyrQXxp.js";import"./index-Tmleijx2.js";import"./row-M-1fLFv3.js";import"./Drawer-CiwctyAV.js";import"./useRealtimeStatus-BUTsp-uP.js";import"./index-Cb6XuDvd.js";import"./DeleteOutlined-CXMAF5FB.js";import"./DownloadOutlined-Dwh-7I6Y.js";import"./index-BlW28zjE.js";import"./PlusOutlined-CcDZkb5g.js";import"./CheckCircleOutlined-Dz7n_P1a.js";import"./CloseCircleOutlined-BgVSyJUv.js";import"./ColorPicker-Cln3f7Rc.js";import"./index-C2ThPjwV.js";import"./index-Cl-sUtUk.js";import"./index-DK3mN3jy.js";import"./index-D1KBpsla.js";import"./Addon-DOudmed9.js";import"./index-C5x5z6Fz.js";import"./index-pqRdtMMy.js";import"./index-xTTpnXCd.js";import"./callSuper-Cu6FRejo.js";import"./index-BT_DRRCT.js";import"./index-CXJxjv7i.js";import"./index-D0Kew-XR.js";import"./index-CbEOvlCk.js";function Ge(){const{message:i}=H.useApp(),[I,d]=l.useState(!1),[a,m]=l.useState(null),[w,u]=l.useState(!1),[A,h]=l.useState(0),[C,x]=l.useState(!1),k=M(),y=e=>{if(!e)return"N/A";const r=parseFloat(e);return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(r)},n=e=>e?new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"N/A",f=e=>e&&{appointmentscheduled:"blue",qualifiedtobuy:"cyan",presentationscheduled:"purple",decisionmakerboughtin:"orange",contractsent:"gold",closedwon:"green",closedlost:"red"}[e.toLowerCase()]||"default",j=e=>e?e.replace(/([A-Z])/g," $1").replace(/^./,r=>r.toUpperCase()).trim():"Not specified",g=e=>{if(!e)return"N/A";const r=[e.firstname,e.lastname].filter(Boolean);return r.length>0?r.join(" "):e.email||"Unknown"},b=e=>e?e.name||e.domain||"Unknown":"N/A",S=async e=>{u(!0),d(!0);try{const r=await p.get(`/api/hubspot/deals/${e.id}`);m(r.data.data)}catch(r){console.error("Failed to fetch deal details",r),i.error("Failed to load deal details"),d(!1)}finally{u(!1)}},T=async()=>{x(!0);try{const e=await p.post("/api/hubspot/deals/sync");e.data.success?(i.success(e.data.message),setTimeout(()=>{h(r=>r+1)},2e3)):i.error(e.data.message)}catch(e){if(console.error("Failed to sync deals",e),p.isAxiosError(e)){const r=e.response?.data?.message||"Failed to sync deals";i.error(r)}else i.error("Failed to sync deals")}finally{x(!1)}},N=[{title:"Deal Name",dataIndex:"dealname",key:"dealname",width:220,searchable:!0,render:(e,r)=>t.jsx(s.Link,{onClick:()=>S(r),children:r.dealname||"Unnamed Deal"})},{title:"Amount",dataIndex:"amount",key:"amount",width:140,sorter:!0,render:e=>{const r=e;return t.jsx(s.Text,{strong:!0,children:y(r)})}},{title:"Stage",dataIndex:"dealstage",key:"dealstage",width:180,render:e=>{const r=e;return t.jsx(D,{color:f(r),children:j(r)})}},{title:"Pipeline",dataIndex:"pipeline",key:"pipeline",width:140,searchable:!0,render:e=>e||t.jsx(s.Text,{type:"secondary",children:"Default"})},{title:"Company",dataIndex:"company",key:"company",width:180,render:(e,r)=>b(r.company)},{title:"Contact",dataIndex:"contact",key:"contact",width:180,render:(e,r)=>g(r.contact)},{title:"Close Date",dataIndex:"closedate",key:"closedate",width:140,sorter:!0,render:e=>{const r=e;return t.jsx(s.Text,{type:"secondary",children:n(r)})}},{title:"Actions",key:"actions",dataIndex:"id",width:120,render:(e,r)=>t.jsx(c,{size:"small",onClick:()=>S(r),children:"View Details"})}];return t.jsxs(v,{title:"HubSpot Deals",actions:t.jsxs(z,{children:[t.jsx(c,{icon:t.jsx(L,{action:"refresh"}),onClick:()=>h(e=>e+1),children:"Refresh"}),t.jsx(c,{type:"primary",icon:t.jsx(P,{name:"Sync"}),onClick:T,loading:C,disabled:!k.has("hubspot.deals.sync"),children:"Sync Now"})]}),wrapper:!1,children:[t.jsx(U,{title:"HubSpot Deals"}),t.jsx("div",{style:{padding:"24px"},children:t.jsx(_,{fetchUrl:"/api/hubspot/deals/datatable",columns:N,searchPlaceholder:"Search deals...",defaultPageSize:15},A)}),t.jsx(F,{title:a&&a.dealname||"Deal Details",open:I,onCancel:()=>{d(!1),m(null)},footer:[t.jsx(c,{onClick:()=>d(!1),children:"Close"},"close")],width:700,loading:w,children:a&&t.jsxs("div",{children:[t.jsxs(o,{bordered:!0,column:1,size:"small",children:[t.jsx(o.Item,{label:"Deal Name",children:a.deal
1name||t.jsx(s.Text,{type:"secondary",children:"Not provided"})}),t.jsx(o.Item,{label:"Amount",children:t.jsx(s.Text,{strong:!0,children:y(a.amount)})}),t.jsx(o.Item,{label:"Stage",children:t.jsx(D,{color:f(a.dealstage),children:j(a.dealstage)})}),t.jsx(o.Item,{label:"Pipeline",children:a.pipeline||t.jsx(s.Text,{type:"secondary",children:"Default"})}),t.jsx(o.Item,{label:"Associated Company",children:b(a.company)}),t.jsx(o.Item,{label:"Associated Contact",children:g(a.contact)}),t.jsx(o.Item,{label:"Close Date",children:n(a.closedate)}),t.jsx(o.Item,{label:"Created in HubSpot",children:n(a.createdate)}),t.jsx(o.Item,{label:"Last Modified in HubSpot",children:n(a.lastmodifieddate)}),t.jsx(o.Item,{label:"HubSpot ID",children:t.jsx(s.Text,{code:!0,children:a.hubspot_id})}),t.jsx(o.Item,{label:"Synced At",children:n(a.updated_at)})]}),a.properties&&Object.keys(a.properties).length>0&&t.jsxs("div",{style:{marginTop:24},children:[t.jsx(s.Title,{level:5,children:"Additional Properties"}),t.jsx(o,{bordered:!0,column:1,size:"small",children:Object.entries(a.properties).filter(([e])=>!["dealname","amount","dealstage","pipeline","closedate","createdate","lastmodifieddate"].includes(e)).map(([e,r])=>t.jsx(o.Item,{label:e,children:r!=null?String(r):t.jsx(s.Text,{type:"secondary",children:"N/A"})},e))})]})]})})]})}export{Ge as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.