{{-- Skapa SMS-utskick form (DESIGN.md Page patterns 3: numbered step cards, summary panel, mobile bar; #2957 slice 5b, card #3019). Posts the same fields as the old form to sms-sendout.store: name, start_time, message, parts, receiverList[] and _token. "nh_when" and the date/time inputs are UI only: resources/assets/js/nuhet/sms-form.js writes start_time as "Y-m-d H:i:s" (the old datetimepicker format) and parts from the SMS splitter (/js/split-sms.min.js, the same counting as before). Param: $company. --}} @php // Lists are shown with their receiver count and how many of them have a mobile number; lists // where nobody has one cannot be ticked, as before. $lists = $company->receiverLists() ->withCount(['receivers', 'receivers as phone_count' => fn ($query) => $query->hasPhone()]) ->orderBy('name')->get(); $checkedIds = array_map('intval', (array) old('receiverList', [])); $checked = $lists->filter(fn ($list) => $list->phone_count > 0 && in_array((int) $list->id, $checkedIds, true)); $checkedCount = $checked->sum('phone_count'); $nowValue = now()->format('Y-m-d H:i:s'); $oldStart = old('start_time'); $oldStartTime = is_string($oldStart) ? \DateTime::createFromFormat('Y-m-d H:i:s', $oldStart) : false; $scheduled = $oldStartTime && $oldStartTime > new \DateTime(); $later = $scheduled ? \Illuminate\Support\Carbon::instance($oldStartTime) : now()->addHour()->startOfHour(); $expire = $company->expire_date ? \Illuminate\Support\Carbon::parse($company->expire_date) : null; $paid = optional($company->package)->monthly_cost > 0; $i18n = [ 'notChosen' => __('sendout.create.notChosen'), 'receiversValue' => __('sendout.create.receiversValue'), 'receiversValueOne' => __('sendout.create.receiversValueOne'), 'receiversShort' => __('sendout.create.receiversShort'), 'asap' => __('sendout.create.asap'), 'priceValue' => __('sms.nhForm.priceValue'), 'confirmText' => __('sms.nhForm.confirmText'), 'confirmExpire' => __('sms.nhForm.confirmExpire'), ]; $invalid = fn ($key) => $errors->has($key) ? 'true' : null; $describedBy = fn ($key) => $errors->has($key) ? $key.'-error' : null; @endphp
@csrf
@include('sendout.partials.nh-noscript')

{{ __('sendout.create.receiversStep') }}

@if ($lists->isEmpty())

{{ __('sendout.create.noLists') }}

{{ __('sendout.create.createList') }}
@else

{{ __('sms.nhForm.receiversHint') }}

@if ($lists->contains(fn ($list) => $list->phone_count == 0)) @endif
@foreach ($lists as $list) @php $countText = $list->receivers_count == 0 ? __('sms.nhForm.listEmpty') : ($list->phone_count > 0 ? __('sms.nhForm.listCount', ['active' => formatNumber($list->phone_count), 'total' => formatNumber($list->receivers_count)]) : __('sms.nhForm.listNobody')); @endphp
@endforeach
@error('receiverList')

{{ $message }}

@enderror
{{ formatNumber($checkedCount) }}{{ __('sms.nhForm.totalLabel') }}
@endif

{{ __('sms.nhForm.messageStep') }}

@include('sms.partials.nh-counter')

{{ __('sms.nhForm.whenStep') }}

has('start_time')) aria-invalid="true" aria-describedby="start_time-error" @endif>
has('start_time')) aria-invalid="true" aria-describedby="start_time-error" @endif>
@error('start_time')

{{ $message }}

@enderror @if ($expire && ! $paid) @endif
{{ __('sendout.create.receiversShort', ['count' => formatNumber($checkedCount)]) }} {{ __('sendout.form.save') }}
{{-- Replaces the old SweetAlert confirmation; sms-form.js fills the texts and submits on [data-nh-confirm]. --}}

{{ __('sms.nhForm.confirmTitle') }}

{{ __('sendout.create.confirmCancel') }} {{ __('sendout.form.save') }}