@extends('layouts.app')
@section('title', 'Sibling Discounts')
@section('page_title', 'Sibling Discount Rules')
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li><li class="breadcrumb-item active">Sibling Discounts</li>
@endsection

@section('content')
<div class="row g-3">
    <div class="col-lg-7">
        <div class="card">
            <div class="card-header"><i class="bi bi-diagram-3 me-1"></i>Discount Ladder</div>
            <div class="card-body">
                <p class="text-muted small">Applied automatically to discountable fee heads based on each child's order in the family (eldest = 1, who normally pays full).</p>
                <table class="table align-middle">
                    <thead><tr><th>Child Order</th><th>Discount</th><th class="text-end">Actions</th></tr></thead>
                    <tbody>
                        @forelse($rules as $rule)
                            <tr>
                                <td>{{ $rule->child_order }}{{ [1=>'st',2=>'nd',3=>'rd'][$rule->child_order] ?? 'th' }} child</td>
                                <td><span class="badge bg-soft-primary">{{ $rule->type === 'percentage' ? rtrim(rtrim($rule->value,'0'),'.').'%' : 'Rs '.number_format($rule->value) }}</span></td>
                                <td class="text-end">
                                    @can('fees.update')<form method="POST" action="{{ route('sibling-discounts.destroy', $rule) }}" class="d-inline" data-confirm="Remove rule?">@csrf @method('DELETE')<button class="btn btn-sm btn-light border text-danger"><i class="bi bi-trash"></i></button></form>@endcan
                                </td>
                            </tr>
                        @empty
                            <tr><td colspan="3" class="text-muted text-center py-3">No rules configured.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    @can('fees.update')
    <div class="col-lg-5">
        <div class="card">
            <div class="card-header"><i class="bi bi-plus-circle me-1"></i>Add / Update Rule</div>
            <div class="card-body">
                <form method="POST" action="{{ route('sibling-discounts.store') }}">
                    @csrf
                    <div class="mb-3"><label class="form-label">Child Order</label><input type="number" name="child_order" min="1" max="20" class="form-control" required></div>
                    <div class="mb-3"><label class="form-label">Type</label>
                        <select name="type" class="form-select"><option value="percentage">Percentage (%)</option><option value="fixed">Fixed (Rs)</option></select></div>
                    <div class="mb-3"><label class="form-label">Value</label><input type="number" step="0.01" name="value" class="form-control" required></div>
                    <button class="btn btn-primary"><i class="bi bi-check-lg me-1"></i>Save Rule</button>
                </form>
            </div>
        </div>
    </div>
    @endcan
</div>
@endsection
