// ไม่มี "use client" — เรียกจาก server (ตรวจลิงก์ก่อนบันทึก) ได้ export const fill = (template: string, values: Record) => template.replace(/\{(\w+)\}/g, (match, key: string) => key in values ? String(values[key]) : match, ); const LINK_PROTOCOLS = new Set(["http:", "https:", "mailto:", "tel:"]); /** * ลิงก์ที่ใส่ในเอกสารได้: http(s) / mailto / tel — ไม่รับ `javascript:` / `data:` (เอกสารถูกส่งเป็นอีเมล/แสดงที่อื่นต่อ) * ไม่มี scheme (`example.com`) = เติม `https://` ให้ · คืน null เมื่อใช้ไม่ได้ */ export function normalizeLinkUrl(raw: string): string | null { const value = raw.trim(); if (!value) return null; const withScheme = /^[a-z][a-z\d+.-]*:/i.test(value) ? value : `https://${value}`; try { return LINK_PROTOCOLS.has(new URL(withScheme).protocol) ? withScheme : null; } catch { return null; } }