/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
import React from 'react';
import {theme} from 'components/shared/theme';
import {Button} from 'components/buttons';

const {colors} = theme;

interface IExportFileButton {
  label?: string;
  file: string;
  fileName?: string;
}

export const ExportFileButton = ({label = 'Export File', file, fileName = 'file'}: IExportFileButton): React.JSX.Element => {
  const handleExport = () => {
    const downloadUrl = URL.createObjectURL(new Blob([file]));
    const linkTag = document.createElement('a');

    linkTag.href = downloadUrl;
    linkTag.setAttribute('target', '_blank');
    linkTag.setAttribute('download', fileName);
    linkTag.click();
  };

  return (
    <Button onClick={handleExport} className="testId-exportFile" backgroundColor={colors.red} borderColor={colors.red}>
      {label}
    </Button>
  );
};
