import { FC } from 'react';

import { IconArrowLeft, IconX } from '@material-hu/icons/tabler';
import IconButton from '@material-hu/mui/IconButton';
import Stack from '@material-hu/mui/Stack';

import HuPills from '@material-hu/components/design-system/Pills';
import HuTitle from '@material-hu/components/design-system/Title';

import { useLokaliseTranslation } from 'src/utils/i18n';

type Props = {
  onClose: () => void;
  title: string;
  onGoBack?: () => void;
  pill?: string;
  sticky?: boolean;
};

const SectionHeader: FC<Props> = props => {
  const { onClose, onGoBack, pill, title, sticky = false } = props;
  const { t } = useLokaliseTranslation(['time_tracker', 'general']);

  return (
    <Stack
      sx={{
        alignItems: 'center',
        alignSelf: 'flex-start',
        backgroundColor: ({ palette }) =>
          palette.new.background.layout.tertiary,
        flexDirection: 'row',
        justifyContent: 'space-between',
        px: 3,
        py: 1,
        width: '100%',
        position: sticky ? 'sticky' : 'relative',
        top: 0,
        zIndex: 10,
      }}
    >
      <Stack
        sx={{
          alignItems: 'center',
          flexDirection: 'row',
          gap: 1,
        }}
      >
        {onGoBack && (
          <IconButton
            onClick={onGoBack}
            aria-label={t('general:back')}
          >
            <IconArrowLeft />
          </IconButton>
        )}
        <HuTitle
          variant="L"
          title={title}
        />
        {pill && (
          <HuPills
            label={pill}
            type="neutral"
            hasIcon={false}
          />
        )}
      </Stack>
      <IconButton
        onClick={onClose}
        aria-label={t('general:close')}
      >
        <IconX />
      </IconButton>
    </Stack>
  );
};

export default SectionHeader;
