<a class="a-close" onclick="ptmenu.closeForm()"><i class="fa fa-close" aria-hidden="true"></i></a>
<input type="hidden" id="input-append-categories-link" value="{{ append_categories_link }}" />
<div class="frm-container">
    <div class="frm-heading">
        <h4 class="frm-title">{{ text_item_form }}</h4>
    </div>
    <div class="frm-body">
        <div class="frm-button">
            <button type="button" class="btn btn-primary btn-submit" onclick="ptmenu.submitTopItemForm({{ menu_id }})" title="{{ button_save }}"><i class="fa fa-save"></i> Save</button>
        </div>
        <div class="frm-left">
            <ul class="frm-list">
                <li class="active"><a href="#tab-general" data-toggle="tab">{{ text_general_setting }}</a></li>
                <li><a href="#tab-content" data-toggle="tab">{{ text_mega_setting }}</a></li>
            </ul>
        </div>
        <div class="frm-right">
            {% if error_warning %}
            <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
            {% endif %}
            <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-menu-item" class="form-horizontal">
                <div class="tab-content">
                    <div id="tab-general" class="tab-pane active">
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-item-name">{{ entry_item_name }}</label>
                            <div class="col-sm-6">
                                <input type="text" id="input-item-name" class="form-control" value="{{ name }}" name="name" />
                                {% if error_name %}
                                    <div class="text-danger">{{ error_name }}</div>
                                {% endif %}
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-status">{{ entry_status }}</label>
                            <div class="col-sm-4">
                                <select name="status" id="input-status" class="form-control">
                                    {% if status %}
                                        <option value="1" selected="selected">{{ text_enabled }}</option>
                                        <option value="0">{{ text_disabled }}</option>
                                    {% else %}
                                        <option value="1">{{ text_enabled }}</option>
                                        <option value="0" selected="selected">{{ text_disabled }}</option>
                                    {% endif %}
                                </select>
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-title">{{ entry_title }}</label>
                            <div class="col-sm-6">
                                {% for language in languages %}
                                <div class="input-group">
                                    <span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /> {{ language.name }}</span>
                                    <input type="text" name="title[{{ language.language_id }}]" value="{{ title[language.language_id] ? title[language.language_id] : '' }}" placeholder="" id="input-title{{ language.language_id }}" class="form-control" />
                                </div>
                                {% endfor %}
                            </div>
                            <div class="col-sm-1"></div>
                            <div class="col-sm-3">
                                <div class="checkbox">
                                    <input type="checkbox" name="disable_title" value="{{ disable_title }}" {% if disable_title %} checked="checked" {% endif %} /> {{ text_hide_title }}
                                </div>
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-link">{{ entry_link }}</label>
                            <div class="col-sm-6">
                                <select class="form-control link-selection">
                                    {% set flg = 0 %}
                                    {% for mlink in links %}
                                    <option value="{{ mlink.url }}" {% if link == mlink.url %} selected="selected" {% set flg = 1 %} {% endif %}>{{ mlink.label }}</option>
                                    {% endfor %}
                                    <option value="0" {% if flg == 0 %} selected="selected" {% endif %}>{{ text_custom_link }}</option>
                                </select>

                                <input type="text" id="input-link" name="link" value="{{ link }}" class="form-control" style="margin-top: 10px"/>
                            </div>
                            <div class="col-sm-1"></div>
                            <div class="col-sm-3">
                                <div class="checkbox">
                                    <input type="checkbox" name="disable_link" value="{{ disable_link }}" {% if disable_link %} checked="checked" {% endif %} /> {{ text_disable_link }}
                                </div>
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-sub-menu-type">{{ entry_menu_content_type }}</label>
                            <div class="col-sm-2">
                                <select name="sub_menu_type" id="input-sub-menu-type" class="form-control sub-type-selection">
                                    <option value="mega"    {% if sub_menu_type == 'mega' %}    selected="selected" {% endif %}>{{ text_megamenu }}</option>
                                    <option value="flyout"  {% if sub_menu_type == 'flyout' %}  selected="selected" {% endif %}>{{ text_flyoutmenu }}</option>
                                </select>
                            </div>
                            <label class="frm-label col-sm-2 sub-width-container" for="input-sub-menu-width">{{ entry_menu_width }}</label>
                            <div class="col-sm-2">
                                <input type="text" name="sub_menu_content_width" id="input-sub-menu-width" class="form-control sub-width-container" value="{{ sub_menu_content_width }}" />
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-item-align">{{ entry_item_align }}</label>
                            <div class="col-sm-2">
                                <select name="item_align" id="input-item-align" class="form-control">
                                    <option value="left"    {% if item_align == 'left' %}    selected="selected" {% endif %}>{{ text_left }}</option>
                                    <option value="right"   {% if item_align == 'right' %}   selected="selected" {% endif %}>{{ text_right }}</option>
                                </select>
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-icon">{{ entry_icon }}</label>
                            <div class="col-sm-6">
                                <a href="" id="thumb-image" data-toggle="image" class="img-thumbnail"><img src="{{ thumb }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>
                                <input type="hidden" name="icon" value="{{ icon }}" id="input-image" />
                            </div>
                        </div>
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-position">{{ entry_order }}</label>
                            <div class="col-sm-2">
                                <input type="text" id="input-position" name="position" value="{{ position }}" class="form-control" />
                            </div>
                        </div>
                    </div>

                    <div id="tab-content" class="tab-pane">
                        <div class="frm-group">
                            <label class="frm-label col-sm-2" for="input-sub-menu-content-type">{{ entry_content_type }}</label>
                            <div class="col-sm-4">
                                <select name="sub_menu_content_type" id="input-sub-menu-content-type" class="form-control">
                                    <option value="widget"   {% if sub_menu_content_type == 'widget' %}    selected="selected" {% endif %}>{{ text_widget }}</option>
                                    <option value="category" {% if sub_menu_content_type == 'category' %}  selected="selected" {% endif %}>{{ text_category }}</option>
                                    <option value="children" {% if sub_menu_content_type == 'children' %}  selected="selected" {% endif %}>{{ text_children }}</option>
                                </select>
                            </div>
                        </div>
                        <div class="frm-group frm-group-content frm-group-category">
                            <label class="frm-label col-sm-2" for="input-sub-menu-category">{{ text_choose_top_category }}</label>
                            <div class="col-sm-4 frm-group-category">
                                <select name="category_id" id="input-sub-menu-category" class="form-control">
                                    {% for category in categories %}
                                        <option value="{{ category.category_id }}" {% if category_id == category.category_id %} selected="selected" {% endif %}>{{ category.name }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <div class="col-sm-2 frm-group-category">
                                <button type="button" class="btn btn-primary btn-widget" onclick="ptmenu.addCategoryWidget()"><i class="fa fa-plus"></i> {{ text_add_widget }}</button>
                                <img class="frm-loader-img" src="{{ loader_image }}" alt="loader_image" />
                            </div>
                        </div>
                        <div class="frm-group frm-group-content frm-group-widget">
                            <label class="frm-label col-sm-2">{{ entry_choose_widget }}</label>
                            <div class="col-sm-4">
                                <select id="widget-type" class="form-control">
                                    <option value="category">{{ text_category }}</option>
                                    <option value="product">{{ text_product }}</option>
                                    <option value="html">{{ text_html }}</option>
                                    <<option value="link">{{ text_link }}</option>
                                </select>
                            </div>
                            <div class="col-sm-4">
                                <select id="widget-cols" class="form-control">
                                    <option value="2">{{ 1 ~ " " ~ text_column }}</option>
                                    <option value="4">{{ 2 ~ " " ~ text_columns }}</option>
                                    <option value="6">{{ 3 ~ " " ~ text_columns }}</option>
                                    <option value="8">{{ 4 ~ " " ~ text_columns }}</option>
                                    <option value="10">{{ 5 ~ " " ~ text_columns }}</option>
                                    <option value="12">{{ 6 ~ " " ~ text_columns }}</option>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <button type="button" class="btn btn-primary btn-widget" onclick="ptmenu.addWidget()"><i class="fa fa-plus"></i> {{ text_add_widget }}</button>
                                <img class="frm-loader-img" src="{{ loader_image }}" alt="loader_image" />
                            </div>
                        </div>

                        <div class="frm-group frm-group-content frm-group-children">
                            <label class="frm-label col-sm-2" for="input-cols">{{ entry_number_cols }}</label>
                            <div class="col-sm-4">
                                <select id="input-cols" name="sub_menu_content_columns" class="form-control">
                                    <option value="1" {% if sub_menu_content_columns == 1 %} selected="selected" {% endif %}>{{ 1 ~ " " ~ text_column }}</option>
                                    <option value="2" {% if sub_menu_content_columns == 2 %} selected="selected" {% endif %}>{{ 2 ~ " " ~ text_columns }}</option>
                                    <option value="3" {% if sub_menu_content_columns == 3 %} selected="selected" {% endif %}>{{ 3 ~ " " ~ text_columns }}</option>
                                    <option value="4" {% if sub_menu_content_columns == 4 %} selected="selected" {% endif %}>{{ 4 ~ " " ~ text_columns }}</option>
                                    <option value="5" {% if sub_menu_content_columns == 5 %} selected="selected" {% endif %}>{{ 5 ~ " " ~ text_columns }}</option>
                                    <option value="6" {% if sub_menu_content_columns == 6 %} selected="selected" {% endif %}>{{ 6 ~ " " ~ text_columns }}</option>
                                </select>
                            </div>
                        </div>
                        <!-- Widget Type Container -->
                        <div class="widget-container widget-sortable" id="widget-type-widget-container">
                            {% if widget %}
                                {% if widget.widget %}
                                    {% set i = 0 %}
                                    {% for w in widget.widget %}
                                        <div class="widget-block col-sm-{{ w.cols }}">
                                            <div class="widget-content">
                                                <a class="a-resize-minus a-left" onclick="ptmenu.decreaseColumn($(this))"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
                                                <a class="a-resize-plus a-left" onclick="ptmenu.increaseColumn($(this))"><i class="fa fa-chevron-right" aria-hidden="true"></i></a>
                                                <div class="widget-name-container">
                                                    {% if w.type == 'category' or w.type == 'product' %}
                                                        <span class="name">{{ w.name ? w.name : '...' }}</span>
                                                    {% endif %}

                                                    {% if w.type == 'html' or w.type == 'link' %}
                                                        <span class="name">{{ w.name[lang_id] ? w.name[lang_id] : '...' }}</span>
                                                    {% endif %}

                                                </div>
                                                <div class="widget-action">
                                                    <a class="a-config" onclick="ptmenu.showWidgetConfiguration($(this))"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                                                    <a class="a-config a-delete" onclick="ptmenu.deleteWidget($(this))"><i class="fa fa-times" aria-hidden="true"></i></a>
                                                </div>
                                            </div>

                                            {% if w.type == 'category' %}
                                                <div class="widget-configuration">
                                                    <div class="option"><input type="text" class="w-category" placeholder="{{ text_choose_category }}" /></div>
                                                    <div class="option"><input type="checkbox" class="show-image" {% if w.show_image == 1 %} checked="checked" {% endif %} /> {{ text_show_image }}</div>
                                                    <div class="option"><input type="checkbox" class="show-child" {% if w.show_child == 1 %} checked="checked" {% endif %} /> {{ text_show_child }}</div>
                                                </div>
                                                <input type="hidden" class="widget-name" value="{{ w.name }}" name="widget[widget][{{ i }}][name]" />
                                                <input type="hidden" class="widget-category-id" value="{{ w.category_id }}" name="widget[widget][{{ i }}][category_id]" />
                                                <input type="hidden" class="widget-show-image" value="{{ w.show_image }}" name="widget[widget][{{ i }}][show_image]" />
                                                <input type="hidden" class="widget-show-child" value="{{ w.show_child }}" name="widget[widget][{{ i }}][show_child]" />
                                            {% endif %}

                                            {% if w.type == 'product' %}
                                                <div class="widget-configuration">
                                                    <div class="option"><input type="text" class="w-product" placeholder="{{ text_choose_product }}" /></div>
                                                    <div class="option"><input type="checkbox" class="show-image" {% if w.show_image == 1 %} checked="checked" {% endif %} /> {{ text_show_image }}</div>
                                                </div>
                                                <input type="hidden" class="widget-name" value="{{ w.name }}" name="widget[widget][{{ i }}][name]" />
                                                <input type="hidden" class="widget-product-id" value="{{ w.product_id }}" name="widget[widget][{{ i }}][product_id]" />
                                                <input type="hidden" class="widget-show-image" value="{{ w.show_image }}" name="widget[widget][{{ i }}][show_image]" />
                                            {% endif %}

                                            {% if w.type == 'html' %}
                                                <div class="widget-configuration">
                                                    <ul class="nav nav-tabs ul-widget-lang" id="ul-widget-html-{{ i }}">
                                                        {% for language in languages %}
                                                            <li><a href="#widget-html-language{{ language.language_id }}-{{ i }}" data-toggle="tab"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /> {{ language.name }}</a></li>
                                                        {% endfor %}
                                                    </ul>
                                                    <div class="tab-content" id="tab-widget-html-{{ i }}">
                                                        {% for language in languages %}
                                                            <div class="tab-pane" id="widget-html-language{{ language.language_id }}-{{ i }}">
                                                                <div class="option"><input type="text" name="widget[widget][{{ i }}][name][{{ language.language_id }}]" value="{{ w.name[language.language_id] }}" placeholder="{{ text_title }}" /></div>
                                                                <div class="option">
                                                                    <textarea data-toggle="summernote" rows="10" class="w-html-content" name="widget[widget][{{ i }}][content][{{ language.language_id }}]" placeholder="{{ text_html }}">{{ w.content[language.language_id] }}</textarea>
                                                                </div>
                                                            </div>
                                                        {% endfor %}
                                                    </div>
                                                    <div class="option"><input type="checkbox" class="show-title" {% if w.show_title == 0 %} checked="checked" {% endif %} /> {{ text_hide_title }}</div>
                                                </div>
                                                <input type="hidden" class="widget-show-title" value="{{ w.show_title ? w.show_title : 0}}" name="widget[widget][{{ i }}][show_title]" />
                                            {% endif %}

                                            {% if w.type == 'link' %}
                                                <div class="widget-configuration">
                                                    <ul class="nav nav-tabs ul-widget-lang" id="ul-widget-link-{{ i }}">
                                                        {% for language in languages %}
                                                            <li><a href="#widget-link-language{{ language.language_id }}-{{ i }}" data-toggle="tab"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /> {{ language.name }}</a></li>
                                                        {% endfor %}
                                                    </ul>
                                                    <div class="tab-content" id="tab-widget-link-{{ i }}">
                                                        {% for language in languages %}
                                                            <div class="tab-pane" id="widget-link-language{{ language.language_id }}-{{ i }}">
                                                                <div class="option"><input type="text" name="widget[widget][{{ i }}][name][{{ language.language_id }}]" value="{{ w.name[language.language_id] }}" placeholder="{{ text_title }}" /></div>
                                                            </div>
                                                        {% endfor %}
                                                    </div>
                                                    <div class="option"><input type="text" name="widget[widget][{{ i }}][link]" value="{{ w.link }}" placeholder="{{ text_link }}" /></div>
                                                </div>
                                            {% endif %}

                                            <input type="hidden" class="widget-type" value="{{ w.type }}" name="widget[widget][{{ i }}][type]" />
                                            <input type="hidden" class="widget-cols" value="{{ w.cols }}" name="widget[widget][{{ i }}][cols]" />
                                            <input type="hidden" class="widget-position" value="{{ w.position }}" name="widget[widget][{{ i }}][position]" />
                                        </div>
                                        {% set i = i + 1 %}
                                    {% endfor %}
                                {% else %}
                                    <p class="p-widget-items">{{ text_no_children_items }}</p>
                                {% endif %}
                            {% else %}
                                <p class="p-widget-items">{{ text_no_children_items }}</p>
                            {% endif %}
                        </div>

                        <!-- Category Type Container -->
                        <div class="widget-container widget-sortable" id="widget-type-category-container">
                            {% if widget %}
                                {% if widget.category %}
                                    {% set i = 0 %}
                                    {% for w in widget.category %}
                                        <div class="widget-block col-sm-{{ w.cols }}">
                                            <div class="widget-content">
                                                <a class="a-resize-minus a-left" onclick="ptmenu.decreaseColumn($(this))"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
                                                <a class="a-resize-plus a-left" onclick="ptmenu.increaseColumn($(this))"><i class="fa fa-chevron-right" aria-hidden="true"></i></a>
                                                <div class="widget-name-container">
                                                    <span class="name">{{ w.name ? w.name : '...' }}</span>
                                                </div>
                                                <div class="widget-action">
                                                    <a class="a-config" onclick="ptmenu.showWidgetConfiguration($(this))"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                                                    <a class="a-delete a-config" onclick="ptmenu.deleteWidget($(this))"><i class="fa fa-times" aria-hidden="true"></i></a>
                                                </div>
                                            </div>

                                            <div class="widget-configuration">
                                                <div class="option"><input type="text" class="w-category" placeholder="{{ text_choose_category }}" /></div>
                                                <div class="option"><input type="checkbox" class="show-image" {% if w.show_image == 1 %} checked="checked" {% endif %} /> {{ text_show_image }}</div>
                                                <div class="option"><input type="checkbox" class="show-child" {% if w.show_child == 1 %} checked="checked" {% endif %} /> {{ text_show_child }}</div>
                                            </div>

                                            <input type="hidden" class="widget-name" value="{{ w.name }}" name="widget[category][{{ i }}][name]" />
                                            <input type="hidden" class="widget-type" value="{{ w.type }}" name="widget[category][{{ i }}][type]" />
                                            <input type="hidden" class="widget-cols" value="{{ w.cols }}" name="widget[category][{{ i }}][cols]" />
                                            <input type="hidden" class="widget-position" value="{{ w.position }}" name="widget[category][{{ i }}][position]" />
                                            <input type="hidden" class="widget-category-id" value="{{ w.category_id }}" name="widget[category][{{ i }}][category_id]" />
                                            <input type="hidden" class="widget-show-image" value="{{ w.show_image }}" name="widget[category][{{ i }}][show_image]" />
                                            <input type="hidden" class="widget-show-child" value="{{ w.show_child }}" name="widget[category][{{ i }}][show_child]" />
                                        </div>
                                        {% set i = i + 1 %}
                                    {% endfor %}
                                {% else %}
                                    <p class="p-widget-items">{{ text_no_children_items }}</p>
                                {% endif %}
                            {% else %}
                                <p class="p-widget-items">{{ text_no_children_items }}</p>
                            {% endif %}
                        </div>

                        <input type="hidden" name="category_id" id="input-category-id" value="{{ category_id }}" />
                        <input type="hidden" name="has_child" id="input-has-child" value="{{ has_child }}" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="view/javascript/summernote/summernote.js"></script>
<link href="view/javascript/summernote/summernote.css" rel="stylesheet" />
<script type="text/javascript" src="view/javascript/summernote/summernote-image-attributes.js"></script>
<script type="text/javascript">
    ptmenu.initSortMenuItem();
    ptmenu.chooseCategory();
    ptmenu.chooseProduct();
    ptmenu.checkBoxClick();
    ptmenu.initSummerNote();
</script>

<script type="text/javascript">
    var sub_menu_content_type_selection = $('#input-sub-menu-content-type');
    var sub_menu_content_type = sub_menu_content_type_selection.val();

    $('.widget-container').hide();
    $('#widget-type-'+ sub_menu_content_type +'-container').show();

    $('.frm-group-content').hide();
    $('.frm-group-' + sub_menu_content_type).show();

    sub_menu_content_type_selection.change(function () {
        var sub_menu_content_type = $(this).val();

        $('.frm-group-content').hide();
        $('.frm-group-' + sub_menu_content_type).show();

        $('.widget-container').hide();
        $('#widget-type-'+ sub_menu_content_type +'-container').show();
    });

    $('.ul-widget-lang').each(function () {
        $(this).find('a:first').tab('show');
    });

    $('#input-link').hide();
    var link = $('.link-selection').val();
    if (link == '0') {
        $('#input-link').show();
    } else {
        $('#input-link').hide();
        $('#input-link').val(link);
    }

    $('.link-selection').change(function () {
        var link = $(this).val();
        if (link == '0') {
            $('#input-link').show();
        } else {
            $('#input-link').hide();
            $('#input-link').val(link);
        }
    });

    $('.sub-width-container').hide();
    var sub_menu_type = $('.sub-type-selection').val();
    if (sub_menu_type == 'mega') {
        $('.sub-width-container').show();
    } else {
        $('.sub-width-container').hide();
    }

    $('.sub-type-selection').change(function () {
        var sub_menu_type = $(this).val();
        if (sub_menu_type == 'mega') {
            $('.sub-width-container').show();
        } else {
            $('.sub-width-container').hide();
        }
    });
</script>