{% extends "layout_default.phtml" %}
{% set active_menu = 'system' %}
{% block meta_title %}Product configuration{% endblock %}

{% block content %}

<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-settings">{% trans 'General settings' %}</a></li>
        <li><a href="#tab-config">{% trans 'Configuration' %}</a></li>
        <li><a href="#tab-addons">{% trans 'Addons' %}</a></li>
        {% if guest.extension_is_on({"mod":"orderform"}) %}
        <li><a href="#tab-order-form">{% trans 'Custom order form' %}</a></li>
        {% endif %}
        <li><a href="#tab-upgrades">{% trans 'Upgrades' %}</a></li>
        <li><a href="#tab-links">{% trans 'Links' %}</a></li>
    </ul>

    <div class="tabs_container">
        <form method="post" action="admin/product/update" class="mainForm api-form save" data-api-msg="Product configuration updated">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-settings">

            <div class="help">
                <h5>{% trans 'General settings' %}</h5>
            </div>

            <fieldset>
                <div class="rowElem noborder">
                    <label>{% trans 'Type' %}:</label>
                    <div class="formRight noborder">
                        {{ product.type|title }}
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Category' %}:</label>
                    <div class="formRight noborder">
                        {{ mf.selectbox('product_category_id', guest.product_category_get_pairs, product.product_category_id, 1) }}
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Status' %}:</label>
                    <div class="formRight">
                        <input type="radio" name="status" value="enabled"{% if product.status == 'enabled' %} checked="checked"{% endif %}/><label>Enabled</label>
                        <input type="radio" name="status" value="disabled"{% if product.status == 'disabled' %} checked="checked"{% endif %} /><label>Disabled</label>
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Hidden' %}:</label>
                    <div class="formRight">
                        <input type="radio" name="hidden" value="1"{% if product.hidden %} checked="checked"{% endif %}/><label>Yes</label>
                        <input type="radio" name="hidden" value="0"{% if not product.hidden %} checked="checked"{% endif %} /><label>No</label>
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Activation' %}:</label>
                    <div class="formRight">
                        <input type="radio" name="setup" value="after_order"{% if product.setup == 'after_order' %} checked="checked"{% endif %}/><label>After order is placed</label>
                        <input type="radio" name="setup" value="after_payment"{% if product.setup == 'after_payment' %} checked="checked"{% endif %} /><label>After payment is received</label>
                        <input type="radio" name="setup" value="manual"{% if product.setup == 'manual' %} checked="checked"{% endif %} /><label>Manual activation</label>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label>{% trans 'Icon URL' %}:</label>
                    <div class="formRight">
                        <input type="text" name="icon_url" id="bb-icon" value="{{product.icon_url}}" placeholder="" style="width: 80%"/>
                        <input type="button" value="{% trans 'Browse' %}" class="bHtml blueBtn button" />
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Title' %}:</label>
                    <div class="formRight">
                        <input type="text" name="title" value="{{product.title}}" required="required" placeholder=""/>
                    </div>
                    <div class="fix"></div>
                </div>
                <div class="rowElem">
                    <label>{% trans 'Slug' %}:</label>
                    <div class="formRight">
                        <input type="text" name="slug" value="{{product.slug}}" required="required" placeholder=""/>
                    </div>
                    <div class="fix"></div>
                </div>
                
                <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
           </fieldset>

           <fieldset>
               <legend>{% trans 'Payment options' %}</legend>
                {% include "partial_pricing.phtml" with {'product': product} %}

                <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
            </fieldset>

           <fieldset>
               <legend>{% trans 'Product / service description' %}</legend>
                <textarea name="description" cols="5" rows="5" class="bb-textarea">{{product.description}}</textarea>
                
                <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
           </fieldset>

            <div class="body">
                <a href="{{ 'product'|alink }}"  title="" class="btnIconLeft mr10"><img src="images/icons/dark/arrowLeft.png" alt="" class="icon"><span>Go back</span></a>
            </div>

        <div class="fix"></div>
        </div>

        <div class="tab_content nopadding" id="tab-addons">
            <div class="help">
                <h5>{% trans 'Choose which addons you would like to offer with' %} {{ product.title }}</h5>
            </div>

            <table class="tableStatic wide">
                <tbody>
                    {% for addon_id, addon_title in admin.product_addon_get_pairs %}
                    <tr {% if loop.first %}class="noborder"{% endif %}>
                        <td style="width:5%">
                            <input type="hidden" name="addons[{{addon_id}}]" value="0">
                            <input type="checkbox" name="addons[{{addon_id}}]" value="1" id="addon_{{ addon_id }}" {% if addon_id in assigned_addons %}checked="checked"{% endif %}/>
                        </td>
                        <td><label for="addon_{{ addon_id }}">{{addon_title}}</label></td>
                        <td style="width:5%"><a class="bb-button btn14" href="{{ '/product/addon'|alink }}/{{addon_id}}"><img src="images/icons/dark/pencil.png" alt=""></a></td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="3">{% trans 'The list is empty' %}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="3">
                            <a href="{{ 'product/addons'|alink }}#tab-new" title="" class="btnIconLeft mr10 mt5"><img src="images/icons/dark/settings2.png" alt="" class="icon"><span>Create new addon</span></a>
                        </td>
                    </tr>
                </tfoot>
            </table>
            <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />


            <div class="fix"></div>
        </div>

        <div class="tab_content nopadding mainForm" id="tab-upgrades">
            <div class="help">
                <h5>{% trans 'Choose which products can client upgrade to' %}</h5>
            </div>
            <fieldset>
                <div class="rowElem">
                    <label>{% trans 'Product Upgrades' %}</label>
                    <div class="formRight">
                        {% set products = admin.product_get_pairs %}
                        <input type="hidden" name="upgrades" value="">
                        <select name="upgrades[]" multiple="multiple" class="multiple" size="{{products|length}}">
                            {% for id,ptitle in products %}
                            <option value="{{id}}" {% if product.upgrades[id] %}selected="selected"{% endif %}>{{ptitle }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="fix"></div>
                </div>
                <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
                <input type="hidden" name="id" value="{{ product.id }}" />
            </fieldset>
        </div>

        <input type="hidden" name="id" value="{{ product.id }}" />
        </form>

        <div class="tab_content nopadding" id="tab-config">
            {% set service_partial = "mod_service" ~ product.type ~ "_config.phtml" %}
            {% if admin.system_template_exists({"file":service_partial}) %}
                {% include service_partial with {'product': product} %}
            {% else %}
                <div class="help">
                    <h5>{% trans 'No additional configuration for this product is required' %}</h5>
                </div>
            {% endif %}
            <div class="fix"></div>
        </div>
        
        {% if guest.extension_is_on({"mod":"orderform"}) %}
            <div class="tab_content nopadding mainForm" id="tab-order-form">
            {% include "mod_orderform_builder.phtml" with {'product': product} %}
            </div>
        {% endif %}
        
        <div class="tab_content nopadding mainForm" id="tab-links">
            <fieldset>
            <div class="help">
                <h5>{% trans 'Product links' %}</h5>
            </div>

            <div class="rowElem noborder">
                <label>{% trans 'Product ID' %}</label>
                <div class="formRight">
                    <input type="text" value="{{ product.id }}"/>
                    <div class="fix"></div>
                </div>
            </div>

            <div class="rowElem">
                <label>{% trans 'Order page with ID' %}</label>
                <div class="formRight">
                    <input type="text" value="{{ 'order'|link }}/{{product.id}}"/>
                    <div class="fix"></div>
                </div>
            </div>

            <div class="rowElem">
                <label>{% trans 'Order page with slug' %}</label>
                <div class="formRight">
                    <input type="text" value="{{ 'order'|link }}/{{product.slug}}"/>
                    <div class="fix"></div>
                </div>
            </div>

            </fieldset>
            
            <div class="body aligncenter">
                <a href="{{ 'order'|link }}/{{product.slug}}" title="" class="btn55 mr10" target="_blank"><img src="images/icons/middlenav/preview.png" alt=""><span>View as client</span></a>
            </div>

            <div class="fix"></div>
        </div>

    </div>

</div>
{% endblock %}


{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}

{% block js %}
<script type="text/javascript">
$(function() {
	$(".bHtml").click( function() {
		jAlert(bb.load('{{"filemanager/icons"|alink }}', {rel:"bb-icon"}), '{% trans 'Select icon and click OK' %}');
	});
});
</script>
{% endblock %}
