{% extends 'layouts/admin.twig' %}

{% block content %}
    <ul class="breadcrumbs el">
        <li><a href="/admin/">Home</a> /</li>
        <li class="end">{{ page_meta.title }}</li>
    </ul>

    <h1>{{ page_meta.title }}</h1>
    {{ navigation|raw }}
    {% include 'admin/messages.twig' %}

    <form action="{{ route('incompatible-medications.store', [ item.id ]) }}"
          method="post"
          class="style incompatible">

        {{ form_field({
            'type': 'select',
            'name': 'copy_item_id',
            'label': 'Copy from Product',
            'values': copy_items
        }) }}
        <div class="row">
            <label for="medications">Medications</label>
            <input type="hidden" id="medications" name="medications"
                   class="js_medications_tagit"
                   value="{{ old('medications') }}" />
        </div>
        <script src="/core/admin/js/libs/tagit/js/tag-it.min.js"></script>
        <link rel="stylesheet" href="/core/admin/js/libs/tagit/css/jquery.tagit.css">
        <script>
            var all_medications = {{ all_medications|raw }};
        </script>
        {{ form_field({
            'type': 'select',
            'name': 'severity',
            'label': 'Severity',
            'values': {
                'minor': 'Minor',
                'warning': 'Warning',
                'moderate': 'Moderate',
                'severe': 'Severe'
            },
            'value': old('severity')
        }) }}

        {{ form_field({
            'type': 'text',
            'name': 'message',
            'label': 'Message text',
            'value': old('message')
        }) }}

        <div class="row">
            <button type="submit"
                    class="btn"
                    name="submit">
                Add
            </button>
        </div>
    </form>

    {% if incompatible_medications is not empty %}
        <table class="manage-items">
            <tr>
                <th>Severity</th>
                <th>Name</th>
                <th>Details</th>
                <th>Remove</th>
            </tr>
            {% for medication in incompatible_medications %}
                <tr>
                    <td>{{ medication.level|capitalize }}</td>
                    <td>{{ medication.medication }}</td>
                    <td>{{ medication.message }}</td>
                    <td>
                        <form action="{{ route('incompatible-medications.destroy', [ item.id, medication.id]) }}" method="post" class="removeForm">
                            {{ method_field('DELETE') }}
                            <button type="submit">
                                <i class="fa fa-remove"></i>
                            </button>
                        </form>
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% else %}
        <p>No medications found</p>
    {% endif %}
{% endblock %}