---
// src/components/ContributionButton.astro - CLEANED: Removed duplicate auth script
export interface Props {
  type: 'edit' | 'new' | 'write';
  toolName?: string;
  variant?: 'primary' | 'secondary' | 'small';
  text?: string;
  className?: string;
  style?: string;
}

const { 
  type, 
  toolName, 
  variant = 'secondary', 
  text, 
  className = '', 
  style = '' 
} = Astro.props;

let href: string;
let defaultText: string;
let icon: string;

switch (type) {
  case 'edit':
    href = `/contribute/tool?edit=${encodeURIComponent(toolName || '')}`;
    defaultText = 'Edit';
    icon = `<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
            <path d="M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>`;
    break;
  case 'new':
    href = '/contribute/tool';
    defaultText = 'Add Tool';
    icon = `<line x1="12" y1="5" x2="12" y2="19"/>
            <line x1="5" y1="12" x2="19" y2="12"/>`;
    break;
  case 'write':
    href = '/contribute/knowledgebase';
    defaultText = 'Write Article';
    icon = `<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
            <polyline points="14 2 14 8 20 8"/>
            <line x1="16" y1="13" x2="8" y2="13"/>
            <line x1="16" y1="17" x2="8" y2="17"/>
            <polyline points="10 9 9 9 8 9"/>`;
    break;
  default:
    href = '/contribute';
    defaultText = 'Contribute';
    icon = `<line x1="12" y1="5" x2="12" y2="19"/>
            <line x1="5" y1="12" x2="19" y2="12"/>`;
}

const displayText = text || defaultText;
const buttonClass = `btn btn-${variant} ${className}`.trim();
const iconSize = variant === 'small' ? '14' : '16';
---

<a 
  href={href} 
  class={buttonClass}
  style={style}
  data-contribute-button={type}
  data-tool-name={toolName}
  title={`${displayText}${toolName ? `: ${toolName}` : ''}`}
>
  <svg width={iconSize} height={iconSize} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right: 0.5rem;">
    <Fragment set:html={icon} />
  </svg>
  {displayText}
</a>