'use client';

import { ReactNode } from 'react';
import { cn } from '@/lib/utils';
import { Button, ButtonProps } from '@/components/ui/button';
import { RefreshCw, Plus, Search, Download } from 'lucide-react';

interface PageActionsProps {
  children: ReactNode;
  className?: string;
}

export function PageActions({ children, className }: PageActionsProps) {
  return (
    <div className={cn('flex items-center gap-2', className)}>
      {children}
    </div>
  );
}

interface RefreshButtonProps extends Omit<ButtonProps, 'onClick'> {
  onClick: () => void;
  loading?: boolean;
}

export function RefreshButton({ onClick, loading, className, ...props }: RefreshButtonProps) {
  return (
    <Button
      variant="outline"
      size="icon"
      onClick={onClick}
      disabled={loading}
      className={className}
      {...props}
    >
      <RefreshCw className={`h-4 w-4 ${loading ? 'animate-spin' : ''}`} />
    </Button>
  );
}

interface CreateButtonProps extends Omit<ButtonProps, 'onClick'> {
  onClick: () => void;
  label?: string;
}

export function CreateButton({ onClick, label = '新建', className, ...props }: CreateButtonProps) {
  return (
    <Button
      onClick={onClick}
      className={cn('gap-2', className)}
      {...props}
    >
      <Plus className="h-4 w-4" />
      {label}
    </Button>
  );
}

interface SearchButtonProps extends Omit<ButtonProps, 'onClick'> {
  onClick: () => void;
  label?: string;
}

export function SearchButton({ onClick, label = '搜索', className, ...props }: SearchButtonProps) {
  return (
    <Button
      onClick={onClick}
      className={cn('gap-2', className)}
      {...props}
    >
      <Search className="h-4 w-4" />
      {label}
    </Button>
  );
}

interface ExportButtonProps extends Omit<ButtonProps, 'onClick'> {
  onClick: () => void;
  label?: string;
}

export function ExportButton({ onClick, label = '导出 CSV', className, ...props }: ExportButtonProps) {
  return (
    <Button
      variant="outline"
      onClick={onClick}
      className={cn('gap-2', className)}
      {...props}
    >
      <Download className="h-4 w-4" />
      {label}
    </Button>
  );
}

export default PageActions;
