chordia-ui 3.5.3 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),g=require("../sortable.esm.cjs.js"),v=require("lucide-react"),nt=require("react-dom"),ze=require("../CustomFilterChips.cjs.js");require("../TourGuideTooltip.cjs.js");function Ee({dateRangePicker:x,onWeekToDate:d,exportConfig:b,filterChipsConfig:f,trailingActions:k}){const[_,A]=a.useState(!1),w=a.useRef(null),M=a.useRef(null);a.useEffect(()=>{const u=z=>{M.current&&!M.current.contains(z.target)&&w.current&&!w.current.contains(z.target)&&A(!1)};if(_)return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u)}},[_]);const K=()=>{A(u=>!u)},G=u=>{A(!1),b!=null&&b.onExport&&b.onExport(u)},S=(()=>{if(!(f!=null&&f.filters))return!1;const u=f.filters,z=f.customFilters||[],E=Object.entries(u).some(([h,j])=>!!(Array.isArray(j)&&j.length||typeof j=="string"&&j.trim()!==""||j&&typeof j=="object"&&(j.min!=null||j.max!=null))),U=z.some(h=>h.active);return E||U})();return t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[d&&t.jsxs("button",{onClick:d,className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 transition-colors hover:bg-white text-sm font-medium text-gray-900",style:{fontFamily:"var(--font-sans)"},children:[t.jsx(v.CalendarClock,{size:16}),t.jsx("span",{children:"Week to Date"})]}),x&&t.jsx(a.Suspense,{fallback:t.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 text-sm font-medium text-gray-400",children:[t.jsx(v.CalendarClock,{size:16}),t.jsx("span",{children:"Loading..."})]}),children:x}),b&&t.jsxs("div",{className:"relative",children:[t.jsxs("button",{ref:w,onClick:K,disabled:b.isExporting,className:"inline-flex items-center justify-between gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 transition-colors hover:bg-white text-sm font-medium text-gray-900 disabled:opacity-50 disabled:cursor-not-allowed min-w-[120px]",style:{fontFamily:"var(--font-sans)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(v.Download,{size:16}),t.jsx("span",{children:b.isExporting?"Exporting...":"Export"})]}),t.jsx(v.ChevronDown,{size:16})]}),_&&t.jsx("div",{ref:M,className:"absolute top-full right-0 mt-2 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50 min-w-[120px]",children:(b.types||["csv"]).map(u=>t.jsxs("button",{onClick:()=>G(u),className:"w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 transition-colors",style:{fontFamily:"var(--font-sans)"},children:["Export ",u.toUpperCase()]},u))})]}),(S||k)&&t.jsxs(t.Fragment,{children:[S&&t.jsx("div",{className:"h-9 mt-1 w-px bg-gray-300 flex-shrink-0"}),t.jsxs("div",{className:"flex items-center gap-3 justify-end",children:[S&&f&&t.jsx(ze.CustomFilterChips,{filters:f.filters,onChange:f.onChange,onClear:f.onClear,customFilters:f.customFilters||[],fieldOptions:f.fieldOptions||{}}),k&&t.jsx("div",{className:"flex-shrink-0",children:k})]})]})]})}function ge(){return t.jsx("div",{style:{height:1,background:"rgba(52,58,64,0.08)"}})}const st=()=>({userData:{email:"anonymous"}}),ot=x=>t.jsx("img",{...x});function at({children:x}){return x}function lt({data:x=[],columns:d=[],initialPageSize:b=10,onRowClick:f,totalCount:k=null,page:_=null,pageSize:A=null,onPageChange:w=null,onPageSizeChange:M=null,onFilterChange:K=null,onMaxColumnsError:G=null,onSort:Y=null,sortFields:S=[],tableId:u=null,isLoading:z=!1,filtersConfig:E=null}){var Oe;const{userData:U}=st(),h=(U==null?void 0:U.email)||"anonymous",j=a.memo(({children:e,content:r,className:n=""})=>{const s=a.useRef(null),[o,l]=a.useState(!1);a.useEffect(()=>{const c=()=>{if(s.current){const J=s.current.scrollWidth>s.current.clientWidth;l(J)}};c();const H=setTimeout(c,0);return window.addEventListener("resize",c),()=>{clearTimeout(H),window.removeEventListener("resize",c)}},[e,r]);const i=t.jsx("span",{className:`truncate block ${n}`,ref:s,children:e});return o&&r?t.jsx(at,{content:r,styling:"bg-green-2 text-gray-900 px-3 py-2 text-sm rounded-lg shadow-md border border-gray-300 max-w-xs whitespace-normal",indicatorColor:"bg-green-2",direction:"top",children:i}):i});j.displayName="TruncatedCell";const X=k!==null&&w!==null,le=K!==null,I=Y!==null,[Me,ie]=a.useState(1),[Te,Le]=a.useState(b),ce=_!==null?_:Me,Q=A!==null?A:Te,Z=e=>{w?w(e):ie(e)},me=e=>{M?M(e):Le(e)},D=9,m="action",T=a.useRef(!1),P=a.useMemo(()=>u?`dataTable_columns_${u}:${h}`:`dataTable_columns_${d.map(r=>r.id||r.key).sort().join("_")}:${h}`,[u,d,h]),B=a.useMemo(()=>u?`dataTable_manual_change_${u}:${h}`:null,[u,h]);a.useCallback((e,r)=>{if(typeof window>"u"||!e||!r||r.length===0)return null;try{const n=localStorage.getItem(e);if(n){const o=JSON.parse(n).filter(l=>r.some(i=>(i.id||i.key)===l));if(o.length>0)return o}}catch(n){console.warn("Failed to load saved columns from localStorage:",n)}return null},[]);const[L,Re]=a.useState({}),[he,$e]=a.useState(null),[ye,be]=a.useState("asc");a.useCallback((e,r)=>e==="csat_score"&&r==="evaluation.csat_score"?r:e,[]);const q=I&&S.length>0?S[0][0]:he,ee=I&&S.length>0?S[0][1]:ye,[ct,ve]=a.useState(()=>d.map(e=>e.id||e.key)),N=a.useCallback(e=>{if(!e||e.length===0)return e;let r=Array.from(new Set(e));r.length>D&&(r=r.slice(0,D));const s=d.map(i=>i.id||i.key).includes(m);return!r.includes(m)&&s&&(r.length>=D?r=[...r.slice(0,D-1),m]:r=[...r,m]),[...r.filter(i=>i!==m),m]},[d]),[p,R]=a.useState(()=>{if(typeof window<"u"&&u)try{if(localStorage.getItem(`dataTable_manual_change_${u}:${h}`)==="true"){const s=localStorage.getItem(`dataTable_columns_${u}:${h}`);if(s){const o=JSON.parse(s);if(Array.isArray(o)&&o.length>0){T.current=!0;const l=o.filter(i=>d.some(c=>(c.id||c.key)===i));if(l.length>0)return l.slice(0,D)}}}}catch(n){console.warn("Failed to load saved columns from localStorage:",n)}const r=d.map(n=>n.id||n.key).slice(0,D);return N(r)}),[C,we]=a.useState(!1),[de,_e]=a.useState({top:0,left:0,width:0}),[Ae,je]=a.useState(new Set),[Se,Ce]=a.useState(new Set),[F,ue]=a.useState(null),[Ie,te]=a.useState(null),W=a.useRef(null),fe=a.useRef(null),V=a.useRef(null),[ke,pe]=a.useState(null),Pe=a.useRef(null),y=e=>e.id||e.key,Be=g.useSensors(g.useSensor(g.PointerSensor),g.useSensor(g.KeyboardSensor,{coordinateGetter:g.sortableKeyboardCoordinates})),We=e=>{const{active:r,over:n}=e;if(n&&r.id!==n.id){if(r.id===m||n.id===m){Ne("Cannot drop columns on the Action column"),pe(null);return}T.current=!0,R(s=>{const o=s.indexOf(r.id),l=s.indexOf(n.id);if(o!==-1&&l!==-1){const i=g.arrayMove(s,o,l),c=N(i);return oe(c),c}return s}),ve(s=>{const o=s.indexOf(r.id),l=s.indexOf(n.id);return g.arrayMove(s,o,l)})}pe(null)},Ve=e=>{pe(e.active.id)},re=a.useMemo(()=>le?x||[]:!x||x.length===0?[]:x.filter(e=>Object.keys(L).every(r=>{const n=L[r];if(!n||n.trim()==="")return!0;const s=e[r];if(s==null)return!1;const o=String(s).toLowerCase();return n.toLowerCase().trim().split(/\s+/).filter(c=>c.length>0).every(c=>o.includes(c))})),[x,L,le]),ne=a.useMemo(()=>I||!q?re:[...re].sort((e,r)=>{const n=e[q],s=r[q];if(n==null)return 1;if(s==null)return-1;if(typeof n=="number"&&typeof s=="number")return ee==="asc"?n-s:s-n;const o=String(n).toLowerCase(),l=String(s).toLowerCase();return ee==="asc"?o.localeCompare(l):l.localeCompare(o)}),[re,q,ee,I]),se=a.useMemo(()=>{if(X)return x||[];{const e=(ce-1)*Q,r=e+Q;return ne.slice(e,r)}},[x,ne,ce,Q,X]),He=e=>{I&&Y?(Y(e),w?w(1):ie(1)):(he===e?be(ye==="asc"?"desc":"asc"):($e(e),be("asc")),Z(1))},De=(e,r)=>{const n=r&&r.trim()!==""?{...L,[e]:r}:Object.fromEntries(Object.entries(L).filter(([s])=>s!==e));Re(n),le&&K&&K(n),w?w(1):ie(1)},Ne=e=>{V.current||(typeof G=="function"&&G(e),V.current=setTimeout(()=>{V.current=null},3e3))},oe=a.useCallback(e=>{if(typeof window<"u"&&P&&e.length>0&&T.current)try{localStorage.setItem(P,JSON.stringify(e)),B&&localStorage.setItem(B,"true")}catch(r){console.warn("Failed to save columns to localStorage:",r)}},[P,B]),xe=e=>{e!==m&&(T.current=!0,R(r=>r.includes(e)?(V.current&&(clearTimeout(V.current),V.current=null),r.length===1||(Ce(n=>new Set(n).add(e)),setTimeout(()=>{R(n=>{const s=n.filter(l=>l!==e),o=N(s);return oe(o),o}),Ce(n=>{const s=new Set(n);return s.delete(e),s})},200)),r):r.length>=D?(Ne("Maximum 9 column selection allowed"),r):(je(n=>new Set(n).add(e)),setTimeout(()=>{R(n=>{const s=n.includes(e)?n:[...n,e],o=N(s);return oe(o),o}),je(n=>{const s=new Set(n);return s.delete(e),s})},200),r)))},Ke=(e,r)=>{p[r]!==m&&ue(r)},Ue=()=>{ue(null),te(null)},qe=(e,r)=>{e.preventDefault(),F!==null&&F!==r&&te(r)},Je=()=>{te(null)},Ge=(e,r)=>{e.preventDefault(),F!==null&&F!==r&&p[r]!==m&&p[F]!==m&&(T.current=!0,R(n=>{const s=g.arrayMove(n,F,r),o=N(s);return oe(o),o})),ue(null),te(null)};a.useEffect(()=>{ve(e=>{const r=p.filter(o=>e.includes(o)),n=p.filter(o=>!e.includes(o)),s=e.filter(o=>!p.includes(o));return[...r,...n,...s]})},[p]),a.useEffect(()=>{if(typeof window<"u"&&P&&p.length>0&&T.current)try{const e=N(p);localStorage.setItem(P,JSON.stringify(e)),B&&localStorage.setItem(B,"true")}catch(e){console.warn("Failed to save columns to localStorage:",e)}},[p,P,B]),a.useEffect(()=>{if(d.length>0&&p.length===0){if(typeof window<"u"&&u)try{if(localStorage.getItem(`dataTable_manual_change_${u}:${h}`)==="true"){const n=localStorage.getItem(`dataTable_columns_${u}:${h}`);if(n){const s=JSON.parse(n);if(Array.isArray(s)&&s.length>0){const o=s.filter(l=>d.some(i=>(i.id||i.key)===l));if(o.length>0){T.current=!0,R(o.slice(0,D));return}}}}}catch(r){console.warn("Failed to load saved columns from localStorage:",r)}const e=d.map(r=>r.id||r.key);R(N(e.slice(0,D)))}},[d,u,h,N]);const $=a.useMemo(()=>{const e=p.map(r=>d.find(n=>y(n)===r)).filter(Boolean);return N(e.map(y)).map(r=>d.find(n=>y(n)===r)).filter(Boolean)},[d,p]),Ye=a.useMemo(()=>$.some(e=>e.filterable===!0),[$]);a.useEffect(()=>{if(!C||!W.current)return;const e=()=>{if(W.current){const r=W.current.getBoundingClientRect();_e({top:r.bottom,left:r.left,width:Math.max(r.width||220,220)})}};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[C]),a.useEffect(()=>{const e=r=>{C&&W.current&&!W.current.contains(r.target)&&fe.current&&!fe.current.contains(r.target)&&we(!1)};if(C)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[C]);const Xe=p.length===1?((Oe=d.find(e=>(e.id||e.key)===p[0]))==null?void 0:Oe.label)||"1 selected":`${p.length} selected`;function Qe({column:e,isHeaderRow:r=!0}){const n=y(e),s=n===m,{attributes:o,listeners:l,setNodeRef:i,transform:c,transition:H,isDragging:J}=g.useSortable({id:n}),et={transform:g.CSS.Transform.toString(c),transition:H,opacity:J?.5:1,width:e.width||"auto",minWidth:e.width||"auto"};let ae=!1;if(I&&S.length>0){const O=S[0][0];(O===n||O==="csat_score"&&n==="evaluation.csat_score")&&(ae=!0)}else ae=q===n;const tt=ee==="asc",rt=e.filterable===!0;return r?t.jsx("th",{ref:i,style:{...et,padding:"12px 14px",textAlign:s?"center":"left",fontWeight:650,fontSize:"11px",letterSpacing:"0.14em",textTransform:"uppercase",color:"rgba(30, 33, 37, 0.62)",cursor:e.sortable!==!1?"pointer":"default",width:e.width||"auto",borderRight:"1px solid rgba(52, 58, 64, 0.06)",userSelect:"none",background:"var(--primary-foreground)",borderBottom:"1px solid rgba(52, 58, 64, 0.12)",position:"sticky",top:0,zIndex:10,fontFamily:"var(--font-sans)"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",justifyContent:s?"center":"flex-start"},children:[!s&&t.jsx("div",{...o,...l,style:{cursor:"grab",color:"rgba(30, 33, 37, 0.32)"},children:t.jsx(v.GripVertical,{size:12})}),t.jsx("span",{onClick:()=>e.sortable!==!1&&He(n),style:{cursor:e.sortable!==!1?"pointer":"default"},children:e.label.toUpperCase()}),e.sortable!==!1&&ae&&t.jsx("span",{children:tt?t.jsx(v.ChevronUp,{size:12}):t.jsx(v.ChevronDown,{size:12})})]})}):t.jsx("th",{style:{width:e.width||"auto",minWidth:e.width||"auto",backgroundColor:"var(--primary-foreground)"},className:"sticky top-[57px] z-10 border-b border-[var(--border-strong)] px-4 py-2 text-left",children:rt?t.jsxs("div",{className:"relative",children:[t.jsx(v.Filter,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--text-faint)] pointer-events-none"}),t.jsx("input",{type:"text",placeholder:"Filter...",value:L[n]||"",onChange:O=>{O.stopPropagation(),De(n,O.target.value)},onKeyDown:O=>O.stopPropagation(),onMouseDown:O=>O.stopPropagation(),className:"w-full pl-7 pr-2 py-1.5 text-xs border border-[var(--border)] rounded text-[var(--text-ink)] placeholder:text-[var(--text-faint)] focus:outline-none focus:border-[var(--border-hover)] focus:ring-1 focus:ring-[var(--focus)] transition-colors",style:{fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)"},autoComplete:"off"})]}):t.jsx("div",{className:"h-[34px]"})})}const Fe=ke?d.find(e=>y(e)===ke):null,Ze=C?t.jsxs("div",{ref:fe,className:"flex flex-col overflow-auto z-[49] min-w-[220px]",style:{position:"fixed",top:`${de.top}px`,left:`${de.left}px`,width:de.width||220,maxHeight:"400px",fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)",borderRadius:"0 0 8px 8px",boxShadow:"4px 4px 6px 0px #6D70681A, -4px 0px 6px 0px #6D70681A",border:"1px solid rgba(52, 58, 64, 0.12)",borderTop:"none"},children:[p.map((e,r)=>{const n=d.find(c=>y(c)===e);if(!n)return null;const s=p.indexOf(e),o=F===s,l=Ie===s,i=e===m;return t.jsxs(a.Fragment,{children:[t.jsxs("div",{draggable:!i,onDragStart:i?void 0:c=>Ke(c,s),onDragEnd:i?void 0:Ue,onDragOver:i?void 0:c=>qe(c,s),onDragLeave:i?void 0:Je,onDrop:i?void 0:c=>Ge(c,s),className:`flex items-center gap-2 px-3 py-2 rounded transition-all ${i?"cursor-default opacity-100":"cursor-move"} ${!i&&o?"opacity-50":""} ${!i&&l&&F!==null&&F!==s?"ring-2 ring-green-2 ring-offset-1":""}`,children:[!i&&t.jsx("svg",{className:"h-4 w-4 text-gray-600 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8h16M4 12h16M4 16h16"})}),t.jsx("button",{type:"button",onClick:c=>{c.preventDefault(),c.stopPropagation(),i||xe(e)},className:`h-4 w-4 rounded-[2px] border flex items-center justify-center transition-colors flex-shrink-0 ${i?"bg-green-2 border-green-2 cursor-default":Se.has(e)?"bg-white border-gray-300":"bg-green-2 border-green-2"}`,children:!Se.has(e)&&t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,style:{color:"#1E2125"},children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsx("span",{className:"text-sm text-gray-900 flex-1",style:{fontFamily:"var(--font-sans)"},children:n.label})]}),r<p.length-1&&t.jsx(ge,{})]},`selected-${e}-${r}`)}),d.filter(e=>!p.includes(y(e))).map((e,r)=>{const n=y(e),s=Ae.has(n),o=d.filter(l=>!p.includes(y(l))).indexOf(e);return t.jsxs(a.Fragment,{children:[p.length>0&&o===0&&t.jsx(ge,{}),t.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 hover:bg-gray-50 rounded cursor-pointer transition-colors",onClick:l=>{l.preventDefault(),xe(n)},children:[t.jsx("button",{type:"button",onClick:l=>{l.preventDefault(),l.stopPropagation(),xe(n)},className:`h-4 w-4 rounded-[2px] border flex items-center justify-center transition-colors flex-shrink-0 ${s?"bg-green-2 border-green-2":"bg-white border-gray-300"}`,children:s&&t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,style:{color:"#1E2125"},children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsx("span",{className:"text-sm text-gray-900 flex-1",children:e.label})]}),o<d.filter(l=>!p.includes(y(l))).length-1&&t.jsx(ge,{})]},`unselected-${n}`)})]}):null;return t.jsxs("div",{className:"w-full",style:{top:"130px",position:"sticky",zIndex:35,backgroundColor:"var(--primary-foreground)"},children:[d.length>0&&t.jsx("div",{className:"pt-2 pb-1",style:{position:"sticky",zIndex:35,backgroundColor:"var(--primary-foreground)"},children:t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("div",{className:"mb-1 ml-1.5",children:t.jsx("p",{className:"text-xs font-medium text-gray-600",style:{fontFamily:"var(--font-sans)"},children:"Select Columns"})}),t.jsxs("div",{ref:W,className:"inline-flex items-center justify-between gap-2 px-4 py-2.5 cursor-pointer transition-colors text-sm font-medium text-gray-900 border border-gray-300 min-w-[220px]",onClick:()=>we(!C),style:{fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)",borderRadius:C?"8px 8px 0 0":"8px"},children:[t.jsx("span",{children:Xe}),C?t.jsx(v.ChevronUp,{size:16}):t.jsx(v.ChevronDown,{size:16})]}),C&&nt.createPortal(Ze,document.body)]}),E&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"h-9 mt-[1.5rem] w-px bg-gray-300 flex-shrink-0"}),t.jsx("div",{className:"flex-shrink-0 mt-[1.5rem]",children:t.jsx(Ee,{dateRangePicker:E.dateRangePicker,onWeekToDate:E.onWeekToDate,exportConfig:E.exportConfig,filterChipsConfig:E.filterChipsConfig,trailingActions:E.trailingActions})})]})]})}),d.length>0&&$.length>0?t.jsxs(g.DndContext,{sensors:Be,collisionDetection:g.closestCenter,onDragStart:Ve,onDragEnd:We,children:[t.jsxs("div",{className:"rounded-[14px]",style:{border:"1px solid rgba(52, 58, 64, 0.12)",borderBottom:"1px solid rgba(52, 58, 64, 0.12)",overflow:"hidden",background:"var(--primary-foreground)",position:"relative",top:"0.5rem"},children:[z&&t.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(255, 255, 255, 0.9)",backdropFilter:"blur(2px)",zIndex:20,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",borderRadius:"14px"},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[t.jsx("p",{style:{fontSize:"13px",color:"rgba(30, 33, 37, 0.6)",margin:0},children:"Loading..."}),t.jsx(ot,{src:"/BrandLoading.gif",alt:"Loading",width:50,height:50,unoptimized:!0,className:"mt-1"})]})}),t.jsx("div",{className:"overflow-x-auto custom-thin-scrollbar-hidden",ref:Pe,style:{maxHeight:"500px",overflowY:"auto",position:"relative",zIndex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px",fontFamily:"var(--font-sans)"},children:[t.jsxs("thead",{children:[t.jsx("tr",{children:t.jsx(g.SortableContext,{items:p,strategy:g.horizontalListSortingStrategy,children:$.map(e=>t.jsx(Qe,{column:e,isHeaderRow:!0},`header-${y(e)}`))})}),Ye&&t.jsx("tr",{children:$.map(e=>{const r=y(e),n=e.filterable===!0;return t.jsx("th",{style:{padding:"8px 14px",background:"var(--primary-foreground)",borderBottom:"1px solid rgba(52, 58, 64, 0.10)",position:"sticky",top:"41px",zIndex:10,width:e.width||"auto",fontFamily:"var(--font-sans)"},children:n?t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",placeholder:"Filter...",value:L[r]||"",onChange:s=>{s.stopPropagation(),De(r,s.target.value)},onKeyDown:s=>s.stopPropagation(),onMouseDown:s=>s.stopPropagation(),style:{width:"100%",padding:"4px 8px 4px 26px",fontSize:"11.5px",border:"1px solid rgba(52, 58, 64, 0.16)",borderRadius:"6px",background:"var(--primary-foreground)",color:"rgba(30, 33, 37, 0.78)",outline:"none",fontFamily:"var(--font-sans)"},onFocus:s=>{s.target.style.borderColor="rgba(231, 212, 162, 0.65)",s.target.style.background="var(--primary-foreground)"},onBlur:s=>{s.target.style.borderColor="rgba(52, 58, 64, 0.16)",s.target.style.background="var(--primary-foreground)"},autoComplete:"off"}),t.jsx(v.Filter,{size:11,style:{position:"absolute",left:"8px",top:"50%",transform:"translateY(-50%)",color:"rgba(30, 33, 37, 0.42)",pointerEvents:"none"}})]}):t.jsx("div",{className:"h-[34px]"})},`filter-${r}`)})})]}),t.jsx("tbody",{children:!z&&se.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:$.length,style:{padding:"32px",textAlign:"center",color:"rgba(30, 33, 37, 0.42)",fontSize:"12px",fontFamily:"var(--font-sans)"},children:"No results found"})}):!z&&se.length>0?se.map((e,r)=>t.jsx("tr",{"data-row-id":e.id||r,style:{borderBottom:"1px solid rgba(52, 58, 64, 0.08)",cursor:f?"pointer":"default",transition:"background 0.15s ease"},onClick:f?n=>{n.stopPropagation(),f(e,r)}:void 0,onMouseEnter:n=>{n.currentTarget.style.background="rgba(231, 212, 162, 0.12)"},onMouseLeave:n=>{n.currentTarget.style.background="transparent"},children:$.map(n=>{const s=y(n),o=e[s],l=n.render?n.render(o,e):o,i=n.width&&n.width!=="auto",c=typeof l=="string"&&l.trim()!=="",H=i&&c,J=H?t.jsx(j,{content:l,children:l}):l;return t.jsx("td",{style:{padding:"10px 14px",color:"rgba(30, 33, 37, 0.78)",fontSize:"13px",borderRight:"1px solid rgba(52, 58, 64, 0.04)",width:n.width||"auto",fontFamily:"var(--font-sans)",...H&&{maxWidth:n.width||"200px",overflow:"hidden"}},children:J},s)})},r)):null})]})})]}),t.jsx(g.DragOverlay,{children:Fe?t.jsx("div",{className:"bg-[var(--paper-high)] border border-[var(--border-strong)] rounded px-4 py-2 shadow-lg",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(v.GripVertical,{size:14,className:"text-[var(--text-faint)]"}),t.jsx("span",{className:"text-sm font-semibold text-[var(--text-ink)]",children:Fe.label})]})}):null})]}):null,(X?k>0:ne.length>0)&&t.jsx("div",{className:"border-t border-gray-200 rounded-b-[14px]",style:{backgroundColor:"var(--primary-foreground)"},children:t.jsx(ze.Pagination,{page:ce,pageSizeOptions:[5,10,20,50,100],pageSize:Q,totalCount:X?k:ne.length,currentDataLength:se.length,onPageChange:Z,onPageSizeChange:M?e=>{me(e),Z(1)}:e=>{me(e),Z(1)},showPageSizeSelector:!0})})]})}function it({title:x="Summary stats",stats:d=[],columns:b=2}){return t.jsxs("div",{style:{fontFamily:"system-ui, -apple-system, sans-serif"},children:[t.jsx("div",{className:"text-[11px] tracking-[0.14em] uppercase mb-[10px]",style:{color:"rgba(30, 33, 37, 0.42)",fontWeight:650},children:x}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${b}, minmax(0, 1fr))`,gap:"10px"},children:d.map((f,k)=>t.jsxs("div",{style:{position:"relative",border:"1px solid rgba(52, 58, 64, 0.12)",borderRadius:"12px",background:"rgba(255, 255, 255, 0.72)",padding:f.accentColor?"10px 10px 10px 14px":"10px",minHeight:"62px",display:"flex",flexDirection:"column",justifyContent:"center",gap:"5px",overflow:"hidden"},children:[f.accentColor&&t.jsx("div",{style:{position:"absolute",left:0,top:0,bottom:0,width:"4px",background:f.accentColor,borderTopLeftRadius:"12px",borderBottomLeftRadius:"12px"}}),t.jsx("div",{className:"text-[10px] tracking-[0.14em] uppercase",style:{color:"rgba(30, 33, 37, 0.42)",fontWeight:650,lineHeight:1.1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:f.label}),t.jsx("div",{style:{fontSize:"13px",color:f.valueStyle==="muted"?"rgba(30, 33, 37, 0.56)":"rgba(30, 33, 37, 0.78)",fontWeight:700,lineHeight:1.15,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:f.valueStyle==="mono"?"ui-monospace, monospace":"inherit"},children:f.value}),f.subtext&&t.jsx("div",{style:{fontSize:"11px",color:"rgba(30, 33, 37, 0.52)",lineHeight:1.15,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:f.subtext})]},k))})]})}exports.DataTable=lt;exports.DataTableFilters=Ee;exports.SummaryStatsPanel=it;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),i=require("react"),h=require("../sortable.esm.cjs.js"),L=require("lucide-react"),Ve=require("react-dom"),He=require("../CustomFilterChips.cjs.js");require("../TourGuideTooltip.cjs.js");function Ke({dateRangePicker:x,onWeekToDate:c,exportConfig:b,filterChipsConfig:u,trailingActions:C}){const[S,$]=i.useState(!1),w=i.useRef(null),F=i.useRef(null);i.useEffect(()=>{const p=D=>{F.current&&!F.current.contains(D.target)&&w.current&&!w.current.contains(D.target)&&$(!1)};if(S)return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[S]);const _=()=>{$(p=>!p)},B=p=>{$(!1),b!=null&&b.onExport&&b.onExport(p)},y=(()=>{if(!(u!=null&&u.filters))return!1;const p=u.filters,D=u.customFilters||[],M=Object.entries(p).some(([g,v])=>!!(Array.isArray(v)&&v.length||typeof v=="string"&&v.trim()!==""||v&&typeof v=="object"&&(v.min!=null||v.max!=null))),V=D.some(g=>g.active);return M||V})();return t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c&&t.jsxs("button",{onClick:c,className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 transition-colors hover:bg-white text-sm font-medium text-gray-900",style:{fontFamily:"var(--font-sans)"},children:[t.jsx(L.CalendarClock,{size:16}),t.jsx("span",{children:"Week to Date"})]}),x&&t.jsx(i.Suspense,{fallback:t.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 text-sm font-medium text-gray-400",children:[t.jsx(L.CalendarClock,{size:16}),t.jsx("span",{children:"Loading..."})]}),children:x}),b&&t.jsxs("div",{className:"relative",children:[t.jsxs("button",{ref:w,onClick:_,disabled:b.isExporting,className:"inline-flex items-center justify-between gap-2 rounded-lg border border-gray-300 bg-white/80 px-4 py-2.5 transition-colors hover:bg-white text-sm font-medium text-gray-900 disabled:opacity-50 disabled:cursor-not-allowed min-w-[120px]",style:{fontFamily:"var(--font-sans)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(L.Download,{size:16}),t.jsx("span",{children:b.isExporting?"Exporting...":"Export"})]}),t.jsx(L.ChevronDown,{size:16})]}),S&&t.jsx("div",{ref:F,className:"absolute top-full right-0 mt-2 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50 min-w-[120px]",children:(b.types||["csv"]).map(p=>t.jsxs("button",{onClick:()=>B(p),className:"w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 transition-colors",style:{fontFamily:"var(--font-sans)"},children:["Export ",p.toUpperCase()]},p))})]}),(y||C)&&t.jsxs(t.Fragment,{children:[y&&t.jsx("div",{className:"h-9 mt-1 w-px bg-gray-300 flex-shrink-0"}),t.jsxs("div",{className:"flex items-center gap-3 justify-end",children:[y&&u&&t.jsx(He.CustomFilterChips,{filters:u.filters,onChange:u.onChange,onClear:u.onClear,customFilters:u.customFilters||[],fieldOptions:u.fieldOptions||{}}),C&&t.jsx("div",{className:"flex-shrink-0",children:C})]})]})]})}function Le(){return t.jsx("div",{style:{height:1,background:"rgba(52,58,64,0.08)"}})}function gt({size:x=10,color:c="currentColor"}){return t.jsxs("svg",{width:x,height:x,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{display:"block"},"aria-hidden":"true",children:[t.jsx("path",{d:"M3.5 8H12.5",stroke:c,strokeWidth:"1.4",strokeLinecap:"round"}),t.jsx("path",{d:"M5 6.5L3.5 8L5 9.5",stroke:c,strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M11 6.5L12.5 8L11 9.5",stroke:c,strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M6.8 3V13",stroke:c,strokeWidth:"1.2",strokeLinecap:"round"}),t.jsx("path",{d:"M9.2 3V13",stroke:c,strokeWidth:"1.2",strokeLinecap:"round"})]})}const mt=()=>({userData:{email:"anonymous"}}),ht=x=>t.jsx("img",{...x});function bt({children:x,content:c,direction:b="top",align:u="center",styling:C,indicatorColor:S}){const $=typeof c=="string"?c:c!=null?String(c):"",w=typeof S=="string"&&(S.startsWith("#")||S.startsWith("rgb")||S.startsWith("hsl")||S.startsWith("var("))?S:"var(--Grey-Strong, #2E3236)",[F,_]=i.useState(!1),[B,ee]=i.useState(!1),[y,p]=i.useState({top:0,left:0,arrowLeft:0,placement:"top"}),D=i.useRef(null),M=i.useRef(null);if(!$)return x;i.useEffect(()=>{ee(!0)},[]);const V=i.useCallback(()=>{if(!D.current||!M.current||typeof window>"u")return;const g=D.current.getBoundingClientRect(),v=M.current.getBoundingClientRect(),N=window.innerWidth,ie=window.innerHeight,E=8,H=10,z=v.width,te=v.height,q=g.top,ae=ie-g.bottom,le=b==="bottom"?"bottom":"top";let K=le;le==="top"&&q<te+H+E&&ae>q?K="bottom":le==="bottom"&&ae<te+H+E&&q>ae&&(K="top");let R=g.left+g.width/2;u==="start"&&(R=g.left),u==="end"&&(R=g.right);let U=K==="top"?g.top-te-H:g.bottom+H,X=u==="start"?R:u==="end"?R-z:R-z/2;U=Math.max(E,Math.min(U,ie-te-E)),X=Math.max(E,Math.min(X,N-z-E));const T=Math.max(10,Math.min(R-X,z-10));p({top:U,left:X,arrowLeft:T,placement:K})},[u,b]);return i.useEffect(()=>{if(!F||!B)return;V();const g=()=>V();return window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[F,B,V]),t.jsxs("span",{ref:D,style:{display:"block",width:"100%"},onMouseEnter:()=>_(!0),onMouseLeave:()=>_(!1),children:[x,F&&B&&Ve.createPortal(t.jsxs("span",{ref:M,style:{position:"fixed",top:`${y.top}px`,left:`${y.left}px`,background:"var(--Grey-Strong, #2E3236)",color:"var(--Grey-White, #FFF)",fontSize:"12px",lineHeight:1.3,fontWeight:500,padding:"8px 10px",borderRadius:"6px",whiteSpace:"normal",maxWidth:"320px",width:"max-content",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.2)",zIndex:99999,pointerEvents:"none",...typeof C=="object"?C:{}},children:[$,t.jsx("span",{style:{position:"absolute",left:`${y.arrowLeft}px`,transform:"translateX(-50%)",width:0,height:0,borderLeft:"6px solid transparent",borderRight:"6px solid transparent",...y.placement==="top"?{top:"100%",borderTop:`7px solid ${w}`}:{bottom:"100%",borderBottom:`7px solid ${w}`}}})]}),document.body)]})}function yt({data:x=[],columns:c=[],initialPageSize:b=10,onRowClick:u,totalCount:C=null,page:S=null,pageSize:$=null,onPageChange:w=null,onPageSizeChange:F=null,onFilterChange:_=null,onMaxColumnsError:B=null,onSort:ee=null,sortFields:y=[],tableId:p=null,isLoading:D=!1,filtersConfig:M=null,columnResizeMinWidth:V=100,columnResizeMaxWidth:g=280}){var Be;const{userData:v}=mt(),N=(v==null?void 0:v.email)||"anonymous",ie=i.memo(({children:e,content:r,className:n=""})=>{const s=i.useRef(null),[o,l]=i.useState(!1);i.useEffect(()=>{const d=()=>{if(s.current){const W=s.current.scrollWidth>s.current.clientWidth;l(W)}};d();const A=setTimeout(d,0);return window.addEventListener("resize",d),()=>{clearTimeout(A),window.removeEventListener("resize",d)}},[e,r]);const a=t.jsx("span",{className:`truncate block ${n}`,ref:s,children:e});return o&&r?t.jsx(bt,{content:r,styling:"bg-green-2 text-gray-900 px-3 py-2 text-sm rounded-lg shadow-md border border-gray-300 max-w-xs whitespace-normal",indicatorColor:"bg-green-2",direction:"top",children:a}):a});ie.displayName="TruncatedCell";const E=C!==null&&w!==null,H=_!==null,z=ee!==null,[te,q]=i.useState(1),[ae,le]=i.useState(b),K=S!==null?S:te,R=$!==null?$:ae,U=e=>{w?w(e):q(e)},X=e=>{F?F(e):le(e)},T=9,j="action",G=i.useRef(!1),re=i.useMemo(()=>p?`dataTable_columns_${p}:${N}`:`dataTable_columns_${c.map(r=>r.id||r.key).sort().join("_")}:${N}`,[p,c,N]),ne=i.useMemo(()=>p?`dataTable_manual_change_${p}:${N}`:null,[p,N]);i.useCallback((e,r)=>{if(typeof window>"u"||!e||!r||r.length===0)return null;try{const n=localStorage.getItem(e);if(n){const o=JSON.parse(n).filter(l=>r.some(a=>(a.id||a.key)===l));if(o.length>0)return o}}catch(n){console.warn("Failed to load saved columns from localStorage:",n)}return null},[]);const[J,Ue]=i.useState({}),[Fe,qe]=i.useState(null),[Ee,ze]=i.useState("asc");i.useCallback((e,r)=>e==="csat_score"&&r==="evaluation.csat_score"?r:e,[]);const ce=z&&y.length>0?y[0][0]:Fe,pe=z&&y.length>0?y[0][1]:Ee,[wt,Re]=i.useState(()=>c.map(e=>e.id||e.key)),P=i.useCallback(e=>{if(!e||e.length===0)return e;let r=Array.from(new Set(e));r.length>T&&(r=r.slice(0,T));const s=c.map(a=>a.id||a.key).includes(j);return!r.includes(j)&&s&&(r.length>=T?r=[...r.slice(0,T-1),j]:r=[...r,j]),[...r.filter(a=>a!==j),j]},[c]),[f,Y]=i.useState(()=>{if(typeof window<"u"&&p)try{if(localStorage.getItem(`dataTable_manual_change_${p}:${N}`)==="true"){const s=localStorage.getItem(`dataTable_columns_${p}:${N}`);if(s){const o=JSON.parse(s);if(Array.isArray(o)&&o.length>0){G.current=!0;const l=o.filter(a=>c.some(d=>(d.id||d.key)===a));if(l.length>0)return l.slice(0,T)}}}}catch(n){console.warn("Failed to load saved columns from localStorage:",n)}const r=c.map(n=>n.id||n.key).slice(0,T);return P(r)}),[O,Te]=i.useState(!1),[we,Xe]=i.useState({top:0,left:0,width:0}),[Ge,We]=i.useState(new Set),[Oe,$e]=i.useState(new Set),[I,je]=i.useState(null),[Je,fe]=i.useState(null),se=i.useRef(null),Se=i.useRef(null),oe=i.useRef(null),[Pe,ke]=i.useState(null),[Ce,Ye]=i.useState({}),Qe=i.useRef(null),xe=i.useRef(null),k=e=>e.id||e.key,ge=i.useCallback(e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){const r=e.trim();if(r.endsWith("px")){const s=parseFloat(r);return Number.isFinite(s)?s:null}const n=parseFloat(r);return Number.isFinite(n)&&`${n}`===r?n:null}return null},[]),De=i.useCallback((e,r)=>Ce[e]!=null?`${Ce[e]}px`:typeof r=="number"?`${r}px`:r||"auto",[Ce]),me=i.useCallback(e=>{if(!xe.current)return;const{columnId:r,startX:n,startWidth:s,minWidth:o,maxWidth:l}=xe.current,a=e.clientX-n,d=Math.round(s+a),A=Math.min(l,Math.max(o,d));Ye(W=>({...W,[r]:A}))},[]),de=i.useCallback(()=>{xe.current=null,document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",me),document.removeEventListener("mouseup",de)},[me]),Ze=i.useCallback((e,r,n)=>{var Z;e.preventDefault(),e.stopPropagation();const s=r.id||r.key,o=ge(r.minWidth)??V,l=ge(r.maxWidth)??g,a=Math.min(o,l),d=Math.max(o,l),A=((Z=e.currentTarget.closest("th"))==null?void 0:Z.getBoundingClientRect().width)||0,W=ge(n),ue=W??Math.max(a,Math.round(A)||a),Ne=Math.min(d,Math.max(a,ue));xe.current={columnId:s,startX:e.clientX,startWidth:Ne,minWidth:a,maxWidth:d},document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",me),document.addEventListener("mouseup",de)},[g,V,me,de,ge]);i.useEffect(()=>()=>de(),[de]);const et=h.useSensors(h.useSensor(h.PointerSensor),h.useSensor(h.KeyboardSensor,{coordinateGetter:h.sortableKeyboardCoordinates})),tt=e=>{const{active:r,over:n}=e;if(n&&r.id!==n.id){if(r.id===j||n.id===j){Ae("Cannot drop columns on the Action column"),ke(null);return}G.current=!0,Y(s=>{const o=s.indexOf(r.id),l=s.indexOf(n.id);if(o!==-1&&l!==-1){const a=h.arrayMove(s,o,l),d=P(a);return ve(d),d}return s}),Re(s=>{const o=s.indexOf(r.id),l=s.indexOf(n.id);return h.arrayMove(s,o,l)})}ke(null)},rt=e=>{ke(e.active.id)},he=i.useMemo(()=>H?x||[]:!x||x.length===0?[]:x.filter(e=>Object.keys(J).every(r=>{const n=J[r];if(!n||n.trim()==="")return!0;const s=e[r];if(s==null)return!1;const o=String(s).toLowerCase();return n.toLowerCase().trim().split(/\s+/).filter(d=>d.length>0).every(d=>o.includes(d))})),[x,J,H]),be=i.useMemo(()=>z||!ce?he:[...he].sort((e,r)=>{const n=e[ce],s=r[ce];if(n==null)return 1;if(s==null)return-1;if(typeof n=="number"&&typeof s=="number")return pe==="asc"?n-s:s-n;const o=String(n).toLowerCase(),l=String(s).toLowerCase();return pe==="asc"?o.localeCompare(l):l.localeCompare(o)}),[he,ce,pe,z]),ye=i.useMemo(()=>{if(E)return x||[];{const e=(K-1)*R,r=e+R;return be.slice(e,r)}},[x,be,K,R,E]),nt=e=>{z&&ee?(ee(e),w?w(1):q(1)):(Fe===e?ze(Ee==="asc"?"desc":"asc"):(qe(e),ze("asc")),U(1))},Ie=(e,r)=>{const n=r&&r.trim()!==""?{...J,[e]:r}:Object.fromEntries(Object.entries(J).filter(([s])=>s!==e));Ue(n),H&&_&&_(n),w?w(1):q(1)},Ae=e=>{oe.current||(typeof B=="function"&&B(e),oe.current=setTimeout(()=>{oe.current=null},3e3))},ve=i.useCallback(e=>{if(typeof window<"u"&&re&&e.length>0&&G.current)try{localStorage.setItem(re,JSON.stringify(e)),ne&&localStorage.setItem(ne,"true")}catch(r){console.warn("Failed to save columns to localStorage:",r)}},[re,ne]),Me=e=>{e!==j&&(G.current=!0,Y(r=>r.includes(e)?(oe.current&&(clearTimeout(oe.current),oe.current=null),r.length===1||($e(n=>new Set(n).add(e)),setTimeout(()=>{Y(n=>{const s=n.filter(l=>l!==e),o=P(s);return ve(o),o}),$e(n=>{const s=new Set(n);return s.delete(e),s})},200)),r):r.length>=T?(Ae("Maximum 9 column selection allowed"),r):(We(n=>new Set(n).add(e)),setTimeout(()=>{Y(n=>{const s=n.includes(e)?n:[...n,e],o=P(s);return ve(o),o}),We(n=>{const s=new Set(n);return s.delete(e),s})},200),r)))},st=(e,r)=>{f[r]!==j&&je(r)},ot=()=>{je(null),fe(null)},it=(e,r)=>{e.preventDefault(),I!==null&&I!==r&&fe(r)},at=()=>{fe(null)},lt=(e,r)=>{e.preventDefault(),I!==null&&I!==r&&f[r]!==j&&f[I]!==j&&(G.current=!0,Y(n=>{const s=h.arrayMove(n,I,r),o=P(s);return ve(o),o})),je(null),fe(null)};i.useEffect(()=>{Re(e=>{const r=f.filter(o=>e.includes(o)),n=f.filter(o=>!e.includes(o)),s=e.filter(o=>!f.includes(o));return[...r,...n,...s]})},[f]),i.useEffect(()=>{if(typeof window<"u"&&re&&f.length>0&&G.current)try{const e=P(f);localStorage.setItem(re,JSON.stringify(e)),ne&&localStorage.setItem(ne,"true")}catch(e){console.warn("Failed to save columns to localStorage:",e)}},[f,re,ne]),i.useEffect(()=>{if(c.length>0&&f.length===0){if(typeof window<"u"&&p)try{if(localStorage.getItem(`dataTable_manual_change_${p}:${N}`)==="true"){const n=localStorage.getItem(`dataTable_columns_${p}:${N}`);if(n){const s=JSON.parse(n);if(Array.isArray(s)&&s.length>0){const o=s.filter(l=>c.some(a=>(a.id||a.key)===l));if(o.length>0){G.current=!0,Y(o.slice(0,T));return}}}}}catch(r){console.warn("Failed to load saved columns from localStorage:",r)}const e=c.map(r=>r.id||r.key);Y(P(e.slice(0,T)))}},[c,p,N,P]);const Q=i.useMemo(()=>{const e=f.map(r=>c.find(n=>k(n)===r)).filter(Boolean);return P(e.map(k)).map(r=>c.find(n=>k(n)===r)).filter(Boolean)},[c,f]),ct=i.useMemo(()=>Q.some(e=>e.filterable===!0),[Q]);i.useEffect(()=>{if(!O||!se.current)return;const e=()=>{if(se.current){const r=se.current.getBoundingClientRect();Xe({top:r.bottom,left:r.left,width:Math.max(r.width||220,220)})}};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[O]),i.useEffect(()=>{const e=r=>{O&&se.current&&!se.current.contains(r.target)&&Se.current&&!Se.current.contains(r.target)&&Te(!1)};if(O)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[O]);const dt=f.length===1?((Be=c.find(e=>(e.id||e.key)===f[0]))==null?void 0:Be.label)||"1 selected":`${f.length} selected`;function ut({column:e,isHeaderRow:r=!0}){const n=k(e),s=n===j,o=De(n,e.width),{attributes:l,listeners:a,setNodeRef:d,transform:A,transition:W,isDragging:ue}=h.useSortable({id:n}),Ne={transform:h.CSS.Transform.toString(A),transition:W,opacity:ue?.5:1,width:o,minWidth:o};let Z=!1;if(z&&y.length>0){const m=y[0][0];(m===n||m==="csat_score"&&n==="evaluation.csat_score")&&(Z=!0)}else Z=ce===n;const ft=pe==="asc",xt=e.filterable===!0;return r?t.jsx("th",{ref:d,style:{...Ne,padding:"12px 14px",textAlign:s?"center":"left",fontWeight:650,fontSize:"11px",letterSpacing:"0.14em",textTransform:"uppercase",color:"rgba(30, 33, 37, 0.62)",cursor:e.sortable!==!1?"pointer":"default",width:o,borderRight:"1px solid rgba(52, 58, 64, 0.06)",userSelect:"none",background:"var(--primary-foreground)",borderBottom:"1px solid rgba(52, 58, 64, 0.12)",position:"sticky",top:0,zIndex:10,fontFamily:"var(--font-sans)"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",justifyContent:s?"center":"flex-start",position:"relative",minHeight:20},children:[!s&&t.jsx("div",{...l,...a,style:{cursor:"grab",color:"rgba(30, 33, 37, 0.32)"},children:t.jsx(L.GripVertical,{size:12})}),t.jsx("span",{onClick:()=>e.sortable!==!1&&nt(n),style:{cursor:e.sortable!==!1?"pointer":"default"},children:e.label.toUpperCase()}),e.sortable!==!1&&Z&&t.jsx("span",{children:ft?t.jsx(L.ChevronUp,{size:12}):t.jsx(L.ChevronDown,{size:12})}),!s&&t.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e.label||n} column`,title:"Drag to resize column",onMouseDown:m=>Ze(m,e,o),onClick:m=>m.stopPropagation(),style:{position:"absolute",top:0,right:-1,width:14,height:"100%",cursor:"col-resize",zIndex:4,display:"flex",alignItems:"center",justifyContent:"center",color:"rgba(30, 33, 37, 0.56)"},onMouseEnter:m=>{m.currentTarget.style.background="rgba(30, 33, 37, 0.08)",m.currentTarget.style.color="rgba(30, 33, 37, 0.86)"},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.currentTarget.style.color="rgba(30, 33, 37, 0.56)"},children:t.jsx(gt,{size:10,color:"currentColor"})})]})}):t.jsx("th",{style:{width:o,minWidth:o,backgroundColor:"var(--primary-foreground)"},className:"sticky top-[57px] z-10 border-b border-[var(--border-strong)] px-4 py-2 text-left",children:xt?t.jsxs("div",{className:"relative",children:[t.jsx(L.Filter,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--text-faint)] pointer-events-none"}),t.jsx("input",{type:"text",placeholder:"Filter...",value:J[n]||"",onChange:m=>{m.stopPropagation(),Ie(n,m.target.value)},onKeyDown:m=>m.stopPropagation(),onMouseDown:m=>m.stopPropagation(),className:"w-full pl-7 pr-2 py-1.5 text-xs border border-[var(--border)] rounded text-[var(--text-ink)] placeholder:text-[var(--text-faint)] focus:outline-none focus:border-[var(--border-hover)] focus:ring-1 focus:ring-[var(--focus)] transition-colors",style:{fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)"},autoComplete:"off"})]}):t.jsx("div",{className:"h-[34px]"})})}const _e=Pe?c.find(e=>k(e)===Pe):null,pt=O?t.jsxs("div",{ref:Se,className:"flex flex-col overflow-auto z-[49] min-w-[220px]",style:{position:"fixed",top:`${we.top}px`,left:`${we.left}px`,width:we.width||220,maxHeight:"400px",fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)",borderRadius:"0 0 8px 8px",boxShadow:"4px 4px 6px 0px #6D70681A, -4px 0px 6px 0px #6D70681A",border:"1px solid rgba(52, 58, 64, 0.12)",borderTop:"none"},children:[f.map((e,r)=>{const n=c.find(d=>k(d)===e);if(!n)return null;const s=f.indexOf(e),o=I===s,l=Je===s,a=e===j;return t.jsxs(i.Fragment,{children:[t.jsxs("div",{draggable:!a,onDragStart:a?void 0:d=>st(d,s),onDragEnd:a?void 0:ot,onDragOver:a?void 0:d=>it(d,s),onDragLeave:a?void 0:at,onDrop:a?void 0:d=>lt(d,s),className:`flex items-center gap-2 px-3 py-2 rounded transition-all ${a?"cursor-default opacity-100":"cursor-move"} ${!a&&o?"opacity-50":""} ${!a&&l&&I!==null&&I!==s?"ring-2 ring-green-2 ring-offset-1":""}`,children:[!a&&t.jsx("svg",{className:"h-4 w-4 text-gray-600 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8h16M4 12h16M4 16h16"})}),t.jsx("button",{type:"button",onClick:d=>{d.preventDefault(),d.stopPropagation(),a||Me(e)},className:`h-4 w-4 rounded-[2px] border flex items-center justify-center transition-colors flex-shrink-0 ${a?"bg-green-2 border-green-2 cursor-default":Oe.has(e)?"bg-white border-gray-300":"bg-green-2 border-green-2"}`,children:!Oe.has(e)&&t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,style:{color:"#1E2125"},children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsx("span",{className:"text-sm text-gray-900 flex-1",style:{fontFamily:"var(--font-sans)"},children:n.label})]}),r<f.length-1&&t.jsx(Le,{})]},`selected-${e}-${r}`)}),c.filter(e=>!f.includes(k(e))).map((e,r)=>{const n=k(e),s=Ge.has(n),o=c.filter(l=>!f.includes(k(l))).indexOf(e);return t.jsxs(i.Fragment,{children:[f.length>0&&o===0&&t.jsx(Le,{}),t.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 hover:bg-gray-50 rounded cursor-pointer transition-colors",onClick:l=>{l.preventDefault(),Me(n)},children:[t.jsx("button",{type:"button",onClick:l=>{l.preventDefault(),l.stopPropagation(),Me(n)},className:`h-4 w-4 rounded-[2px] border flex items-center justify-center transition-colors flex-shrink-0 ${s?"bg-green-2 border-green-2":"bg-white border-gray-300"}`,children:s&&t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,style:{color:"#1E2125"},children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsx("span",{className:"text-sm text-gray-900 flex-1",children:e.label})]}),o<c.filter(l=>!f.includes(k(l))).length-1&&t.jsx(Le,{})]},`unselected-${n}`)})]}):null;return t.jsxs("div",{className:"w-full",style:{top:"130px",position:"sticky",zIndex:35,backgroundColor:"var(--primary-foreground)"},children:[c.length>0&&t.jsx("div",{className:"pt-2 pb-1",style:{position:"sticky",zIndex:35,backgroundColor:"var(--primary-foreground)"},children:t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("div",{className:"mb-1 ml-1.5",children:t.jsx("p",{className:"text-xs font-medium text-gray-600",style:{fontFamily:"var(--font-sans)"},children:"Select Columns"})}),t.jsxs("div",{ref:se,className:"inline-flex items-center justify-between gap-2 px-4 py-2.5 cursor-pointer transition-colors text-sm font-medium text-gray-900 border border-gray-300 min-w-[220px]",onClick:()=>Te(!O),style:{fontFamily:"var(--font-sans)",backgroundColor:"var(--primary-foreground)",borderRadius:O?"8px 8px 0 0":"8px"},children:[t.jsx("span",{children:dt}),O?t.jsx(L.ChevronUp,{size:16}):t.jsx(L.ChevronDown,{size:16})]}),O&&Ve.createPortal(pt,document.body)]}),M&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"h-9 mt-[1.5rem] w-px bg-gray-300 flex-shrink-0"}),t.jsx("div",{className:"flex-shrink-0 mt-[1.5rem]",children:t.jsx(Ke,{dateRangePicker:M.dateRangePicker,onWeekToDate:M.onWeekToDate,exportConfig:M.exportConfig,filterChipsConfig:M.filterChipsConfig,trailingActions:M.trailingActions})})]})]})}),c.length>0&&Q.length>0?t.jsxs(h.DndContext,{sensors:et,collisionDetection:h.closestCenter,onDragStart:rt,onDragEnd:tt,children:[t.jsxs("div",{className:"rounded-[14px]",style:{border:"1px solid rgba(52, 58, 64, 0.12)",borderBottom:"1px solid rgba(52, 58, 64, 0.12)",overflow:"hidden",background:"var(--primary-foreground)",position:"relative",top:"0.5rem"},children:[D&&t.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(255, 255, 255, 0.9)",backdropFilter:"blur(2px)",zIndex:20,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",borderRadius:"14px"},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[t.jsx("p",{style:{fontSize:"13px",color:"rgba(30, 33, 37, 0.6)",margin:0},children:"Loading..."}),t.jsx(ht,{src:"/BrandLoading.gif",alt:"Loading",width:50,height:50,unoptimized:!0,className:"mt-1"})]})}),t.jsx("div",{className:"overflow-x-auto custom-thin-scrollbar-hidden",ref:Qe,style:{maxHeight:"500px",overflowY:"auto",position:"relative",zIndex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px",fontFamily:"var(--font-sans)"},children:[t.jsxs("thead",{children:[t.jsx("tr",{children:t.jsx(h.SortableContext,{items:f,strategy:h.horizontalListSortingStrategy,children:Q.map(e=>t.jsx(ut,{column:e,isHeaderRow:!0},`header-${k(e)}`))})}),ct&&t.jsx("tr",{children:Q.map(e=>{const r=k(e),n=De(r,e.width),s=e.filterable===!0;return t.jsx("th",{style:{padding:"8px 14px",background:"var(--primary-foreground)",borderBottom:"1px solid rgba(52, 58, 64, 0.10)",position:"sticky",top:"41px",zIndex:10,width:n,fontFamily:"var(--font-sans)"},children:s?t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",placeholder:"Filter...",value:J[r]||"",onChange:o=>{o.stopPropagation(),Ie(r,o.target.value)},onKeyDown:o=>o.stopPropagation(),onMouseDown:o=>o.stopPropagation(),style:{width:"100%",padding:"4px 8px 4px 26px",fontSize:"11.5px",border:"1px solid rgba(52, 58, 64, 0.16)",borderRadius:"6px",background:"var(--primary-foreground)",color:"rgba(30, 33, 37, 0.78)",outline:"none",fontFamily:"var(--font-sans)"},onFocus:o=>{o.target.style.borderColor="rgba(231, 212, 162, 0.65)",o.target.style.background="var(--primary-foreground)"},onBlur:o=>{o.target.style.borderColor="rgba(52, 58, 64, 0.16)",o.target.style.background="var(--primary-foreground)"},autoComplete:"off"}),t.jsx(L.Filter,{size:11,style:{position:"absolute",left:"8px",top:"50%",transform:"translateY(-50%)",color:"rgba(30, 33, 37, 0.42)",pointerEvents:"none"}})]}):t.jsx("div",{className:"h-[34px]"})},`filter-${r}`)})})]}),t.jsx("tbody",{children:!D&&ye.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:Q.length,style:{padding:"32px",textAlign:"center",color:"rgba(30, 33, 37, 0.42)",fontSize:"12px",fontFamily:"var(--font-sans)"},children:"No results found"})}):!D&&ye.length>0?ye.map((e,r)=>t.jsx("tr",{"data-row-id":e.id||r,style:{borderBottom:"1px solid rgba(52, 58, 64, 0.08)",cursor:u?"pointer":"default",transition:"background 0.15s ease"},onClick:u?n=>{n.stopPropagation(),u(e,r)}:void 0,onMouseEnter:n=>{n.currentTarget.style.background="rgba(231, 212, 162, 0.12)"},onMouseLeave:n=>{n.currentTarget.style.background="transparent"},children:Q.map(n=>{const s=k(n),o=De(s,n.width),l=e[s],a=n.render?n.render(l,e):l,d=o&&o!=="auto",A=typeof a=="string"&&a.trim()!=="",W=d&&A,ue=W?t.jsx(ie,{content:a,children:a}):a;return t.jsx("td",{style:{padding:"10px 14px",color:"rgba(30, 33, 37, 0.78)",fontSize:"13px",borderRight:"1px solid rgba(52, 58, 64, 0.04)",width:o,fontFamily:"var(--font-sans)",...W&&{maxWidth:o||"200px"}},children:ue},s)})},r)):null})]})})]}),t.jsx(h.DragOverlay,{children:_e?t.jsx("div",{className:"bg-[var(--paper-high)] border border-[var(--border-strong)] rounded px-4 py-2 shadow-lg",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(L.GripVertical,{size:14,className:"text-[var(--text-faint)]"}),t.jsx("span",{className:"text-sm font-semibold text-[var(--text-ink)]",children:_e.label})]})}):null})]}):null,(E?C>0:be.length>0)&&t.jsx("div",{className:"border-t border-gray-200 rounded-b-[14px]",style:{backgroundColor:"var(--primary-foreground)"},children:t.jsx(He.Pagination,{page:K,pageSizeOptions:[5,10,20,50,100],pageSize:R,totalCount:E?C:be.length,currentDataLength:ye.length,onPageChange:U,onPageSizeChange:F?e=>{X(e),U(1)}:e=>{X(e),U(1)},showPageSizeSelector:!0})})]})}function vt({title:x="Summary stats",stats:c=[],columns:b=2}){return t.jsxs("div",{style:{fontFamily:"system-ui, -apple-system, sans-serif"},children:[t.jsx("div",{className:"text-[11px] tracking-[0.14em] uppercase mb-[10px]",style:{color:"rgba(30, 33, 37, 0.42)",fontWeight:650},children:x}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${b}, minmax(0, 1fr))`,gap:"10px"},children:c.map((u,C)=>t.jsxs("div",{style:{position:"relative",border:"1px solid rgba(52, 58, 64, 0.12)",borderRadius:"12px",background:"rgba(255, 255, 255, 0.72)",padding:u.accentColor?"10px 10px 10px 14px":"10px",minHeight:"62px",display:"flex",flexDirection:"column",justifyContent:"center",gap:"5px",overflow:"hidden"},children:[u.accentColor&&t.jsx("div",{style:{position:"absolute",left:0,top:0,bottom:0,width:"4px",background:u.accentColor,borderTopLeftRadius:"12px",borderBottomLeftRadius:"12px"}}),t.jsx("div",{className:"text-[10px] tracking-[0.14em] uppercase",style:{color:"rgba(30, 33, 37, 0.42)",fontWeight:650,lineHeight:1.1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.label}),t.jsx("div",{style:{fontSize:"13px",color:u.valueStyle==="muted"?"rgba(30, 33, 37, 0.56)":"rgba(30, 33, 37, 0.78)",fontWeight:700,lineHeight:1.15,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:u.valueStyle==="mono"?"ui-monospace, monospace":"inherit"},children:u.value}),u.subtext&&t.jsx("div",{style:{fontSize:"11px",color:"rgba(30, 33, 37, 0.52)",lineHeight:1.15,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.subtext})]},C))})]})}exports.DataTable=yt;exports.DataTableFilters=Ke;exports.SummaryStatsPanel=vt;
|
|
2
2
|
//# sourceMappingURL=data.cjs.js.map
|