import { useBlockProps } from "@wordpress/block-editor";
import { InnerBlocks } from "@wordpress/block-editor";

export default function save({ attributes }) {
	const { documentUrl, documentType, documentFileSize } = attributes;
	const blockProps = useBlockProps.save({
		className: "document-card",
	});

	if (!documentUrl) {
		return (
			<div {...blockProps}>
				<InnerBlocks.Content />
			</div>
		);
	}

	return (
		<a
			{...blockProps}
			href={documentUrl}
			target="_blank"
			rel="noopener noreferrer"
			className={`${blockProps.className || ""} document-card--${documentType}`}
		>
			<div className="document-card__content">
				<InnerBlocks.Content />
				<div className="file_info">
					<div className="file_info__type">
						{documentType === "internal" ? "PDF" : "Document externe"}
					</div>
					{documentFileSize > 0 && (
						<div className="file_info__size">( {documentFileSize} KB )</div>
					)}
				</div>
			</div>
		</a>
	);
}
