@extends('layouts.app')
@section('title', 'Auto-block Policy')

@section('content')
<section class="content-header">
    <h1><i class="fa fa-shield-alt"></i> Auto-block Policy
        <small>Low-rated contact blocking rules</small></h1>
    <ol class="breadcrumb">
        <li><a href="{{ route('clinic.owner-blocking.index') }}">Patient Blocking</a></li>
        <li class="active">Policy</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-md-7">
            @component('components.widget', ['class' => 'box-primary'])
                <form method="POST" action="{{ route('clinic.owner-blocking.save') }}">
                    @csrf
                    <div class="form-group">
                        <label style="font-weight:normal;cursor:pointer;">
                            <input type="checkbox" name="enable_auto_block" value="1"
                                   {{ $settings->enable_auto_block ? 'checked' : '' }}>
                            <strong>Enable auto-blocking of low-rated contacts</strong>
                        </label>
                        <small class="text-muted" style="display:block;">
                            When ON, the system applies the block immediately after each new
                            evaluation that pushes the owner's cumulative rating below the
                            threshold. When OFF, contacts below the threshold appear in the
                            review checklist for manual action.
                        </small>
                    </div>

                    <div class="row">
                        <div class="col-md-6 form-group">
                            <label>Block rating threshold (%) <span class="text-danger">*</span></label>
                            <input type="number" name="block_rating_threshold" class="form-control"
                                   min="0" max="100"
                                   value="{{ $settings->block_rating_threshold }}">
                            <small class="text-muted">
                                Below this cumulative percentage triggers a block.
                                25% = 1.25/5 stars (default).
                            </small>
                        </div>
                        <div class="col-md-6 form-group">
                            <label>Minimum ratings before evaluating <span class="text-danger">*</span></label>
                            <input type="number" name="min_ratings_to_evaluate" class="form-control"
                                   min="1" max="50"
                                   value="{{ $settings->min_ratings_to_evaluate }}">
                            <small class="text-muted">
                                Avoid blocking new clients on a single bad review. 3 is a
                                reasonable default; raise it if your clinic logs many ratings.
                            </small>
                        </div>
                    </div>

                    <div class="form-group">
                        <label style="font-weight:normal;cursor:pointer;">
                            <input type="checkbox" name="block_zero_credit_limit" value="1"
                                   {{ $settings->block_zero_credit_limit ? 'checked' : '' }}>
                            <strong>Zero the contact credit limit on block</strong>
                        </label>
                        <small class="text-muted" style="display:block;">
                            Recommended ON. The pre-block credit limit is snapshotted so
                            unblocking can offer to restore it.
                        </small>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-save"></i> Save policy
                        </button>
                        <a href="{{ route('clinic.owner-blocking.index') }}" class="btn btn-default">
                            <i class="fa fa-times"></i> Cancel
                        </a>
                    </div>
                </form>
            @endcomponent
        </div>
        <div class="col-md-5">
            <div class="callout callout-info" style="font-size:12.5px;">
                <h4 style="margin-top:0;"><i class="fa fa-info-circle"></i> How blocking takes effect</h4>
                <ul style="padding-left:18px;margin-bottom:0;">
                    <li>The owner's <strong>contact credit limit</strong> is set to <strong>0</strong>
                        (if that option is on) so new invoices can't be created on credit.</li>
                    <li>They <strong>cannot book new appointments</strong> from the booking flow
                        (the booking endpoint refuses with a "owner blocked" message).</li>
                    <li>An <strong>entry appears on the review checklist</strong> at
                        Contact Blocking - even auto-blocked rows stay listed so admins can see them.</li>
                    <li>The contact profile shows a prominent <strong>BLOCKED</strong> banner with
                        the reason and snapshotted rating that caused it.</li>
                    <li>Unblocking is admin-only and prompts whether to <strong>restore the
                        prior credit limit</strong> or leave it at 0.</li>
                </ul>
            </div>
        </div>
    </div>
</section>
@endsection
