export interface InvoiceDownloadConfig {
	downloadUrl?: string;
	nonce?: string;
	debug?: boolean;
	i18n?: {
		errorDownloadFailed?: string;
		removeStoredInvoiceLabel?: string;
		confirmDeleteInvoice?: string;
		errorDeleteFailed?: string;
	};
}

declare global {
	interface Window {
		__PDFDRAFT_PDF_INVOICES_FOR_WOOCOMMERCE_INVOICE_DOWNLOAD__?: InvoiceDownloadConfig;
	}
}

export function getConfig(): InvoiceDownloadConfig {
	return window.__PDFDRAFT_PDF_INVOICES_FOR_WOOCOMMERCE_INVOICE_DOWNLOAD__ ?? {};
}

export function parseOrderId(value: string | undefined): number {
	if (value === undefined || value === '') return 0;
	const id = parseInt(value, 10);
	return Number.isInteger(id) && id > 0 ? id : 0;
}
