{% extends '@RxConnexion/Admin/content.html.twig' %}
{% block content %}
    <style>
        #add_btn{
            cursor: pointer;
            color: gray;
        }
        .remove_btn{
            cursor: pointer;
            color: #cc4b37;
            float: right;
        }
    </style>
    <form method="POST" action="{{ path('item_package_form', {action: action, id: id}) }}" enctype="multipart/form-data">
        <div class="row max-width-initial">
            <div class="large-6 columns">
                <h5>Basic information</h5>
                <p class="form-hint-text">Enter basic information below</p>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.code) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.code) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.description) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.description) }}
                    </div>
                </div>
            </div>
            <div class="large-6 columns" style="">

                <h5>Items <a href="javascript:void(0);" id="add_btn" title="Add Item(s)"><i class="fa fa-plus"></i></a></h5>
                <p class="form-hint-text">Enter other items below</p>
                <div class="large-12 columns">
                    <div id="cc_container">
                        {% for list in form.itemPackageItems %}
                            <div class="cc_row row" data-idx="{{ loop.index0 }}">
                                <div class="cc_col1 small-12 columns"  data-idx="{{ loop.index0 }}">
                                    <span class="remove_btn" data-idx="{{ loop.index0 }}"><i class="fa fa-times-circle"></i></span>
                                    <input
                                            value="{{ list.vars.value.item.description|default('') }}"
                                            type="text"
                                            name="item_package_form[itemPackageItems][{{ loop.index0 }}][item_description]"
                                            id="itemPackage_itemPackageItem_{{ loop.index0 }}_item_description"
                                            class="itemPackage_itemPackageItem_item_description hidden-cc-{{ loop.index0 }}
                                    ">
                                    <input
                                            value="{{ list.vars.value.item.id|default('') }}"
                                            type="hidden"
                                            name="item_package_form[itemPackageItems][{{ loop.index0 }}][item]"
                                            id="itemPackage_itemPackageItem_{{ loop.index0 }}_item"
                                            class="itemPackage_itemPackageItem_item hidden-cc-{{ loop.index0 }}
                                    ">
                                    <input
                                            value="{{ list.vars.value.id }}"
                                            type="hidden"
                                            name="item_package_form[itemPackageItems][{{ loop.index0 }}][id]"
                                            id="itemPackage_itemPackageItem_{{ loop.index0 }}_id"
                                            class="itemPackage_itemPackageItem_id hidden-cc-{{ loop.index0 }}">
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
            <div class="small-12 columns">
                <hr class="max-width-initial">
                <div class="button-container">
                    <button type="submit" class="button just-continue" name="action" value="{{ action }}"
                            data-message="Are you sure you want to save this information?"
                    >Save</button>
                    {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Item Package Delete' in userData.accesses) %}
                        <button type="submit" class="ask-continue button alert" name="action" value="d"
                                data-message="Are you sure you want to delete this record?"
                        >Delete</button>
                    {% endif %}
                    <a href="{{ path('item_package') }}" class="button secondary">Back</a>
                </div>
            </div>
        </div>
        {{ form_widget(form.action) }}
        {{ form_widget(form.id) }}
        {{ form_widget(form._token) }}
    </form>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        itemPackage_form.settings.id = '{{ action == 'n' ? 0 : itemPackage.idEncoded }}';
        itemPackage_form.settings.item_autocomplete_url = '{{ path('item_autocomplete') }}';
        jQ(document).ready(function(){
            itemPackage_form.init();
        });
        //]]>
    </script>
{% endblock %}