{{-- ── 1. AUTOMATION MODE SELECTOR ─────────────────────────────────── --}}

{{ __('Automation mode') }}

{{ __('Choose how background tasks run. You can change this at any time.') }}

@php $modes = [ 'middleware' => [ 'icon' => '🌐', 'label' => __('Shared hosting'), 'badge' => __('No cron needed'), 'badgeCls'=> 'rf-badge-active', 'desc' => __('Tasks run automatically on every web request. Perfect for shared hosting (cPanel, Plesk). No server access required.'), 'warn' => __('On low-traffic sites, tasks may be delayed if nobody visits the panel. Recommended for getting started.'), ], 'scheduler' => [ 'icon' => '⏰', 'label' => __('Cron scheduler'), 'badge' => __('Recommended'), 'badgeCls'=> 'rf-badge-warning', 'desc' => __('You add ONE cron entry to your hosting control panel (cPanel Cron Jobs). Laravel handles the rest reliably.'), 'warn' => null, ], 'queue' => [ 'icon' => '⚡', 'label' => __('Queue worker'), 'badge' => __('VPS / Dedicated'), 'badgeCls'=> 'rf-badge', 'desc' => __('A persistent worker process handles tasks asynchronously. Highest performance but requires VPS/dedicated access.'), 'warn' => null, ], ]; @endphp @foreach($modes as $modeKey => $m) @php $active = $automationMode === $modeKey; @endphp @endforeach
{{-- ── 2. SETUP GUIDE (dynamic by mode) ────────────────────────────── --}}

{{ __('Setup guide') }}

{{-- Callout: 1 command = the whole cron suite other panel scripts require --}}
💡
{{ __('One command does the work of six separate crons') }} — {{ __('send orders, poll status, drip-feed, refill status and catalogue sync all run from a single artisan command. Resellers do NOT need their own cron jobs — the system processes all panels automatically.') }}
{{-- MIDDLEWARE: nothing to configure --}} @if($mode === 'middleware')
✅

{{ __('No configuration needed') }}

{{ __('Your panel is using automatic middleware mode. Background tasks run on every web request — no cron job or worker process required. Just use your panel normally.') }}

{{ __('If you want more reliable task scheduling (especially on low-traffic sites), switch to "Cron scheduler" above and follow the cPanel setup guide.') }}

@endif {{-- SCHEDULER: show cPanel guide + individual commands --}} @if($mode === 'scheduler')

{{ __('Add these cron entries to your hosting control panel (cPanel → Advanced → Cron Jobs). The first command runs every minute and handles all order processing. The second runs hourly for billing.') }}

{{-- Equivalence table for operators migrating from other SMM panel scripts --}}
{{ __('Typical panel cron') }} {{ __('Built-in equivalent') }} {{ __('Frequency') }}
cron/orderDispatchOrderJob{{ __('Every minute') }}
cron/statusPollOrderStatusJob{{ __('Every minute') }}
cron/sync_servicesSyncCatalogJob{{ __('Configurable (default 1 h)') }}
cron/dripfeedDripFeedTickJob{{ __('Every minute') }}
cron/refill_statusPollRefillJob{{ __('Every minute') }}
cron/status_subscriptions{{ __('SMM Subscriptions') }}{{ __('v1.1 (coming soon)') }}
{{-- Individual cron commands --}}
@foreach($cronEntries as $entry)
{{ $entry['schedule'] }} {{ $entry['label'] }} — {{ $entry['description'] }}
{{ $entry['command'] }}
@endforeach
{{-- cPanel step-by-step --}}
  1. {{ __('Log in to your cPanel account.') }}
  2. {{ __('Go to') }} {{ __('Advanced') }} → {{ __('Cron Jobs') }}.
  3. {{ __('Under "Add New Cron Job", select the frequency using the dropdowns (or type the schedule manually).') }}
  4. {{ __('Paste the command from the box above (without the schedule prefix) into the "Command" field.') }}
  5. {{ __('Click "Add New Cron Job". Repeat for each command above.') }}
  6. {{ __('Done! Your panel will process orders, sync the catalogue and charge subscriptions automatically.') }}
{{ __('Note:') }} {{ __('The path shown above (:path) is your installation directory — it was auto-detected from your server. If the cron does not run, confirm the path matches where you uploaded the panel files.', ['path' => $artisanPath]) }}
{{-- PHP path alternatives --}}

{{ __('The commands above use `php` which works on most hosts. If your cron does not execute, replace `php` with the full path to PHP 8.2+ on your server:') }}

@foreach($phpAlternatives as $alt)
{{ $alt }}
@endforeach

{{ __('Ask your hosting support "What is the full path to PHP 8.2 CLI on this server?" if none of the above work.') }}

