{{ __('SMS Gateway & Templates Setup') }} {{-- Top Section: Balance & Profile Dashboard --}}
{{-- Gateway Balance Card --}}
{{-- Decorative background glow --}}
{{ __('SMS Balance') }} @if(empty($balance) || !is_array($balance) || ($balance['status'] ?? '') === 'error' || empty($balance['data']))

{{ __('Connection Error') }}

{{ __('Endpoint unreachable') }}
@else

{{ is_numeric($balance['data']['remaining_balance'] ?? null) ? number_format((float) $balance['data']['remaining_balance']) : ($balance['data']['remaining_balance'] ?? 'N/A') }}

{{ __('credits') }}
@if(isset($balance['data']['expired_on'])) {{ __('Expiry:') }} {{ \Carbon\Carbon::parse($balance['data']['expired_on'])->format('d M, Y') }} @endif @endif
{{ __('Active') }}
{{-- Gateway Profile Card --}}
{{-- Decorative background glow --}}
{{ strtoupper(substr(is_array($profile) && isset($profile['data']['first_name']) ? $profile['data']['first_name'] : 'N', 0, 1)) }}
{{ __('Gateway Profile') }} @if(empty($profile) || !is_array($profile) || ($profile['status'] ?? '') === 'error' || empty($profile['data']))

{{ __('Profile Error') }}

@else

{{ ($profile['data']['first_name'] ?? '') . ' ' . ($profile['data']['last_name'] ?? '') }}

{{ $profile['data']['email'] ?? 'N/A' }} @endif
{{ __('Verified') }}
{{-- Templates & Bulk SMS Section --}}
@if($activeTab === 'templates') {{-- Search templates --}}
@endif
@if($activeTab === 'templates') {{-- Templates Section --}}
@php $templateMeta = [ 'all_customers' => ['icon' => 'bi-megaphone', 'color' => '#06b6d4', 'bg' => '#ecfeff', 'text' => '#0891b2', 'desc' => 'Sent to all active customers'], 'area_wise_customer_due_list' => ['icon' => 'bi-card-list', 'color' => '#f59e0b', 'bg' => '#fef3c7', 'text' => '#d97706', 'desc' => 'Due list by area coverage'], 'area_wise_customer_list' => ['icon' => 'bi-geo-alt', 'color' => '#14b8a6', 'bg' => '#ccfbf1', 'text' => '#0d9488', 'desc' => 'General message to area list'], 'auto_temporary_disable_alert' => ['icon' => 'bi-x-circle', 'color' => '#ef4444', 'bg' => '#fee2e2', 'text' => '#dc2626', 'desc' => 'Alert for automated disable'], 'bill_generate' => ['icon' => 'bi-receipt', 'color' => '#10b981', 'bg' => '#d1fae5', 'text' => '#059669', 'desc' => 'Sent during bill generation'], 'payment_collection' => ['icon' => 'bi-cash-coin', 'color' => '#10b981', 'bg' => '#d1fae5', 'text' => '#059669', 'desc' => 'Payment confirmation alert'], 'collection_(MFS)_to_owner' => ['icon' => 'bi-shield-check', 'color' => '#6366f1', 'bg' => '#e0e7ff', 'text' => '#4f46e5', 'desc' => 'MFS payment summary to admin'], 'collection_delete' => ['icon' => 'bi-trash', 'color' => '#ef4444', 'bg' => '#fee2e2', 'text' => '#dc2626', 'desc' => 'Payment cancellation alert'], 'collection_edit' => ['icon' => 'bi-pencil-square', 'color' => '#f59e0b', 'bg' => '#fef3c7', 'text' => '#d97706', 'desc' => 'Payment update notification'], 'collection_to_owner' => ['icon' => 'bi-person-check', 'color' => '#6366f1', 'bg' => '#e0e7ff', 'text' => '#4f46e5', 'desc' => 'Collection summary to admin'], 'complain_employee' => ['icon' => 'bi-briefcase', 'color' => '#8b5cf6', 'bg' => '#f3e8ff', 'text' => '#7c3aed', 'desc' => 'Complain assignment alert'], 'complain_list' => ['icon' => 'bi-chat-dots', 'color' => '#8b5cf6', 'bg' => '#f3e8ff', 'text' => '#7c3aed', 'desc' => 'Resolved complaint alert'], 'complain_to_customer' => ['icon' => 'bi-headset', 'color' => '#8b5cf6', 'bg' => '#f3e8ff', 'text' => '#7c3aed', 'desc' => 'Complain registration receipt'], 'create_customer' => ['icon' => 'bi-person-plus', 'color' => '#3b82f6', 'bg' => '#dbeafe', 'text' => '#2563eb', 'desc' => 'New customer account welcome'], 'create_customer_to_owner' => ['icon' => 'bi-info-circle', 'color' => '#3b82f6', 'bg' => '#dbeafe', 'text' => '#2563eb', 'desc' => 'New customer notice to admin'], 'free_customer_list' => ['icon' => 'bi-gift', 'color' => '#ec4899', 'bg' => '#fce7f3', 'text' => '#db2777', 'desc' => 'Complimentary service details'], 'inactive_customer_list' => ['icon' => 'bi-moon-stars', 'color' => '#6b7280', 'bg' => '#f3f4f6', 'text' => '#4b5563', 'desc' => 'Alert for inactive accounts'], 'failed_to_disable_at_mikrotik' => ['icon' => 'bi-exclamation-octagon', 'color' => '#ef4444', 'bg' => '#fee2e2', 'text' => '#dc2626', 'desc' => 'Failed disable mikrotik notice'], 'temporary_disable_customer_list' => ['icon' => 'bi-pause-circle', 'color' => '#f59e0b', 'bg' => '#fef3c7', 'text' => '#d97706', 'desc' => 'Temporary disable notice'], 'reminder' => ['icon' => 'bi-alarm', 'color' => '#f59e0b', 'bg' => '#fef3c7', 'text' => '#d97706', 'desc' => 'Upcoming bill payment warning'] ]; @endphp
@forelse($smsTemps as $smsTemp) @php $meta = $templateMeta[$smsTemp->template_name] ?? ['icon' => 'bi-chat-left-dots', 'color' => '#6b7280', 'bg' => '#f3f4f6', 'text' => '#4b5563', 'desc' => 'Custom notification alert']; @endphp
{{-- Card Header Info --}}
{{ str_replace('_', ' ', $smsTemp->template_name) }}
{{ __($meta['desc']) }}
{{-- Status Switch --}}
@can('sms-setup') is_active ? 'checked' : '' }} style="width: 2.1em; height: 1.05em;" > @else is_active ? 'checked' : '' }} disabled style="width: 2.1em; height: 1.05em;" > @endcan
{{-- Template Body Preview with Highlighted Placeholders --}}
{!! preg_replace('/(\{[A-Z0-9_()]+\})/', '$1', e(Str::limit($smsTemp->template, 140))) !!}
{{-- Card Footer Details & Action Button --}}
{{ $smsTemp->is_active ? __('Active') : __('Inactive') }}
{{-- Modal for Editing SMS Template --}}
@empty
{{ __('No SMS templates found matching your search.') }}
@endforelse
@else {{-- Bulk SMS View --}}
{{-- Left Column: Form Configuration --}}
{{ __('Compose Bulk Message') }}

