@extends('frontend.layouts.user.index') @section('title', __('Create Gift Card')) @push('styles') @endpush @section('content') @php /* * Build serialisable payloads for the JS layer. Templates and wallets * are also rendered server-side below — these arrays exist so the * client-side preview/summary logic can resolve a selected template's * preset_key or a wallet's currency symbol without hitting the DOM * for every read. */ $templatesPayload = $templates->map(fn ($t) => [ 'id' => $t->id, 'name' => $t->name, 'category' => $t->category, 'preset_key' => $t->preset_key ?: 'premium', 'default_amount' => $t->default_amount !== null ? (float) $t->default_amount : null, ])->values(); /* * Per-wallet fee + limit payload. Each wallet carries the currency * role row already (eager-loaded in the controller) — we pull the * gift_card role first, falling back to the voucher role for * wallets that haven't been configured with a dedicated gift_card * role yet (matches the controller's own resolveRole() logic). * * The frontend uses these to render an *accurate* order summary * instead of the previous hardcoded 1.5% placeholder. Backend * still recalculates at submit (single source of truth) — the * payload is for live preview only. */ $walletsPayload = $wallets->map(function ($w) { $role = $w->currency?->roles?->firstWhere('role_name', \App\Constants\CurrencyRole::GIFT_CARD) ?? $w->currency?->roles?->firstWhere('role_name', \App\Constants\CurrencyRole::VOUCHER); return [ 'id' => $w->id, 'name' => $w->name, 'balance' => (float) $w->balance, 'currency' => $w->currency->code ?? 'USD', 'symbol' => $w->currency->symbol ?? '$', 'fee' => (float) ($role->fee ?? 0), 'fee_type' => $role->fee_type ?? 'percent', 'min_limit' => $role->min_limit !== null ? (float) $role->min_limit : null, 'max_limit' => $role->max_limit !== null ? (float) $role->max_limit : null, 'role_name' => $role->role_name ?? null, ]; })->values(); $defaultSender = auth()->user()?->name ?? ''; @endphp