@endif {{-- QUEUE: worker command + cron entries --}} @if($mode === 'queue')

{{ __('Run a persistent worker process on your VPS or dedicated server. Background jobs are queued and processed asynchronously for best performance.') }}

{{-- Step 1: queue worker --}}

{{ __('Step 1 — Start the queue worker (keep it running with Supervisor or systemd):') }}

{{ $workerCmd }}
{{-- Step 2: scheduled crons --}}

{{ __('Step 2 — Add these cron entries (they enqueue work for the worker above):') }}

@foreach($cronEntries as $entry)
{{ $entry['schedule'] }} {{ $entry['label'] }}
{{ $entry['command'] }}
@endforeach
{{-- Supervisor config --}}

{{ __('Create') }} /etc/supervisor/conf.d/redfamosa-worker.conf:

[program:redfamosa-worker]
command={{ $workerCmd }}
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/redfamosa-worker.log

{{ __('Then run:') }} sudo supervisorctl reread && sudo supervisorctl update && sudo supervisorctl start redfamosa-worker:*

@endif
{{-- ── 3. HOW ORDERS FLOW ───────────────────────────────────────────── --}}

{{ __('How orders are pushed to providers') }}

@php $steps = [ ['color'=>'#6366f1', 'title'=>__('Client places order'), 'desc'=>__('Order created with status Awaiting. Charge debited from wallet immediately and atomically.')], ['color'=>'#f59e0b', 'title'=>__('DispatchOrderJob fires'), 'desc'=>__('Picks up Awaiting orders (25 per provider). Calls provider API (action=add, url, quantity). Serialized per provider — no concurrent calls to the same upstream.')], ['color'=>'#10b981', 'title'=>__('Provider returns order ID'), 'desc'=>__('Status → Pending. provider_order_id saved. next_poll_at set to ~60 s. If the API rejects → status Error. Orders are NEVER faked as Completed.')], ['color'=>'#3b82f6', 'title'=>__('PollOrderStatusJob fires'), 'desc'=>__('Sends multiStatus (up to 100 IDs) in one API call. Applies real status: Completed, Partial (proportional refund), Canceled (full refund). next_poll_at staggered 60–300 s to avoid rate limits.')], ['color'=>'#ec4899', 'title'=>__('Refunds on Partial / Canceled'),'desc'=>__('refund = charge × (undelivered ÷ quantity). Dual-wallet (reseller) orders unwind both sides atomically. Ledger is immutable — entries are appended, never edited.')], ['color'=>'#8b5cf6', 'title'=>__('Drip-feed (optional)'), 'desc'=>__('DripFeedTickJob emits sub-orders at the configured interval until the full quantity is done. Each sub-order goes through the same Dispatch → Poll cycle.')], ]; @endphp
@foreach($steps as $i => $s)
{{ $i+1 }}
@if(!$loop->last)
@endif

{{ $s['title'] }}

{{ $s['desc'] }}

@endforeach
{{-- ── 4. LAST CATALOGUE SYNC ───────────────────────────────────────── --}} @if ($lastCatalogueSync)

{{ __('Last catalogue sync') }}

{{ $lastCatalogueSync->status }} {{ $lastCatalogueSync->created_at?->diffForHumans() }}
{{ number_format($lastCatalogueSync->new_count) }} {{ __('imported') }} {{ number_format($lastCatalogueSync->updated_count) }} {{ __('updated') }} {{ number_format($lastCatalogueSync->disabled_count) }} {{ __('disabled') }}
@endif {{-- ── 5. TASKS TABLE ───────────────────────────────────────────────── --}}
@foreach ($tasks as $t) @endforeach
{{ __('Task') }} {{ __('Job class') }} {{ __('Frequency') }} {{ __('Last run') }} {{ __('Action') }}

{{ $t['label'] }}

@if(!empty($t['coming_soon'])) {{ __('Coming v1.1') }} @endif
@if(!empty($t['description']))

{{ $t['description'] }}

@endif
{{ $t['job'] }} {{ $t['cadence'] }} @if ($t['last']) {{ \Illuminate\Support\Carbon::createFromTimestamp($t['last'])->diffForHumans() }} @else — @endif @if(empty($t['coming_soon'])) @else — @endif
{{-- ── 6. CONFIGURABLE INTERVALS ────────────────────────────────────── --}}

{{ __('Periodic task intervals') }}

{{ __('How often each heavy task runs (in seconds). Minimum 60 s, maximum 86400 s (24 h). Changes take effect on the next tick.') }}

{{ __('Default 3600 = every 1 hour') }}

{{ __('Default 3600 = every 1 hour') }}

{{ __('Default 3600 = every 1 hour') }}

{{-- Copy helper script --}}