import { useLabelsMenu, useStatusMenu, useTagMenu, useUserRoute, } from '@/hooks/Mapper/components/contexts/ContextMenuSystem/hooks'; import { useMemo } from 'react'; import { getSystemById } from '@/hooks/Mapper/helpers'; import classes from './ContextMenuSystem.module.scss'; import { PrimeIcons } from 'primereact/api'; import { ContextMenuSystemProps } from '@/hooks/Mapper/components/contexts'; import { useWaypointMenu } from '@/hooks/Mapper/components/contexts/hooks'; import { FastSystemActions } from '@/hooks/Mapper/components/contexts/components'; import { useMapCheckPermissions } from '@/hooks/Mapper/mapRootProvider/hooks/api'; import { UserPermission } from '@/hooks/Mapper/types/permissions.ts'; import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormholeSpace.ts'; import { getSystemStaticInfo } from '@/hooks/Mapper/mapRootProvider/hooks/useLoadSystemStatic'; import { MapAddIcon, MapDeleteIcon } from '@/hooks/Mapper/icons'; import { PingType } from '@/hooks/Mapper/types'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; import clsx from 'clsx'; import { MenuItem } from 'primereact/menuitem'; import { MenuItemWithInfo, WdMenuItem } from '@/hooks/Mapper/components/ui-kit'; export const useContextMenuSystemItems = ({ onDeleteSystem, onLockToggle, onHubToggle, onUserHubToggle, onTogglePing, onSystemTag, onSystemStatus, onSystemLabels, onCustomLabelDialog, onOpenSettings, onWaypointSet, systemId, hubs, userHubs, systems, }: Omit) => { const getTags = useTagMenu(systems, systemId, onSystemTag); const getStatus = useStatusMenu(systems, systemId, onSystemStatus); const getLabels = useLabelsMenu(systems, systemId, onSystemLabels, onCustomLabelDialog); const getWaypointMenu = useWaypointMenu(onWaypointSet); const canLockSystem = useMapCheckPermissions([UserPermission.LOCK_SYSTEM]); const canManageSystem = useMapCheckPermissions([UserPermission.UPDATE_SYSTEM]); const canDeleteSystem = useMapCheckPermissions([UserPermission.DELETE_SYSTEM]); const getUserRoutes = useUserRoute({ userHubs, systemId, onUserHubToggle }); const { data: { pings, isSubscriptionActive }, } = useMapRootState(); const ping = useMemo(() => (pings.length === 1 ? pings[0] : undefined), [pings]); const isShowPingBtn = useMemo(() => { if (!isSubscriptionActive) { return false; } if (pings.length === 0) { return true; } return pings[0].solar_system_id === systemId; }, [isSubscriptionActive, pings, systemId]); return useMemo((): MenuItem[] => { const system = systemId ? getSystemById(systems, systemId) : undefined; const systemStaticInfo = getSystemStaticInfo(systemId)!; const hasPing = ping?.solar_system_id === systemId; if (!system || !systemId) { return []; } return [ { className: classes.FastActions, template: () => { return ( ); }, }, { separator: true }, getTags(), getStatus(), ...getLabels(), ...getWaypointMenu(systemId, systemStaticInfo.system_class), { label: !hubs.includes(systemId) ? 'Add Route' : 'Remove Route', icon: !hubs.includes(systemId) ? ( ) : ( ), command: onHubToggle, }, ...getUserRoutes(), { separator: true }, { command: () => onTogglePing(PingType.Rally, systemId, hasPing), disabled: !isShowPingBtn, template: () => { const iconClasses = clsx({ 'pi text-cyan-400 hero-signal': !hasPing, 'pi text-red-400 hero-signal-slash': hasPing, }); if (isShowPingBtn) { return {!hasPing ? 'Ping: RALLY' : 'Cancel: RALLY'}; } return ( {!hasPing ? 'Ping: RALLY' : 'Cancel: RALLY'} ); }, }, ...(system.locked && canLockSystem ? [ { label: 'Unlock', icon: PrimeIcons.LOCK_OPEN, command: onLockToggle, }, ] : []), ...(!system.locked && canManageSystem ? [ { label: 'Lock', icon: PrimeIcons.LOCK, command: onLockToggle, }, ] : []), ...(canDeleteSystem && !system.locked ? [ { separator: true }, { command: onDeleteSystem, disabled: hasPing, template: () => { if (!hasPing) { return Delete; } return ( Delete ); }, }, ] : []), ]; }, [ systemId, systems, getTags, getStatus, getLabels, getWaypointMenu, getUserRoutes, hubs, onHubToggle, canLockSystem, onLockToggle, canDeleteSystem, onDeleteSystem, onOpenSettings, onTogglePing, ping, isShowPingBtn, ]); };