import React from 'react';
import type { DialogTriggerProps } from './types';

export function DialogTrigger({
  children,
  asChild,
  onClick,
}: DialogTriggerProps) {
  if (asChild && React.isValidElement(children)) {
    return React.cloneElement(children, {
      onClick: onClick || (children.props as { onClick?: () => void }).onClick,
    } as Record<string, unknown>);
  }
  return (
    <button
      type="button"
      onClick={onClick}
      className="inline-flex appearance-none bg-transparent border-0 p-0 cursor-pointer text-inherit font-inherit"
    >
      {children}
    </button>
  );
}
