import {
Anchor,
Badge,
Box,
Burger,
Button,
Center,
Collapse,
Divider,
Drawer,
Group,
Image,
Popover,
ScrollArea,
SimpleGrid,
Switch,
Text,
ThemeIcon,
UnstyledButton,
rem,
useComputedColorScheme,
useMantineColorScheme,
useMantineTheme,
} from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import {
IconBrandWordpress,
IconCalendarClock,
IconChevronDown,
IconCode,
IconCopyOff,
IconDatabase,
IconExternalLink,
IconMoonStars,
IconRecycle,
IconSun,
} from '@tabler/icons-react';
import { __ } from '@wordpress/i18n';
import { useState } from 'react';
import classes from './Header.module.css';
import Logo from './logo.png';
export function Header({ setActiveView }: { setActiveView: (tab: string) => void }) {
const [drawerOpened, { toggle: toggleDrawer, close: closeDrawer }] = useDisclosure(false);
const [linksOpened, { toggle: toggleLinks }] = useDisclosure(false);
const theme = useMantineTheme();
// The switch shows the scheme actually in use ("auto" resolved against the OS) and only writes a
// scheme when the user flips it. It used to copy the scheme into local state at mount and push it
// back on every render, so the provider's defaultColorScheme="auto" never survived the first paint.
const { setColorScheme } = useMantineColorScheme();
const computedColorScheme = useComputedColorScheme('light');
const [opened, setOpened] = useState(false);
function setActiveViewAndClosePopover(tab: string) {
setActiveView(tab);
if (drawerOpened) {
return closeDrawer();
}
setOpened(false);
}
const featureMenuData = [
{
icon: IconRecycle,
title: __('Safely Trash', 'scotty'),
description: __('Delete the unnecessary records from your database', 'scotty'),
onClick: () => setActiveViewAndClosePopover('trash'),
},
{
icon: IconCopyOff,
title: __('Check duplicates', 'scotty'),
description: __('Check and analyze your database for duplicate records', 'scotty'),
onClick: () => setActiveViewAndClosePopover('duplicates'),
},
{
icon: IconDatabase,
title: __('Database Sneak Peek', 'scotty'),
description: __('Have a look at the database tables and optimize them', 'scotty'),
onClick: () => setActiveViewAndClosePopover('database'),
},
{
icon: IconCalendarClock,
title: __('Cron jobs', 'scotty'),
description: __('Cron jobs to run the tasks at regular intervals', 'scotty'),
onClick: () => setActiveViewAndClosePopover('cron'),
},
{
icon: IconCode,
title: __('Shortcode', 'scotty'),
description: __('Have a look at the shortcode and use them in your posts', 'scotty'),
onClick: () => setActiveViewAndClosePopover('shortcode'),
},
{
icon: IconBrandWordpress,
title: __('WordPress Advanced', 'scotty'),
description: __('Settings for advanced WordPress features', 'scotty'),
onClick: () => setActiveViewAndClosePopover('wordpress'),
},
];
const sunIcon = (
);
const moonIcon = (
);
const links = featureMenuData.map((item) => (