---
import { ORIGIN } from "astro:env/server";
import qrcode from "qrcode-generator";

const { msg, width, height } = Astro.props;

const qr = qrcode(0, "M");

let data = msg;

if (msg.startsWith("/")) {
	data = (ORIGIN ?? Astro.url.host) + msg;
}

qr.addData(data);
qr.make();
let img = qr.createImgTag();

if (width !== undefined) {
	img = img.replace(/width="[0-9]+"/, `width="${width}"`);
}

img = img.replace(">", ' style="image-rendering: pixelated;">');
---

<Fragment set:html={img} />
