{{-- Rules --}}

{{ __('Your margin rules') }}

{{ __('Most specific wins: service beats category beats global.') }}

@forelse ($rules as $rule) @empty @endforelse
{{ __('Scope') }} {{ __('Applies to') }} {{ __('Margin') }} {{ __('Status') }} {{ __('Action') }}
@php $scopeTone = ['service' => 'rf-badge-active', 'category' => 'rf-badge-info', 'global' => 'rf-badge-neutral'][$rule->scope]; @endphp {{ __(ucfirst($rule->scope)) }} @if ($rule->scope === 'service') {{ $rule->service?->name ?? '—' }} @elseif ($rule->scope === 'category') {{ $rule->category?->name ?? '—' }} @else {{ __('All services') }} @endif @if ($rule->margin_type === 'percent') +{{ rtrim(rtrim(number_format((float) $rule->margin_value, 2), '0'), '.') }}% @else +{{ rate_money($rule->margin_value, $this->panelCurrency()) }} @endif
{{-- Live preview --}}

{{ __('Price preview') }}

{{ __('See exactly what your client pays vs your owner cost.') }}

{{-- Searchable, server-side: the catalogue holds thousands of services, so only the first 20 matches ever reach the browser. --}} {{-- .live on purpose: with a deferred wire:model the child component kept the chosen service but the parent never re-rendered, so picking a service showed NOTHING until another request. --}} @if ($preview)
{{ \Illuminate\Support\Str::limit($preview['name'], 34) }} {{ $preview['type'] === 'package' ? __('Flat') : __('per 1000') }}
{{ __('Your owner cost') }} {{ rate_money($preview['owner'], $preview['currency']) }}
{{ __('Client pays') }} {{ rate_money($preview['client'], $preview['currency']) }}
{{ __('Your margin') }} {{ rate_money($preview['margin'], $preview['currency']) }} (+{{ $preview['margin_pct'] }}%)
@else

{{ __('Pick a service to preview its price.') }}

@endif
{{-- Rule editor open stays server-driven: the Category/Service selects are rendered conditionally from $scope (wire:model.live), so the server must build the right form. render() is light. CLOSE is client-side via wire-model. --}}
@if ($scope === 'category')
{{-- Searchable server-side: 600+ categories, first 20 matches only. --}} @error('category_id')

{{ $message }}

@enderror
@elseif ($scope === 'service')
{{-- Searchable server-side: thousands of services, first 20 matches only. --}} @error('service_id')

{{ $message }}

@enderror
@endif
@error('margin_value')

{{ $message }}

@enderror

{{ __('Percent: client price = owner price × (1 + margin/100). Fixed: client price = owner price + margin.') }}