{{ __('Select target recipients, load a template or write custom text, and trigger campaign.') }}

{{-- Recipient Group Selector --}}
{{-- Target Date (Only for due_date filter) --}} @if($recipientGroup === 'due_date')
@endif {{-- Specific Customers Selection (Only for specific filter) --}} @if($recipientGroup === 'specific')
{{-- Search results dropdown --}} @if(!empty($bulkSearchList))
@foreach($bulkSearchList as $item)
{{ $item['customer_name'] }} ({{ $item['customer_unique_id'] }})
{{ $item['mobile'] }} | PPP: {{ $item['pppUser']['username'] ?? 'N/A' }}
@endforeach
@endif {{-- Removed selectedCustomers badge list --}}
@endif {{-- Template Loader Dropdown --}}
{{-- Message Composition Area --}}
{{-- Placeholder Pills --}}
{{ __('Insert Dynamic Placeholders:') }}
@foreach([ '{CUSTOMER_NAME}' => 'Name', '{CUSTOMER_ID}' => 'ID', '{PPPOE_USERNAME}' => 'PPPoE User', '{DUE_AMOUNT}' => 'Due Amount', '{BILL_AMOUNT}' => 'Bill Amount', '{AUTO_TEMPORARY_DAY}' => 'Due Date', '{COMPANY_NAME}' => 'Company Name', '{COMPANY_MOBILE}' => 'Company Phone' ] as $placeholder => $label) @endforeach
@error('bulkMessage') {{ $message }} @enderror
{{ __('Placeholders will render dynamically.') }}
{{ __('Characters:') }} 0 | {{ __('Parts:') }} 0
{{-- Right Column: Preview & Submit Summary --}}
{{-- Summary Card --}}
{{-- Decorative radial glow --}}
{{ __('Campaign Summary') }}
{{ __('Status: Ready') }}

{{ number_format($recipientsCount) }}

{{ __('Recipients') }}

0

{{ __('SMS Parts') }}

0

{{ __('Est. Credits') }}
{{-- Recipient Preview / Selection Table Card --}}
@if($recipientGroup === 'specific')
{{ __('Selected Recipients (Total: :count)', ['count' => number_format($recipientsCount)]) }}
@else
{{ __('Recipient Preview (First 8)') }}
{{-- Live filter search for preview --}}
@endif
@forelse($recipientsPreview as $recipient) @empty @endforelse
{{ __('ID / Name') }} {{ __('Mobile') }} {{ __('Dues') }} {{ __('Action') }}
{{ $recipient->customer_unique_id }}
{{ Str::limit($recipient->customer_name, 15) }}
@if($recipient->pppUser) {{ $recipient->pppUser->username }} @endif
{{ $recipient->mobile }} {{ number_format($recipient->billing->due_amount ?? 0, 2) }} @if($recipientGroup === 'specific') {{-- Trash can to remove from specific selection --}} @else {{-- X mark to exclude from general group --}} @endif
@if($recipientGroup === 'specific') {{ __('No recipients selected yet. Search and add above.') }} @else {{ __('No recipients match search or filters.') }} @endif
{{-- Display Excluded Recipients (Only for non-specific groups) --}} @if($recipientGroup !== 'specific' && !empty($excludedCustomers) && count($excludedCustomers) > 0)
@foreach($excludedCustomers as $cust) {{ Str::limit($cust->customer_name, 12) }} ({{ $cust->customer_unique_id }}) @endforeach
@endif
{{-- Send Button Card --}}
@endif