import React, { ReactNode } from 'react';
import { Box, Button, ButtonProps, Heading } from '@wix/design-system';

export interface CustomDrawerLayoutProps {
  dataHook?: string;
  title?: ReactNode;
  children?: ReactNode;
  primaryButtonText?: ReactNode;
  secondaryButtonText?: ReactNode;
  secondaryButtonProps?: Partial<Omit<ButtonProps, 'as'>>;
  primaryButtonProps?: Partial<Omit<ButtonProps, 'as'>>;
  primaryButtonOnClick?: () => void;
  secondaryButtonOnClick?: () => void;
}

export function CustomDrawerLayout(props: CustomDrawerLayoutProps) {
  const {
    dataHook,
    title,
    children,
    primaryButtonText,
    secondaryButtonText,
    secondaryButtonProps,
    primaryButtonProps,
    primaryButtonOnClick,
    secondaryButtonOnClick,
  } = props;

  return (
    <Box
      dataHook={dataHook}
      direction="vertical"
      padding="SP3"
      backgroundColor="white"
      borderRadius="12px"
    >
      {title && (
        <Box
          direction="vertical"
          paddingTop="SP1"
          paddingBottom="SP1"
          marginBottom="SP4"
          align="center"
        >
          <Heading size="small" textAlign="center">
            {title}
          </Heading>
        </Box>
      )}

      <Box flex={1} marginBottom="SP4">
        {children}
      </Box>

      <Box direction="vertical" gap="SP4">
        {primaryButtonText && (
          <Button
            dataHook="baseModalLayout-primary-button"
            fullWidth
            priority="primary"
            onClick={primaryButtonOnClick}
            {...(primaryButtonProps as ButtonProps)}
          >
            {primaryButtonText}
          </Button>
        )}

        {secondaryButtonText && (
          <Button
            dataHook="baseModalLayout-secondary-button"
            fullWidth
            onClick={secondaryButtonOnClick}
            priority="secondary"
            {...(secondaryButtonProps as ButtonProps)}
          >
            {secondaryButtonText}
          </Button>
        )}
      </Box>
    </Box>
  );
}
