'use client' import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import { RiArrowRightUpLine, } from '@remixicon/react' import PlanComp from '../plan' import { useAppContext } from '@/context/app-context' import { useProviderContext } from '@/context/provider-context' import { useBillingUrl } from '@/service/use-billing' const Billing: FC = () => { const { t } = useTranslation() const { isCurrentWorkspaceManager } = useAppContext() const { enableBilling } = useProviderContext() const { data: billingUrl, isFetching, refetch } = useBillingUrl(enableBilling && isCurrentWorkspaceManager) const handleOpenBilling = async () => { // Open synchronously to preserve user gesture for popup blockers if (billingUrl) { window.open(billingUrl, '_blank', 'noopener,noreferrer') return } const newWindow = window.open('', '_blank', 'noopener,noreferrer') try { const url = (await refetch()).data if (url && newWindow) { newWindow.location.href = url return } } catch (err) { console.error('Failed to fetch billing url', err) } // Close the placeholder window if we failed to fetch the URL newWindow?.close() } return (