import { farcasterIcon } from './icons.js'
export type QRCodeProps = {
url: string
}
export async function QRCode(props: QRCodeProps) {
const { url } = props
// 1. Create QR code
const { create } = await import('qrcode')
const arr = Array.prototype.slice.call(
create(url, { errorCorrectionLevel: 'H' }).modules.data,
0,
)
const sqrt = Math.sqrt(arr.length)
const matrix = arr.reduce(
(rows, key, index) =>
(index % sqrt === 0
? rows.push([key])
: rows[rows.length - 1].push(key)) && rows,
[],
)
// 2. Add corners
const logoMargin = 10
const logoSize = 60
const size = 250
const dots = []
const cellSize = size / matrix.length
const qrList = [
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: 0, y: 1 },
] as const
for (const item of qrList) {
const x1 = (matrix.length - 7) * cellSize * item.x
const y1 = (matrix.length - 7) * cellSize * item.y
for (let i = 0; i < 3; i++) {
const className = i % 2 !== 0 ? 'light' : 'dark'
const height = cellSize * (7 - i * 2)
const rx = (i - 2) * -5 + (i === 0 ? 2 : 0)
const ry = (i - 2) * -5 + (i === 0 ? 2 : 0)
const width = cellSize * (7 - i * 2)
const x = x1 + cellSize * i
const y = y1 + cellSize * i
const props = { class: className, height, rx, ry, width, x, y }
const dot =