@extends('admin.layouts.app') @section('title', 'WhatsApp Alerts & Message Templates - Dham Seva') @section('content')
{{-- Page Header --}}
💬

WhatsApp Automation & Message Templates

100% editable notification templates for 80G donations, volunteer seva passes, festival reminders & stays.

@if($settings->is_enabled) Live Automation Active @else Simulation / Mock Mode @endif
{{-- Alert Messages --}} @if(session('success'))
✓ {{ session('success') }}
@endif @if(session('error'))
⚠️ {{ session('error') }}
@endif {{-- KPI Stat Cards --}}
Active Templates
{{ $stats['active_templates'] }} / {{ $templates->count() }}
100% Customizable
Live Sent Alerts
{{ $stats['total_sent'] }}
Delivered to WhatsApp
Mock / Simulated
{{ $stats['total_mock'] }}
Development & Test Runs
Failed / Errors
{{ $stats['total_failed'] }}
Invalid Numbers or API Error
{{-- Main Navigation Tabs --}} @php $activeTab = request()->get('tab', 'templates'); @endphp
{{-- TAB 1: MESSAGE TEMPLATES (100% Admin Editable) --}} @if($activeTab === 'templates')
💡

Zero Hardcoding Policy:

The messages configured below are dispatched directly to devotees and volunteers. Click any Dynamic Variable Chip to automatically insert personalized details (such as Devotee Name, Amount, Receipt Number, Event Date, etc.). The live smartphone preview on the right updates instantly.

{{-- Templates List --}}
@foreach($templates as $template)
{{-- Template Header --}}
{{ strtoupper($template->category) }}

{{ $template->name }}

Key: {{ $template->key }}
@csrf
@csrf @method('PUT')
{{-- Left: Text Editor & Variables --}}
{{-- Click-to-insert Variable Chips --}}
Inserts variable at cursor position
@if(!empty($template->available_variables)) @foreach($template->available_variables as $vKeyIndex => $variable) @php $vKey = is_array($variable) ? ($variable['key'] ?? '') : $vKeyIndex; $vLabel = is_array($variable) ? ($variable['label'] ?? $vKey) : $variable; @endphp @endforeach @endif
{{-- Message Body Editor --}}
WhatsApp Formatting: *bold*, _italic_
{{-- Right: Live WhatsApp Phone Mockup Preview --}}
📱 Live WhatsApp Smartphone Preview
{{-- Smartphone Wrapper --}}
{{-- WhatsApp Header --}}
🛕
Dham Seva ✓
Official Business Account
{{-- WhatsApp Chat Area --}}
{{ $template->body }}
{{-- Chat Footer --}}
WhatsApp End-to-End Encrypted
{{-- Quick Test Button --}}
@endforeach
@endif {{-- TAB 2: WHATSAPP API SETTINGS --}} @if($activeTab === 'settings')
@csrf

WhatsApp API Credentials & Engine

Configure official Meta Cloud API or aggregator credentials.

{{-- Master Toggle --}}
Master WhatsApp Automation Switch
Enable automated instant WhatsApp notifications for donations, seva passes, and reminders.
Generated under System User in Meta Business Manager.
{{-- Right: Information Box --}}
✨ Meta Free Tier Allowance:
  • Meta provides 1,000 service conversations completely free each month.
  • 80G donation receipts and seva passes fall under the "Utility" category.
  • Alerts are sent directly from the Trust's verified WhatsApp business number.
  • If credentials are empty or master toggle is off, the system runs safely in Mock Mode, recording logs without crashing.

Quick Verification:

You can test the alerts directly on your phone without making a real donation. Go to the 'Message Templates' tab and click "Send Test to Mobile".

@endif {{-- TAB 3: DISPATCH AUDIT LOGS --}} @if($activeTab === 'logs')

WhatsApp Delivery Audit Logs

Transparent record of every automated alert sent by the platform.

@forelse($logs as $log) @empty @endforelse
Recipient Phone Devotee Name Template Status Message Preview Date & Time
{{ $log->recipient_phone }} {{ $log->recipient_name ?: '-' }} {{ $log->template_key }} @if($log->status === 'sent') ✓ Sent @elseif($log->status === 'mock') ⚙️ Mock @else ✕ Failed @endif {{ Str::limit($log->message_body, 70) }} {{ $log->created_at->format('d M Y, h:i A') }}
No WhatsApp logs recorded yet.
@if($logs->hasPages())
{{ $logs->links() }}
@endif
@endif
{{-- Modal: Send Test Message --}} @endsection