<x-app-layout title="GP pricing · Settings">
    <x-settings.page
        title="GP products & services"
        description="Prices for general practice consultations and clinic services at {{ $organization->name }}. Drug prices are managed in Inventory; lab test prices are set by admins in Laboratory catalog."
    >
        <p class="text-sm">
            <a href="{{ route('care.settings') }}" class="font-medium text-indigo-600 hover:text-indigo-800">← Facility settings</a>
        </p>

        @if (session('success'))
            <p class="rounded-lg bg-emerald-50 px-3 py-2 text-sm text-emerald-800">{{ session('success') }}</p>
        @endif

        <x-settings.card title="Service prices" description="Used for GP consultation bills, registration / patient card, and related charges. Currency: {{ $currency }}.">
            <form method="POST" action="{{ route('care.settings.gp-pricing.update') }}" class="space-y-4">
                @csrf
                @method('PUT')
                <div class="overflow-x-auto">
                    <table class="min-w-full text-left text-sm">
                        <thead>
                            <tr class="border-b border-slate-200 text-xs uppercase tracking-wide text-slate-500">
                                <th class="py-2 pr-3">Service</th>
                                <th class="py-2 pr-3">Type</th>
                                <th class="py-2">Price ({{ $currency }})</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($services as $i => $service)
                                <tr class="border-b border-slate-100">
                                    <td class="py-2.5 pr-3">
                                        <input type="hidden" name="services[{{ $i }}][code]" value="{{ $service['code'] }}">
                                        <p class="font-medium text-slate-900">{{ $service['label'] }}</p>
                                        <p class="text-xs text-slate-400">{{ $service['code'] }}</p>
                                    </td>
                                    <td class="py-2.5 pr-3 text-slate-600">{{ ucfirst($service['type'] ?? 'misc') }}</td>
                                    <td class="py-2.5">
                                        <input
                                            type="number"
                                            name="services[{{ $i }}][amount]"
                                            step="0.01"
                                            min="0"
                                            value="{{ old('services.'.$i.'.amount', number_format(((int) ($service['amount_minor'] ?? 0)) / 100, 2, '.', '')) }}"
                                            @disabled(! $canManage)
                                            class="w-32 rounded-lg border-slate-300 text-sm tabular-nums"
                                            required
                                        >
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                @if ($canManage)
                    <div class="flex justify-end">
                        <button type="submit" class="btn-primary">Save prices</button>
                    </div>
                @endif
            </form>
        </x-settings.card>
    </x-settings.page>
</x-app-layout>
