@use('App\Campaigns\Manager\ManagerFormat')
@use('App\Models\CampaignEntityEdit')
@use('App\Campaigns\Manager\Editing\EditCapabilities')
@php
    $steps = ['edit' => 'Change', 'review' => 'Review', 'result' => 'Result'];
    $position = array_search($step, array_keys($steps), true);
    $platform = ManagerFormat::platform($campaign->platform);
    $typeName = strtolower(ManagerFormat::type($entity->entity_type));
    $readAt = $campaign->latestSuccessfulSyncRun?->started_at;
    $show = fn (string $field, mixed $value): string => EditCapabilities::display($entity, $field, $value);
    $status = ManagerFormat::status($entity->status);
    $facts = ManagerFormat::highlights($entity);
@endphp
<div class="mb-page mb-cm">
    @push('styles')
        <link href="{{ asset('assets/mb/css/campaigns.css') }}?v={{ filemtime(public_path('assets/mb/css/campaigns.css')) }}" rel="stylesheet">
        <link href="{{ asset('assets/mb/css/campaign-manager.css') }}?v={{ filemtime(public_path('assets/mb/css/campaign-manager.css')) }}" rel="stylesheet">
    @endpush

    <div class="mb-page-inner">
        <a href="{{ route('campaign-manager.show', $campaign) }}" class="mb-cm-back" wire:navigate><i class="bi bi-arrow-left"></i> {{ $campaign->name }}</a>

        <div class="mb-cm-hero">
            <div class="mb-cm-hero-main">
                <span class="mb-cm-mark is-lg is-{{ $campaign->platform }}" aria-hidden="true"><i class="bi {{ ManagerFormat::platformIcon($campaign->platform) }}"></i></span>
                <div class="min-w-0">
                    <div class="mb-eyebrow"><i class="bi bi-pencil-square"></i> Edit {{ $typeName }}</div>
                    <h1 class="mb-cm-hero-title">{{ $entity->name ?: '(no name)' }}</h1>
                    <div class="mb-cm-chips">
                        <span class="mb-tag mb-platform-tag is-{{ $campaign->platform }}"><i class="bi {{ ManagerFormat::platformIcon($campaign->platform) }}"></i> {{ $platform }}</span>
                        <span class="mb-tag" title="{{ $platform }} id"><i class="bi bi-hash"></i> <span class="mb-cm-mono">{{ $entity->external_id }}</span></span>
                        @if ($entity->status)
                            <span class="mb-status is-static is-{{ $status['class'] }}"><span class="mb-dot"></span>{{ $status['label'] }}</span>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <ol class="mb-steps list-unstyled" aria-label="Progress">
            @foreach ($steps as $key => $label)
                <li @class(['mb-step', 'is-active' => $key === $step, 'is-done' => $loop->index < $position]) @if ($key === $step) aria-current="step" @endif>
                    <div class="mb-step-bar"><i></i></div>
                    <div class="mb-step-label">{{ $loop->iteration }}. {{ $label }}</div>
                </li>
            @endforeach
        </ol>

        @if ($problem)
            <div class="mb-cm-alert is-err" role="alert"><i class="bi bi-exclamation-octagon"></i><div>{{ $problem }}</div></div>
        @endif

        <div class="mb-cm-edit-grid">
            <section class="mb-card">
                @if ($step === 'edit')
                    <div class="mb-perf-card-head">
                        <div class="mb-perf-card-title-wrap">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon"><i class="bi bi-sliders"></i></span>
                                <h2 class="mb-perf-card-title">What should change?</h2>
                            </div>
                            <div class="mb-cell-meta">
                                Starting from what {{ $platform }} reported {{ $readAt?->diffForHumans() }}. Nothing is sent until you confirm on the next step.
                            </div>
                        </div>
                    </div>
                    <div class="mb-cm-body">
                        @if ($refusal)
                            <div class="mb-cm-alert is-muted" role="status"><i class="bi bi-lock"></i><div>{{ $refusal }}</div></div>
                            <div class="mb-cm-actions">
                                <a href="{{ route('campaign-manager.show', $campaign) }}" class="mb-btn-ghost" wire:navigate>Back to campaign</a>
                            </div>
                        @else
                            <form wire:submit="review" novalidate>
                                @forelse ($fields as $field)
                                    @php
                                        $structured = $field !== 'conversion_rules' && \App\Campaigns\Manager\Editing\AdvancedEditFields::structured($field);
                                    @endphp
                                    <div class="mb-cm-field">
                                        @if ($structured)
                                            <details @if ($errors->has('values.'.$field)) open @endif>
                                                <summary class="form-label">{{ ManagerFormat::field($field) }} <span class="text-muted small">Advanced</span></summary>
                                                <label for="field-{{ $field }}" class="visually-hidden">{{ ManagerFormat::field($field) }}</label>
                                        @else
                                            <label for="field-{{ $field }}" class="form-label">{{ ManagerFormat::field($field) }}</label>
                                        @endif
                                        @if ($field === 'conversion_rules')
                                            @php
                                                $ruleOptions = $conversionRuleOptions + array_combine(
                                                    (array) EditCapabilities::current($entity, 'conversion_rules'),
                                                    (array) EditCapabilities::current($entity, 'conversion_rules'),
                                                );
                                            @endphp
                                            <select id="field-conversion_rules" multiple class="form-select @error('values.conversion_rules') is-invalid @enderror"
                                                    wire:model="values.conversion_rules" aria-describedby="help-conversion_rules">
                                                @foreach ($ruleOptions as $urn => $label)
                                                    <option value="{{ $urn }}">{{ $label }}</option>
                                                @endforeach
                                            </select>
                                            <button type="button" class="mb-cm-link mt-2" wire:click="loadConversionRules" wire:loading.attr="disabled" wire:target="loadConversionRules">Load account conversion rules</button>
                                            @error('values.conversion_rules')
                                                <div class="invalid-feedback d-block">{{ $message }}</div>
                                            @enderror
                                        @elseif ($structured)
                                            <textarea id="field-{{ $field }}" rows="5" spellcheck="false"
                                                      class="form-control font-monospace @error('values.'.$field) is-invalid @enderror"
                                                      wire:model="values.{{ $field }}" aria-describedby="help-{{ $field }}"></textarea>
                                            @error('values.'.$field)
                                                <div class="invalid-feedback">{{ $message }}</div>
                                            @enderror
                                        @elseif (EditCapabilities::isMoney($field))
                                            <div class="input-group has-validation">
                                                <input id="field-{{ $field }}" type="text" inputmode="decimal" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                       wire:model="values.{{ $field }}" autocomplete="off" aria-describedby="help-{{ $field }}" @if (EditCapabilities::isSpendLimit($field)) placeholder="No limit" @endif>
                                                <span class="input-group-text">{{ $currency }}</span>
                                                @error('values.'.$field)
                                                    <div class="invalid-feedback">{{ $message }}</div>
                                                @enderror
                                            </div>
                                        @elseif ($options = EditCapabilities::options($entity, $field))
                                            <select id="field-{{ $field }}" class="form-select @error('values.'.$field) is-invalid @enderror"
                                                    @if ($field === 'bid_strategy') wire:model.live="values.{{ $field }}" @else wire:model="values.{{ $field }}" @endif
                                                    aria-describedby="help-{{ $field }}">
                                                @foreach ($options as $value => $label)
                                                    <option value="{{ $value }}">{{ $label }}</option>
                                                @endforeach
                                            </select>
                                            @error('values.'.$field)
                                                <div class="invalid-feedback">{{ $message }}</div>
                                            @enderror
                                        @elseif (EditCapabilities::isSchedule($field))
                                            <input id="field-{{ $field }}" type="datetime-local" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                   wire:model="values.{{ $field }}" aria-describedby="help-{{ $field }}">
                                            @error('values.'.$field)
                                                <div class="invalid-feedback">{{ $message }}</div>
                                            @enderror
                                        @elseif ($field === 'frequency_max' || $field === 'frequency_days')
                                            <div class="input-group has-validation">
                                                <input id="field-{{ $field }}" type="number" min="1" max="90" step="1" inputmode="numeric" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                       wire:model="values.{{ $field }}" autocomplete="off" aria-describedby="help-{{ $field }}" placeholder="No cap">
                                                <span class="input-group-text">{{ $field === 'frequency_max' ? 'times' : 'days' }}</span>
                                                @error('values.'.$field)
                                                    <div class="invalid-feedback">{{ $message }}</div>
                                                @enderror
                                            </div>
                                        @elseif ($field === 'age_min' || $field === 'age_max')
                                            <div class="input-group has-validation">
                                                <input id="field-{{ $field }}" type="number" min="18" max="65" step="1" inputmode="numeric" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                       wire:model="values.{{ $field }}" autocomplete="off" aria-describedby="help-{{ $field }}">
                                                <span class="input-group-text">years</span>
                                                @error('values.'.$field)
                                                    <div class="invalid-feedback">{{ $message }}</div>
                                                @enderror
                                            </div>
                                        @elseif ($field === 'publisher_platforms')
                                            <div id="field-{{ $field }}" class="d-flex flex-wrap gap-3 @error('values.'.$field) is-invalid @enderror" role="group" aria-describedby="help-{{ $field }}">
                                                @foreach (EditCapabilities::META_PLATFORMS as $value => $label)
                                                    <div class="form-check">
                                                        <input class="form-check-input" type="checkbox" id="field-{{ $field }}-{{ $value }}" value="{{ $value }}" wire:model="values.{{ $field }}">
                                                        <label class="form-check-label" for="field-{{ $field }}-{{ $value }}">{{ $label }}</label>
                                                    </div>
                                                @endforeach
                                            </div>
                                            @error('values.'.$field)
                                                <div class="invalid-feedback d-block">{{ $message }}</div>
                                            @enderror
                                        @elseif ($field === 'target_roas')
                                            <div class="input-group has-validation">
                                                <input id="field-{{ $field }}" type="text" inputmode="decimal" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                       wire:model="values.{{ $field }}" autocomplete="off" aria-describedby="help-{{ $field }}" placeholder="No target">
                                                <span class="input-group-text">× spend</span>
                                                @error('values.'.$field)
                                                    <div class="invalid-feedback">{{ $message }}</div>
                                                @enderror
                                            </div>
                                        @else
                                            <input id="field-{{ $field }}" type="text" class="form-control @error('values.'.$field) is-invalid @enderror"
                                                   wire:model="values.{{ $field }}" autocomplete="off" aria-describedby="help-{{ $field }}">
                                            @error('values.'.$field)
                                                <div class="invalid-feedback">{{ $message }}</div>
                                            @enderror
                                        @endif
                                        <div id="help-{{ $field }}" class="mb-cm-current">
                                            <span>Currently: <strong>{{ $show($field, EditCapabilities::current($entity, $field)) }}</strong></span>
                                            @if ($hints[$field] ?? null)<span>{{ $hints[$field] }}</span>@endif
                                        </div>
                                        @if ($structured)
                                            </details>
                                        @endif
                                    </div>
                                @empty
                                    <div class="mb-cm-alert is-muted" role="status"><i class="bi bi-lock"></i><div>Nothing on this {{ $typeName }} can be changed from here with the changes switched on now.</div></div>
                                @endforelse

                                @if ($warning && in_array('name', $fields, true))
                                    <div class="mb-cm-alert is-warn" role="note"><i class="bi bi-exclamation-triangle"></i><div>{{ $warning }}</div></div>
                                @endif

                                <div class="mb-cm-actions">
                                    @if ($fields !== [])
                                        <button type="submit" class="mb-btn-primary" wire:loading.attr="disabled" wire:target="review">
                                            Review change <i class="bi bi-arrow-right"></i>
                                        </button>
                                    @endif
                                    <a href="{{ route('campaign-manager.show', $campaign) }}" class="mb-cm-link" wire:navigate>Cancel</a>
                                </div>
                            </form>
                        @endif
                    </div>
                @elseif ($step === 'review')
                    <div class="mb-perf-card-head">
                        <div class="mb-perf-card-title-wrap">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon"><i class="bi bi-eye"></i></span>
                                <h2 class="mb-perf-card-title">Review before applying</h2>
                            </div>
                            <div class="mb-cell-meta">This is exactly what will be sent to {{ $platform }}, for {{ $typeName }} <strong class="mb-cm-mono">{{ $entity->external_id }}</strong> on account <span class="mb-cm-mono">{{ $campaign->ad_account_id }}</span>.</div>
                        </div>
                    </div>
                    <div class="mb-cm-body">
                        @if ($edit->isStructural())
                            @php $deleting = $edit->action === CampaignEntityEdit::Delete; @endphp
                            <div @class(['mb-cm-action-summary', 'is-danger' => $deleting])>
                                <span class="mb-cm-action-icon"><i class="bi {{ $deleting ? 'bi-trash3' : 'bi-copy' }}"></i></span>
                                <div>
                                    <h3>{{ $deleting ? 'Delete' : 'Duplicate' }} {{ $entity->name ?: $entity->external_id }}</h3>
                                    <p>{{ $actionSummary }}</p>
                                    @if (isset($edit->details['conversion_event']))
                                        <dl class="mb-cm-kv">
                                            <dt>Original event (unchanged)</dt>
                                            <dd>{{ data_get($entity->settings, 'promoted_object.custom_event_type', 'Custom conversion') }}</dd>
                                            <dt>New paused copy event</dt>
                                            <dd>{{ $edit->details['conversion_event'] }}</dd>
                                        </dl>
                                    @endif
                                    @if ($deleting && $edit->details)
                                        <dl class="mb-cm-kv">
                                            <dt>Spent over its life</dt>
                                            <dd>{{ EditCapabilities::money((float) ($edit->details['spend'] ?? 0), $edit->details['currency'] ?? $currency) }} {{ $edit->details['currency'] ?? $currency }}</dd>
                                            <dt>Impressions over its life</dt>
                                            <dd>{{ number_format((int) ($edit->details['impressions'] ?? 0)) }}</dd>
                                        </dl>
                                    @endif
                                </div>
                            </div>
                        @endif
                        <div class="mb-cm-diff">
                            @foreach (EditCapabilities::ordered($entity, (array) $edit->changes) as $field => $change)
                                @php
                                    $delta = EditCapabilities::isMoney($field) && is_numeric($change['before']) && is_numeric($change['after']) && (float) $change['before'] > 0
                                        ? ((float) $change['after'] - (float) $change['before']) / (float) $change['before'] * 100
                                        : null;
                                    $shift = EditCapabilities::isSchedule($field) ? EditCapabilities::shift($change['before'], $change['after']) : null;
                                    $starts = $field === 'status' ? in_array($change['after'], EditCapabilities::LIVE, true) : null;
                                    $deltaLabel = match (true) {
                                        $delta !== null => sprintf('%+.0f%%', $delta),
                                        $shift !== null => $shift['label'],
                                        $starts !== null => $starts ? 'Starts' : 'Stops',
                                        default => '—',
                                    };
                                    $direction = $delta ?? $shift['direction'] ?? ($starts === null ? 0 : ($starts ? 1 : -1));
                                @endphp
                                <div class="mb-cm-diff-row">
                                    <div class="mb-cm-diff-field">{{ ManagerFormat::field($field) }}</div>
                                    <div class="mb-cm-diff-side"><small>Now on {{ $platform }}</small><span class="mb-cm-before">{{ $show($field, $change['before']) }}</span></div>
                                    <i class="bi bi-arrow-right mb-cm-diff-arrow" aria-hidden="true"></i>
                                    <div class="mb-cm-diff-side"><small>Will become</small><span class="mb-cm-after">{{ $show($field, $change['after']) }}</span></div>
                                    <span @class(['mb-cm-delta', 'is-up' => $direction > 0, 'is-down' => $direction < 0]) title="Change">{{ $deltaLabel }}</span>
                                </div>
                            @endforeach
                        </div>

                        @if ($warning && array_key_exists('name', (array) $edit->changes))
                            <div class="mb-cm-alert is-warn" role="note"><i class="bi bi-exclamation-triangle"></i><div>{{ $warning }}</div></div>
                        @endif

                        @if ($confirmations)
                            <div class="mb-cm-alert is-warn" role="note">
                                <i class="bi bi-shield-exclamation"></i>
                                <div class="flex-grow-1">
                                    <ul class="mt-0">
                                        @foreach ($confirmations as $note)
                                            <li>{{ $note }}</li>
                                        @endforeach
                                    </ul>
                                    <div class="form-check mb-cm-ack">
                                        <input class="form-check-input" type="checkbox" id="acknowledged" wire:model="acknowledged">
                                        <label class="form-check-label" for="acknowledged">I have read the above and want this change applied.</label>
                                    </div>
                                </div>
                            </div>
                        @endif

                        <p class="mb-cm-note">
                            <i class="bi bi-shield-check"></i>
                            Before sending, {{ $platform }} is read again. If this {{ $typeName }} has changed there since
                            {{ $edit->created_at->diffForHumans() }}, nothing is sent and you will be shown why. Afterwards it is read once more to confirm the change took.
                        </p>

                        <div class="mb-cm-actions">
                            <button type="button" @class(['mb-btn-primary', 'mb-cm-danger' => $edit->action === CampaignEntityEdit::Delete]) wire:click="confirm" wire:loading.attr="disabled" wire:target="confirm,back">
                                <span wire:loading.remove wire:target="confirm">
                                    @if ($edit->action === CampaignEntityEdit::Delete)
                                        <i class="bi bi-trash3"></i> Delete permanently
                                    @elseif ($edit->action === CampaignEntityEdit::Duplicate)
                                        <i class="bi bi-copy"></i> Make the copy
                                    @else
                                        <i class="bi bi-check2"></i> Confirm and apply
                                    @endif
                                </span>
                                <span wire:loading wire:target="confirm"><span class="spinner-border spinner-border-sm"></span> Applying…</span>
                            </button>
                            <button type="button" class="mb-cm-link" wire:click="back" wire:loading.attr="disabled" wire:target="confirm,back"><i class="bi bi-arrow-left"></i> Back</button>
                        </div>
                    </div>
                @else
                    <div class="mb-cm-body">
                        @php
                            [$tone, $icon, $title, $detail] = match ($edit->state) {
                                CampaignEntityEdit::Applied => ['ok', 'bi-check2-circle', 'Done.', match ($edit->action) {
                                    CampaignEntityEdit::Delete => ($edit->details['pending'] ?? false)
                                        ? $platform.' has marked this '.$typeName.' for deletion; it no longer delivers and cannot be restarted.'
                                        : $platform.' no longer has this '.$typeName.'.',
                                    CampaignEntityEdit::Duplicate => $platform.' now has a '.($entity->platform === 'linkedin' ? 'DRAFT' : 'paused').' copy, '.($edit->details['copy_name'] ?? $edit->details['copy_id']).'. Nothing in it spends until it is turned on.',
                                    default => $platform.' now reports the new '.implode(', ', array_map(ManagerFormat::field(...), array_keys(EditCapabilities::ordered($entity, (array) $edit->changes)))).' (confirmed '.$edit->verified_at->diffForHumans().').',
                                }],
                                CampaignEntityEdit::Unconfirmed => ['warn', 'bi-hourglass-split', 'Sent, not confirmed.', $edit->error],
                                CampaignEntityEdit::Stale => ['warn', 'bi-arrow-repeat', 'Not sent.', $edit->error],
                                CampaignEntityEdit::Cancelled => ['muted', 'bi-x-circle', 'Cancelled.', 'This change was cancelled.'],
                                default => ['err', 'bi-exclamation-octagon', $edit->readback ? 'Partly applied.' : 'Not applied.', $edit->error],
                            };
                        @endphp
                        <div class="mb-cm-result" role="status">
                            <span class="mb-cm-result-icon is-{{ $tone }}"><i class="bi {{ $icon }}"></i></span>
                            <div>
                                <h2>{{ $title }}</h2>
                                <p>{{ $detail }}</p>
                            </div>
                        </div>

                        @if ($edit->readback && ! $edit->isStructural())
                            <dl class="mb-cm-kv">
                                @foreach (EditCapabilities::ordered($entity, (array) $edit->readback) as $field => $value)
                                    <dt>{{ ManagerFormat::field($field) }} on {{ $platform }}</dt>
                                    <dd>{{ $show($field, $value) }}</dd>
                                @endforeach
                            </dl>
                        @endif

                        <div class="mb-cm-actions mt-3">
                            <a href="{{ route('campaign-manager.show', $campaign) }}" class="mb-btn-primary" wire:navigate>Back to campaign</a>
                            @if ($copyCampaign)
                                <a href="{{ route('campaign-manager.show', $copyCampaign) }}" class="mb-btn-ghost" wire:navigate><i class="bi bi-box-arrow-up-right"></i> Open the copy</a>
                            @endif
                            @if ($copy)
                                <a href="{{ route('campaign-manager.edit', [$campaign, $copy]) }}" class="mb-btn-ghost" wire:navigate><i class="bi bi-pencil"></i> Edit the copy</a>
                            @endif
                            @if (! $refusal)
                                <button type="button" class="mb-cm-link" wire:click="startOver"><i class="bi bi-arrow-counterclockwise"></i> Make another change</button>
                            @endif
                        </div>
                    </div>
                @endif
            </section>

            <aside class="mb-cm-aside">
                @if ($facts !== [])
                    <section class="mb-card">
                        <div class="mb-perf-card-head">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon is-muted"><i class="bi bi-card-checklist"></i></span>
                                <h2 class="mb-perf-card-title">Now on {{ $platform }}</h2>
                            </div>
                        </div>
                        <div class="mb-cm-body">
                            <dl class="mb-cm-kv mt-0">
                                @foreach ($facts as $fact)
                                    <dt>{{ $fact['label'] }}</dt>
                                    <dd>{{ $fact['value'] }}</dd>
                                @endforeach
                            </dl>
                        </div>
                    </section>
                @endif

                @if ($step === 'edit')
                    <section class="mb-card">
                        <div class="mb-perf-card-head">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon is-muted"><i class="bi bi-three-dots"></i></span>
                                <h2 class="mb-perf-card-title">More actions</h2>
                            </div>
                        </div>
                        <div class="mb-cm-body">
                            <ul class="mb-cm-more">
                                @foreach ($actions as $action => $reason)
                                    @php $deleting = $action === CampaignEntityEdit::Delete; @endphp
                                    <li>
                                        <button type="button" @class(['mb-cm-more-btn', 'is-danger' => $deleting]) wire:click="propose('{{ $action }}')" wire:loading.attr="disabled" wire:target="propose" @disabled($reason !== null)>
                                            <i class="bi {{ $deleting ? 'bi-trash3' : 'bi-copy' }}"></i>
                                            <span>{{ $deleting ? 'Delete' : 'Duplicate' }} this {{ $typeName }}</span>
                                            <span wire:loading wire:target="propose('{{ $action }}')" class="spinner-border spinner-border-sm ms-auto"></span>
                                        </button>
                                        <small>{{ $reason ?? ($deleting ? 'Shows what it has spent before anything is removed.' : ($entity->platform === 'linkedin' ? 'Reconstructed as DRAFT; existing sponsored content is reused.' : 'Made paused, beside the original.')) }}</small>
                                    </li>
                                @endforeach
                            </ul>
                            @if ($entity->platform === 'meta' && $entity->entity_type === 'ad_set')
                                <hr>
                                <h3 class="h6">Copy with a different conversion event</h3>
                                <p class="mb-cm-note">Meta does not let published ad sets change conversion event. Create a paused copy instead; the original and its history stay unchanged.</p>
                                @if ($eventCopyRefusal)
                                    <p class="mb-cm-note">{{ $eventCopyRefusal }}</p>
                                @else
                                    <label for="copy-conversion-event" class="form-label">New copy conversion event</label>
                                    <select id="copy-conversion-event" class="form-select mb-2" wire:model="copyConversionEvent">
                                        <option value="">Choose an event</option>
                                        @foreach ($eventCopyOptions as $value => $label)
                                            <option value="{{ $value }}">{{ $label }}</option>
                                        @endforeach
                                    </select>
                                    <button type="button" class="mb-btn-primary" wire:click="reviewEventCopy" wire:loading.attr="disabled" wire:target="reviewEventCopy">
                                        <i class="bi bi-copy"></i> Review paused event copy
                                    </button>
                                @endif
                            @endif
                        </div>
                    </section>
                @endif

                @if ($step === 'edit' && $locked)
                    <section class="mb-card">
                        <div class="mb-perf-card-head">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon is-muted"><i class="bi bi-lock"></i></span>
                                <h2 class="mb-perf-card-title">Not changeable here</h2>
                            </div>
                        </div>
                        <div class="mb-cm-body">
                            <ul class="mb-cm-locked">
                                @foreach ($locked as $field => $reason)
                                    <li><i class="bi bi-dash-circle"></i><div><strong>{{ ManagerFormat::field($field) }}</strong><span>{{ $reason }}</span></div></li>
                                @endforeach
                            </ul>
                        </div>
                    </section>
                @endif

                @if (! empty($entity->settings))
                    <details class="mb-card mb-cm-collapse">
                        <summary class="mb-perf-card-head">
                            <div class="mb-perf-card-title-row">
                                <span class="mb-perf-card-icon mb-cm-perf-icon is-muted"><i class="bi bi-list-ul"></i></span>
                                <h2 class="mb-perf-card-title">Other settings</h2>
                            </div>
                            <i class="bi bi-chevron-down mb-card-chevron"></i>
                        </summary>
                        <div class="mb-cm-body">
                            <p class="mb-cm-note">Everything {{ $platform }} last reported for this {{ $typeName }}, including what cannot be changed from here.</p>
                            <dl class="mb-cm-kv">
                                @foreach (collect($entity->settings)->sortKeys() as $field => $value)
                                    <dt>{{ ManagerFormat::field($field) }}</dt>
                                    <dd>
                                        @if (ManagerFormat::isLong($value))
                                            <details><summary>Show</summary><pre>{{ ManagerFormat::value($value) }}</pre></details>
                                        @else
                                            {{ ManagerFormat::setting($field, $value, $entity) }}
                                        @endif
                                    </dd>
                                @endforeach
                            </dl>
                        </div>
                    </details>
                @endif
            </aside>
        </div>
    </div>
</div>
