import type { ReactElement, ButtonHTMLAttributes } from 'react'; import { cva, type VariantProps } from 'class-variance-authority'; import { cn } from '@/lib/utils'; import { useAppSelector } from '@/hooks/redux-hooks'; const secondaryButtonVariants = cva( 'inline-flex items-center justify-center px-3 py-1.5 rounded text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer', { variants: { variant: { default: 'bg-[#23dce1] text-[#112868] hover:bg-[#112868] hover:text-[#23dce1]', disabled: 'bg-[#23dce1] text-[#112868] opacity-50', }, }, defaultVariants: { variant: 'default', }, } ); interface SecondaryButtonProps extends ButtonHTMLAttributes, VariantProps { children: React.ReactNode; } export const SecondaryButton = ({ children, variant, className, disabled, ...props }: SecondaryButtonProps): ReactElement => { const buttonVariant = disabled ? 'disabled' : variant || 'default'; const { theme } = useAppSelector((state) => state.theme); const { roles } = useAppSelector((state) => state.auth); // Check if user is tenant admin (not super_admin) or if we're on a tenant route let rolesArray: string[] = []; if (Array.isArray(roles)) { rolesArray = roles; } else if (typeof roles === 'string') { try { rolesArray = JSON.parse(roles); } catch { rolesArray = []; } } const isSuperAdmin = rolesArray.includes('super_admin'); const isTenantAdmin = !isSuperAdmin && rolesArray.length > 0; // Check if we're on a tenant route (for login page where user might not be authenticated) const isTenantRoute = typeof window !== 'undefined' && window.location.pathname.startsWith('/tenant'); // Use theme colors for tenant admin or tenant routes, default colors for super admin const shouldUseTheme = (isTenantAdmin || (isTenantRoute && !isSuperAdmin)) && theme; const primaryColor = shouldUseTheme && theme.primary_color ? theme.primary_color : '#112868'; const secondaryColor = shouldUseTheme && theme.secondary_color ? theme.secondary_color : '#23dce1'; return ( ); };