import type { ServiceButtonProps } from '../../lib/ServiceButton';

import { ServiceTypes } from '~/lib/types';
import AppleMusicPresaveButton from './AppleMusicPresaveButton';
import DeezerPresaveButton from './DeezerPresaveButton';
import SpotifyPresaveButton from './SpotifyPresaveButton';

export const PRESAVE_BUTTONS = {
  [ServiceTypes.SPOTIFY]: SpotifyPresaveButton,
  [ServiceTypes.ITUNES]: AppleMusicPresaveButton,
  [ServiceTypes.DEEZER]: DeezerPresaveButton,
};

export interface PresaveButtonProps
  extends Pick<ServiceButtonProps, 'height' | 'margin'> {
  type: keyof typeof PRESAVE_BUTTONS;
  albumId: number;
  withColoredIcon: boolean;
  text?: string;
}

const PresaveButton = ({ type, ...restProps }: PresaveButtonProps) => {
  const ButtonResolved = PRESAVE_BUTTONS[type];
  if (!ButtonResolved) return null;

  return <ButtonResolved {...restProps} />;
};

export default PresaveButton;
