import React from "react";

import ActionButton, { ActionButtonProps } from "../../../components/ActionButton";
import { useI18n } from "../../../contexts/I18nContext";

export interface EndSubscriptionButtonProps extends Pick<ActionButtonProps, "refresh"> {
  subscriptionId: number;
}

const EndSubscriptionButton: React.FC<EndSubscriptionButtonProps> = ({
  subscriptionId,
  refresh,
}) => {
  const { t } = useI18n();

  return (
    <ActionButton
      errorMessage={t("Failed to end subscription.")}
      operation="subscription.subscription:end"
      refresh={refresh}
      request={{ params: { subscription_id: subscriptionId } }}
      successMessage={t("Subscription ended successfully.")}
    >
      {t("End subscription")}
    </ActionButton>
  );
};

export default EndSubscriptionButton;
