import React from 'react';
import { BookingPackage, Pax } from '@qite/tide-client/build/types';
import { useOfferPrinter } from '../use-offer-printer';

interface PrintOfferButtonProps {
  bookingPackage?: BookingPackage;

  getPax: () => Pax[] | undefined;

  tagIds?: number[];

  printActionId?: number | null;

  onPrinted?: (pdfUrl: string) => void;

  labelIdle?: string;
  labelCreating?: string;
  labelPrinting?: string;
  disabled?: boolean;
  className?: string;
  loader?: React.ReactNode;
}

const PrintOfferButton: React.FC<PrintOfferButtonProps> = ({
  bookingPackage,
  getPax,
  tagIds,
  printActionId = null,
  onPrinted,
  labelIdle = 'Print offer',
  labelCreating = 'Generating offer…',
  labelPrinting = 'Generating PDF…',
  disabled = false,
  className
}) => {
  const { handlePrint, stage, loading } = useOfferPrinter({
    bookingPackage,
    getPax,
    tagIds,
    onPrinted,
    printActionId
  });

  const label = stage === 'creating' ? labelCreating : stage === 'printing' ? labelPrinting : labelIdle;

  return (
    <button type="button" onClick={handlePrint} disabled={disabled || loading} className={className}>
      {label}
    </button>
  );
};

export default PrintOfferButton;
