<?php $infoLines = json_decode($patient->info_lines);?>
<?php $infoLines = !$infoLines ? [] : $infoLines; ?>
<div moe-parent
     url="/embed/{{ $patient->uid }}/allergies/{{ @$selectable ? 1 : 0 }}"
     class="<?= !@$selectable ? 'mt-2' : 'border-bottom' ?> pb-1">
    <div class="d-flex align-items-center mb-2 py-2 <?= @$selectable ? 'px-2' : 'border-top' ?> border-bottom">

        @if(!@$selectable)
        <h6 class="my-0 font-weight-bold text-secondary">Allergies</h6>
        <span class="mx-2 text-secondary">|</span>
        @endif

        <div moe>
            <a start show class="py-0 font-weight-normal">Add</a>
            <form url="/api/clientInfoLine/create">
                <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                <input type="hidden" name="category" value="allergy">
                <div class="mb-2">
                    <input type="text" class="form-control form-control-sm" name="contentText" value="" placeholder="Allergy *" required>
                </div>
                <div class="d-flex align-items-center">
                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                </div>
            </form>
        </div>

        <span class="mx-2 text-secondary">|</span>
        <div moe>
            <a start show class="">Multi</a>
            <form url="/api/clientInfoLine/createMultiple">
                <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                <input type="hidden" name="category" value="allergy">
                <div class="mb-2">
                    <textarea class="form-control form-control-sm" rows="8" name="contentTexts" value="" placeholder="Allergies *" required></textarea>
                </div>
                <div class="d-flex align-items-center">
                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                </div>
            </form>
        </div>

        @if(!@$selectable)
        <span class="mx-2 text-secondary">|</span>
        <a start show class="py-0 font-weight-normal"
           href="/patients/view/{{ $patient->uid }}/allergies">
            View All
        </a>
        @endif
    </div>
    <div class="px-2">
    <table class="table table-sm border-0 my-0">
        <tbody>
        <?php $itemCount = 0;
        ?>
        @foreach($infoLines as $category => $lines)
            @if($category === "allergy")
                @foreach ($lines as $line)
                    <?php $itemCount++; ?>
                    <tr>
                        <td class="text-black p-0 border-0 pb-1">
                            <div class="d-flex allergy-item">
                                @if(@$selectable)
                                    <span class="mr-2 d-inline-flex align-items-center">
                                        <input type="checkbox" class="my-0 allergy-item-checkbox">
                                    </span>
                                @endif
                                <div moe relative class="mr-2">
                                    <a class="on-hover-opaque" start show title="Delete">
                                        <i class="font-size-11 fa fa-trash-alt text-danger"></i>
                                    </a>
                                    <form url="/api/clientInfoLine/remove">
                                        <input type="hidden" name="uid" value="{{ $line->uid }}">
                                        <p class="small">Are you sure you want to delete this entry?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                <div moe relative class="mr-2">
                                    <a class="on-hover-opaque" start show title="Edit">
                                        <i class="font-size-11 fa fa-edit"></i>
                                    </a>
                                    <form url="/api/clientInfoLine/updateContent">
                                        <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                                        <input type="hidden" name="uid" value="{{ $line->uid }}">
                                        <input type="hidden" name="category" value="allergy">
                                        <div class="mb-2">
                                            <input type="text" class="form-control form-control-sm" name="contentText" placeholder="Allergy *" value="{{$line->contentText}}" required>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                <span class="content-html text-nowrap"><b>{{$line->contentText}}</b></span>
                            </div>
                        </td>
                    </tr>
                @endforeach
            @endif
        @endforeach
        @if($itemCount === 0)
            <tr>
                <td class="text-secondary p-0 border-0">
                    No items to show
                </td>
            </tr>
        @endif
        </tbody>
    </table>
    </div>
</div>
