diff --git a/apps/web/src/components/SmsHeaderWallet.vue b/apps/web/src/components/SmsHeaderWallet.vue index 3420214..15a4191 100644 --- a/apps/web/src/components/SmsHeaderWallet.vue +++ b/apps/web/src/components/SmsHeaderWallet.vue @@ -10,6 +10,7 @@ const summary = ref(null); const loading = ref(false); const chargeOpen = ref(false); const warnOpen = ref(false); +const copyHint = ref(''); const NEGATIVE_KEY = 'mento_sms_negative_warning_shown'; const visible = computed(() => Boolean(summary.value?.billingEnabled)); @@ -27,6 +28,42 @@ const toneClass = computed(() => { return 'ok'; }); +const chargeInfo = computed(() => summary.value?.chargeInfo ?? null); + +function normalizeCopyText(value: string) { + const persianDigits = '۰۱۲۳۴۵۶۷۸۹'; + const arabicDigits = '٠١٢٣٤٥٦٧٨٩'; + return value + .replace(/[\u06F0-\u06F9]/g, (digit) => String(persianDigits.indexOf(digit))) + .replace(/[\u0660-\u0669]/g, (digit) => String(arabicDigits.indexOf(digit))) + .replace(/\s+/g, ''); +} + +function formatCardDisplay(value: string) { + const digits = normalizeCopyText(value); + if (!digits) return '—'; + return digits.replace(/(\d{4})(?=\d)/g, '$1 ').trim(); +} + +async function copyValue(label: string, value: string) { + const text = normalizeCopyText(value); + if (!text) { + copyHint.value = `${label} ثبت نشده است`; + return; + } + try { + await navigator.clipboard.writeText(text); + copyHint.value = `${label} کپی شد`; + } catch { + copyHint.value = 'کپی انجام نشد'; + } +} + +function closeCharge() { + chargeOpen.value = false; + copyHint.value = ''; +} + async function load() { if (!auth.isAuthenticated || !auth.user?.organizationId) { summary.value = null; @@ -79,39 +116,58 @@ defineExpose({ refresh: load });