import { useState } from 'react'
import { NavLink, Outlet } from 'react-router-dom'
import { NAV_GROUPS } from '../api/config.js'
import { AGENTS } from '../api/agents.js'
import { rolesOf, visibleStages } from '../api/permissions.js'
import { useStageCounts } from '../api/portfolio.jsx'
import { useZino } from '../api/provider.jsx'
import AgentCard from '../components/AgentCard.jsx'
import AgentChip from '../components/AgentChip.jsx'
import Icon from '../components/Icon.jsx'
import { KIND_ICON } from '../api/display.js'
import GlobalSearch from './GlobalSearch.jsx'
import UserMenu from './UserMenu.jsx'
import logo from '../assets/brand/zurich_logo.webp'
import './Shell.css'
/**
* The sidebar groups the pipeline by WHO IS HOLDING each lead, not by where it
* sits in the process. Fourteen flat stages answer "what is the process?", which
* is not the question anyone signing in has; these answer "is anything waiting
* on me?". Queues that need a person are named by what they want done.
*
* The counts come from PortfolioProvider — one fetch shared with the overview,
* so the two cannot disagree. The badge counts leads whose PHASE needs a
* person, not leads in the state (see phaseOf); a dot marks a queue holding a
* renewal inside a week.
*
* The closed states are folded away: three of the twelve, reporting rather
* than work, and at equal weight they made the live queues harder to find.
*/
export default function Shell() {
const { user } = useZino()
const roles = rolesOf(user)
// The sidebar shows the queues this role WORKS in. Reporting on the rest
// lives on the overview, which counts the whole book for everyone.
const stages = visibleStages(roles)
const { counts, ready } = useStageCounts()
const [openAgent, setOpenAgent] = useState(null)
// One queue row. Extracted because the live groups and the folded Closed
// group render the same thing and drifted apart when they did not.
const queue = (s) => {
const c = counts[s.uid] || { total: 0, waiting: 0, working: 0, urgent: 0 }
const n = s.kind === 'end' ? c.total : c.waiting
return (