import { LinkFieldDefaults } from '@hubspot/cms-components/fields';
import { LinkFieldValue } from '../utils/linkField.js';
import { FieldVisibility } from '../utils/types.js';

export type BaseLinkProps = {
  className?: string;
  style?: React.CSSProperties;
  children?: React.ReactNode;
};

// added this so that TS doesn't get mad about duplicate properties
// since we want to enforce required props in some of these type definitions
export type LinkHTMLProps = Omit<
  React.AnchorHTMLAttributes<HTMLAnchorElement>,
  'href' | 'target' | 'rel' | 'className' | 'style' | 'children'
>;

type LinkWithField = BaseLinkProps &
  LinkHTMLProps & {
    linkField: LinkFieldValue;
    href?: never;
    target?: never;
    rel?: never;
  };

type LinkWithoutField = BaseLinkProps &
  LinkHTMLProps & {
    linkField?: never;
    href: string;
    target?: '_self' | '_blank' | '_parent' | '_top';
    rel?: string;
  };

export type LinkProps = LinkWithField | LinkWithoutField;

export type ContentFieldsProps<TLinkName extends string = 'link'> = {
  linkLabel?: string;
  linkName?: TLinkName;
  linkDefault?: typeof LinkFieldDefaults;
} & FieldVisibility<TLinkName>;
