<x-app-layout><x-slot name="header"><h1 class="text-2xl font-bold">{{ $group->exists ? 'Edit group' : 'Create group' }}</h1></x-slot><div class="mx-auto max-w-3xl px-4 py-8"><form method="POST" action="{{ $group->exists ? route('groups.update', $group) : route('groups.store') }}" class="space-y-5 rounded-2xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900">@csrf @if($group->exists)@method('PUT')@endif
@php($input='mt-1 block w-full rounded-xl border-slate-300 bg-transparent shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-slate-700')
<div><x-input-label for="name" value="Group name"/><input class="{{ $input }}" id="name" name="name" value="{{ old('name',$group->name) }}" required><x-input-error :messages="$errors->get('name')" class="mt-2"/></div><div class="grid gap-5 sm:grid-cols-2"><div><x-input-label for="contribution_type" value="Frequency"/><select class="{{ $input }}" id="contribution_type" name="contribution_type">@foreach(['daily','weekly','monthly','custom'] as $type)<option value="{{ $type }}" @selected(old('contribution_type',$group->contribution_type)===$type)>{{ ucfirst($type) }}</option>@endforeach</select></div><div><x-input-label for="contribution_amount" value="Amount (NGN)"/><input class="{{ $input }}" type="number" step="0.01" min="1" id="contribution_amount" name="contribution_amount" value="{{ old('contribution_amount',$group->exists ? $group->contribution_amount/100 : '') }}" required></div><div><x-input-label for="maximum_members" value="Maximum members"/><input class="{{ $input }}" type="number" id="maximum_members" name="maximum_members" value="{{ old('maximum_members',$group->maximum_members) }}" required></div><div><x-input-label for="status" value="Status"/><select class="{{ $input }}" id="status" name="status">@foreach(['draft','active','completed','cancelled'] as $status)<option value="{{ $status }}" @selected(old('status',$group->status?->value ?? 'draft')===$status)>{{ ucfirst($status) }}</option>@endforeach</select></div><div><x-input-label for="start_date" value="Start date"/><input class="{{ $input }}" type="date" id="start_date" name="start_date" value="{{ old('start_date',$group->start_date?->format('Y-m-d')) }}" required></div><div><x-input-label for="end_date" value="End date"/><input class="{{ $input }}" type="date" id="end_date" name="end_date" value="{{ old('end_date',$group->end_date?->format('Y-m-d')) }}"></div></div><div><x-input-label for="member_ids" value="Enrolled members"/><select class="{{ $input }} min-h-40" id="member_ids" name="member_ids[]" multiple>@foreach($members as $member)<option value="{{ $member->id }}" @selected(in_array($member->id,old('member_ids',$group->members->pluck('id')->all())))>{{ $member->full_name }} · {{ $member->member_number }}</option>@endforeach</select><p class="mt-1 text-xs text-slate-500">Hold Ctrl/Cmd to select multiple members.</p></div><div class="flex justify-end gap-3"><a href="{{ route('groups.index') }}" class="rounded-xl px-4 py-2 text-sm">Cancel</a><button class="rounded-xl bg-emerald-600 px-5 py-2 text-sm font-semibold text-white">Save group</button></div></form></div></x-app-layout>
