import { colors, fonts, toInlineStyle } from './theme';

interface ButtonProps {
    text: string;
    url: string;
    variant?: 'primary' | 'secondary' | 'destructive';
}

export function Button({ text, url, variant = 'primary' }: ButtonProps): string {
    let backgroundColor = colors.primary;
    let textColor = '#ffffff';

    if (variant === 'secondary') {
        backgroundColor = colors.secondary;
        textColor = colors.foreground;
    } else if (variant === 'destructive') {
        backgroundColor = colors.destructive;
        textColor = '#ffffff';
    }

    const tableStyles = toInlineStyle({
        margin: '24px 0',
    });

    const tdStyles = toInlineStyle({
        backgroundColor,
        borderRadius: '6px',
        textAlign: 'center',
    });

    const anchorStyles = toInlineStyle({
        display: 'inline-block',
        padding: '12px 24px',
        color: textColor,
        textDecoration: 'none',
        fontFamily: fonts.main,
        fontSize: '16px',
        fontWeight: '600',
        lineHeight: '1.5',
        maxWidth: '100%',
    });

    // Table-based button for maximum email client compatibility (Outlook friendly)
    return `
    <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="${tableStyles}">
      <tr>
        <td align="center" style="${tdStyles}">
          <a href="${url}" target="_blank" style="${anchorStyles}">${text}</a>
        </td>
      </tr>
    </table>
  `;
}
