2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
import{r as l,j as e,R as z}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{u as O,b as A,d as $,ai as E,aj as H,a8 as R,a9 as j,ak as W}from"./main-af3pcbZa.js";function T(){var C;const c=O(),{activeSite:r,setActiveSite:g,loadActiveSite:m}=A(),{activeSector:a,sectors:s,setActiveSector:i,loading:o}=$(),{user:d,refreshUser:b,isAuthenticated:v}=E(),[f,p]=l.useState(!1),[u,B]=l.useState([]),[y,N]=l.useState(!0),w=l.useRef(null),[k,h]=l.useState(!1),S=l.useRef(null);l.useEffect(()=>{v&&d&&b().catch(t=>{console.debug("SiteAndSectorSelector: Failed to refresh user (non-critical):",t)})},[v]),l.useEffect(()=>{F(),r||m()},[(C=d==null?void 0:d.account)==null?void 0:C.id]);const F=async()=>{try{N(!0);const n=((await H()).results||[]).filter(x=>x.is_active);B(n)}catch(t){console.error("Failed to load sites:",t),c.error(`Failed to load sites: ${t.message}`)}finally{N(!1)}},M=async t=>{try{await W(t);const n=u.find(x=>x.id===t);n&&(g(n),c.success(`Switched to "${n.name}"`)),p(!1)}catch(n){c.error(`Failed to switch site: ${n.message}`)}},L=t=>{if(t===null)i(null),h(!1);else{const n=s.find(x=>x.id===t);n&&(i(n),h(!1))}};return r?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative inline-block",children:[e.jsxs("button",{ref:w,onClick:()=>p(!f),className:"flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-brand-200 rounded-lg hover:bg-brand-50 hover:border-brand-300 dark:bg-gray-800 dark:text-gray-300 dark:border-brand-700/50 dark:hover:bg-brand-500/10 dark:hover:border-brand-600/50 transition-colors dropdown-toggle","aria-label":"Switch site",disabled:y||u.length===0,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-500 dark:text-brand-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})}),e.jsx("span",{className:"max-w-[150px] truncate",children:y?"Loading...":(r==null?void 0:r.name)||"Select Site"})]}),e.jsx("svg",{className:`w-4 h-4 text-brand-500 dark:text-brand-400 transition-transform ${f?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsx(R,{isOpen:f,onClose:()=>p(!1),anchorRef:w,placement:"bottom-left",className:"w-64 p-2",children:u.map(t=>e.jsxs(j,{onItemClick:()=>M(t.id),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${(r==null?void 0:r.id)===t.id?"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300":"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300"}`,children:[e.jsx("span",{className:"flex-1",children:t.name}),(r==null?void 0:r.id)===t.id&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]},t.id))})]}),!o&&s.length>0&&e.jsxs("div",{className:"relative inline-block",children:[e.jsxs("button",{ref:S,onClick:()=>h(!k),className:"flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-brand-200 rounded-lg hover:bg-brand-50 hover:border-brand-300 dark:bg-gray-800 dark:text-gray-300 dark:border-brand-700/50 dark:hover:bg-brand-500/10 dark:hover:border-brand-600/50 transition-colors dropdown-toggle","aria-label":"Select sector",disabled:o||s.length===0,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-500 dark:text-brand-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})}),e.jsx("span",{className:"max-w-[150px] truncate",children:o?"Loading...":(a==null?void 0:a.name)||"All Sectors"})]}),e.jsx("svg",{className:`w-4 h-4 text-brand-500 dark:text-brand-400 transition-transform ${k?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs(R,{isOpen:k,onClose:()=>h(!1),anchorRef:S,placement:"bottom-right",className:"w-64 p-2 overflow-y-auto max-h-[300px]",children:[e.jsxs(j,{onItemClick:()=>L(null),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${a?"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300":"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300"}`,children:[e.jsx("span",{className:"flex-1",children:"All Sectors"}),!a&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]}),s.map(t=>e.jsxs(j,{onItemClick:()=>L(t.id),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${(a==null?void 0:a.id)===t.id?"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300":"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300"}`,children:[e.jsx("span",{className:"flex-1",children:t.name}),(a==null?void 0:a.id)===t.id&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]},t.id))]})]})]}):null}function I({title:c,lastUpdated:r,showRefresh:g=!1,onRefresh:m,className:a="",badge:s,hideSiteSector:i=!1}){const{activeSite:o}=A(),{activeSector:d}=$(),b={blue:"bg-blue-600 dark:bg-blue-500",green:"bg-green-600 dark:bg-green-500",purple:"bg-purple-600 dark:bg-purple-500",orange:"bg-orange-600 dark:bg-orange-500",red:"bg-red-600 dark:bg-red-500",indigo:"bg-indigo-600 dark:bg-indigo-500"};return e.jsxs("div",{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 ${a}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[s&&e.jsx("div",{className:`flex items-center justify-center w-10 h-10 rounded-xl ${b[s.color]} flex-shrink-0`,children:s.icon&&typeof s.icon=="object"&&"type"in s.icon?z.cloneElement(s.icon,{className:"text-white size-5"}):s.icon}),e.jsx("h2",{className:"text-2xl font-bold text-gray-800 dark:text-white/90",children:c})]}),!i&&e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r&&e.jsx(e.Fragment,{children:e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Last updated: ",r.toLocaleTimeString()]})}),o&&e.jsxs(e.Fragment,{children:[r&&e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Site: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:o.name})]})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Sector: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:d.name})]})]}),!d&&o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Sector: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:"All Sectors"})]})]})]}),i&&r&&e.jsx("div",{className:"flex items-center gap-3 mt-1",children:e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Last updated: ",r.toLocaleTimeString()]})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[!i&&e.jsx(T,{}),g&&m&&e.jsx("button",{onClick:m,className:"px-4 py-2 text-sm font-medium text-brand-500 hover:text-brand-600 border border-brand-200 rounded-lg hover:bg-brand-50 dark:border-brand-800 dark:hover:bg-brand-500/10 transition-colors",children:"Refresh"})]})]})}export{I as P};
|