<div class="form-container">

    {$has_at_least_one_combination = false}
    {$default_product_sale_element_id = 0}

    {loop name="product.sales.elements.test" type="product_sale_elements" product=$product_id currency=$edit_currency_id backend_context="1"}
        {loop name="product.combinations" type="attribute_combination" product_sale_elements="$ID"}
            {$has_at_least_one_combination = true}
        {/loop}

        {elseloop rel="product.combinations"}
            {$default_product_sale_element_id = $ID}
        {/elseloop}
    {/loop}

    {if $has_at_least_one_combination == false}
	    {form name="thelia.admin.product_default_sale_element.update"}
	    <form method="POST" action="{url path='/admin/product/default-price/update'}" {form_enctype} class="clearfix">

		    {include
		        file = "includes/inner-form-toolbar.html"
	            hide_submit_buttons = false
	            show_currencies = true

		        page_url  = "{url path='/admin/products/update' product_id=$ID}"
		        close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}"
		    }

	        {* Be sure to get the product ID and current tab, even if the form could not be validated *}
            <input type="hidden" name="product_id" value="{$product_id}" />
	        <input type="hidden" name="current_tab" value="prices" />

	        {form_hidden_fields}

            {form_field field='product_id'}
                <input type="hidden" name="{$name}" value="{$value}" />
            {/form_field}

            {form_field field='product_sale_element_id'}
                <input type="hidden" name="{$name}" value="{$default_product_sale_element_id}" />
            {/form_field}

            {form_field field='isdefault'}
                <input type="hidden" name="{$name}" value="{$value}" />
            {/form_field}

            {form_field field='reference'}
                <input type="hidden" name="{$name}" value="{$value}" />
            {/form_field}

	        {form_field field='success_url'}
	            <input type="hidden" name="{$name}" value="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" />
	        {/form_field}

	        {loop type="currency" name="product-currency" id=$edit_currency_id backend_context="1"}

	            {$currency_symbol = $SYMBOL}
	            {$currency_name = $NAME}

	            {form_field field='currency'}
	                <input type="hidden" name="{$name}" value="{$ID}" />
	            {/form_field}

	            {$current_currency_is_default = $IS_DEFAULT}
	        {/loop}


            {if $form_error}
            <div class="row">
                <div class="col-md-12">
                    <div class="alert alert-danger">{$form_error_message}</div>
                </div>
            </div>
            {/if}

			<div class="row">
			    <div class="col-md-4">
			        {form_field field='tax_rule'}
			            <div class="form-group {if $error}has-error{/if}">
			                <label for="tax_rule_field" class="control-label">{$label} : </label>
			                <div class="form-group">
			                    <select id="tax_rule_field" required="required" name="{$name}" class="form-control">
			                        <option value="">{intl l="Select a tax tule"}</option>
			                        {loop name="tax" type="tax-rule" backend_context="1"}
			                            <option value="{$ID}" {if $ID == $TAX_RULE_ID}selected="selected"{/if}>{$TITLE}</option>
			                        {/loop}
			                    </select>
			                </div>
			            </div>
			        {/form_field}
			    </div>
			</div>

	        <p class="title title-without-tabs">{intl l='Pricing'}</p>

	        <p>{intl l="The default pricing is used when no combination is defined."}</p>

		    <div class="row">

		        {* -- Pricing ------------------------------------------------------- *}

		        <div class="col-md-4">
	                <div class="well well-sm">
			            <p class="title title-without-tabs">{intl l='Pricing'}</p>

			              <p></p> <!-- LAME !!! FIXME -->

	                      {form_field field='use_exchange_rate'}
	                          {if $current_currency_is_default}
	                             <input type="hidden" name="{$name}" value="0">
	                             {$show_pricing_fields = true}
	                          {else}
			                      <div class="form-group {if $error}has-error{/if}">
			                          <div class="checkbox">
			                              <label>
			                                  <input type="checkbox" data-pse-id="{$default_product_sale_element_id}" class="use_exchange_rate_box" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
			                                  {$label}
			                              </label>
			                          </div>
			                      </div>
			                      {$show_pricing_fields = ($value == 0)}
			                  {/if}
	                      {/form_field}

			              {form_field field='price'}
			                  <div class="form-group {if $error}has-error{/if}">
			                      <label for="price_without_tax" class="control-label">{$label} : </label>

			                         <div class="input-group">
			                             <input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="price-without-tax" data-rel-price="price_with_tax" type="text" id="price_without_tax" required="required" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Price excl. taxes'}">
			                             <span class="input-group-addon">{$currency_symbol}</span>
			                         </div>
			                  </div>
			              {/form_field}

                          {form_field field='price_with_tax'}
			                  <div class="form-group">
			                      <label for="price_with_tax" class="control-label">{intl l="Product price including taxes"} : </label>
			                      <div class="input-group">
			                          <input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="price-with-tax" data-rel-price="price_without_tax" type="text" id="price_with_tax" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$value}" placeholder="{intl l='Price incl. taxes'}">
			                          <span class="input-group-addon">{$currency_symbol}</span>
			                      </div>
			                  </div>
                          {/form_field}

			              {hook name="product.details-pricing-form" location="product_details_pricing_form" }
			          </div>
		        </div>


                 {* -- Détails -------------------------------------------------- *}

                 <div class="col-md-4">
                     <div class="well well-sm">
                        <p class="title title-without-tabs">{intl l='Stock'}</p>

						{form_field field='ean_code'}
						   <div class="form-group {if $error}has-error{/if}">
						       <label for="{$label_attr.for}" class="control-label">{$label} : </label>

						       <div class="form-group">
						           <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product EAN Code'}">
						       </div>
						   </div>
						{/form_field}

                         {form_field field='weight'}
                            <div class="form-group {if $error}has-error{/if}">
                                <label for="{$label_attr.for}" class="control-label">{$label} : </label>

                                <div class="input-group">
                                    <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product weight'}">
                                    <span class="input-group-addon">{intl l="Kg"}</span>
                                </div>
                            </div>
                         {/form_field}

                         {form_field field='quantity'}
                            <div class="form-group {if $error}has-error{/if}">
                                <label for="{$label_attr.for}" class="control-label">{$label} : </label>

                                <div class="form-group">
                                    <input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Current quantity'}">
                                </div>
                            </div>
                         {/form_field}

                         {hook name="product.details-details-form" location="product_details_details_form" }
                    </div>
                </div>


		        {* -- Promotion ------------------------------------------------- *}

		        <div class="col-md-4">
	                <div class="well well-sm">
			            <p class="title title-without-tabs">{intl l='Promotion'}</p>

			            {form_field field='sale_price'}
			                <div class="form-group {if $error}has-error{/if}">
			                    <label for="sale_price_without_tax" class="control-label">{$label} : </label>

			                    <div class="input-group">
			                        <input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="sale-price-without-tax" data-rel-price="sale_price_with_tax" type="text" id="sale_price_without_tax" required="required" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
			                        <span class="input-group-addon">{$currency_symbol}</span>
			                    </div>
			               </div>
			            {/form_field}

                        {form_field field='sale_price_with_tax'}
                        <div class="form-group">
                            <label for="sale_price_with_tax" class="control-label">{$label} : </label>
                            <div class="input-group">
                                <input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="sale-price-with-tax" data-rel-price="sale_price_without_tax" type="text" id="sale_price_with_tax" name="sale_price_with_tax" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Sale price incl. taxes'}">
                                <span class="input-group-addon">{$currency_symbol}</span>
                            </div>
                        </div>
                        {/form_field}

						{form_field field='onsale'}
						<div class="form-group {if $error}has-error{/if}">
						    <div class="checkbox">
						        <label>
						            <input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
						            {$label}
						        </label>
						    </div>
						</div>
						{/form_field}

			            {form_field field='isnew'}
			            <div class="form-group {if $error}has-error{/if}">
			                <div class="checkbox">
			                    <label>
			                        <input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
			                        {$label}
			                    </label>
			                </div>
			            </div>
			            {/form_field}

			            {hook name="product.details-promotion-form" location="product_details_promotion_form" }
			        </div>
                </div>
	        </div>
        </form>
	    {/form}
    {/if}

    {* -- Attribute combinations -------------------------------------------- *}

    {if $has_at_least_one_combination}

       {form name="thelia.admin.product_sale_element.update"}
       <form method="POST" action="{url path='/admin/product/combinations/update'}" {form_enctype}>
            <div class="row">
                <div class="col-md-12">

					{include
					    file = "includes/inner-form-toolbar.html"
					    hide_submit_buttons = false
					    show_currencies = true
					    page_url  = "{url path='/admin/products/update' product_id=$ID}"
					    close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}"
					}

					{* Be sure to get the product ID and current tab, even if the form could not be validated *}
					<input type="hidden" name="product_id" value="{$product_id}" />
					<input type="hidden" name="current_tab" value="prices" />

					{form_hidden_fields}

					{form_field field='product_id'}
					    <input type="hidden" name="{$name}" value="{$value}" />
					{/form_field}

					{form_field field='success_url'}
					    <input type="hidden" name="{$name}" value="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" />
					{/form_field}

	                {if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}

                    {loop type="currency" name="get-currency-symbol" id=$edit_currency_id backend_context="1"}
                        {$currency_symbol = $SYMBOL}
                        {$current_currency_is_default = $IS_DEFAULT}

                        {form_field field='currency'}
                            <input type="hidden" name="{$name}" value="{$ID}" />
                        {/form_field}
                    {/loop}

					<div class="row">
					    <div class="col-md-4">
					        {form_field field='tax_rule'}
					            <div class="form-group {if $error}has-error{/if}">
					                <label for="tax_rule_field" class="control-label">{$label} : </label>
					                <div class="form-group">
					                   <select id="tax_rule_field" required="required" name="{$name}" class="form-control">
					                        <option value="">{intl l="Select a tax tule"}</option>
					                        {loop name="tax" type="tax-rule" backend_context="1"}
					                            <option value="{$ID}" {if $ID == $TAX_RULE_ID}selected="selected"{/if}>{$TITLE}</option>
					                        {/loop}
					                    </select>
					                </div>
					            </div>
					        {/form_field}
					    </div>
					    <div class="col-md-4">
                          {form_field field='use_exchange_rate'}
                              {if $current_currency_is_default}
                                 <input type="hidden" name="{$name}" value="0">
                                 {$show_pricing_fields = true}
                              {else}
                                  <div class="form-group {if $error}has-error{/if}">
                                      <label>&nbsp;</label>
                                      <div class="checkbox">
                                          <label>
                                              <input type="checkbox" class="use_exchange_rate_box" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
                                              {$label}
                                          </label>
                                      </div>
                                  </div>
                                  {$show_pricing_fields = ($value == 0)}
                              {/if}
                          {/form_field}
					    </div>
					</div>

	                {hook name="product.before-combinations" location="product_before_combinations" }

					<table class="table table-striped table-condensed table-responsive" id="combinations_list">
					    <caption>
					        {intl l='Attribute Combinations'}

					        {hook name="product.combinations-list-caption" location="product_combinations_list_caption" }

                            {include file='renderer/buttons.html' btn_group=false buttons=[
                                [
                                    'type' => 'create',
                                    'id' => 'open_combination_builder',
                                    'class' => 'action-btn',
                                    'title' => {intl l='Quickly create combinations using the combination builder'},
                                    'text' => {intl l='Combination builder'},
                                    'href' => '#combination_builder_dialog',
                                    'auth' => ['resource' => 'admin.product', 'access' => 'UPDATE'],
                                    'data' => [
                                        'toggle' => 'modal'
                                    ],
                                    'with_text' => true
                                ],
                                [
                                    'type' => 'create',
                                    'class' => 'action-btn',
                                    'title' => {intl l='Add a new combination'},
                                    'href' => '#combination_creation_dialog',
                                    'auth' => ['resource' => 'admin.product', 'access' => 'UPDATE'],
                                    'data' => [
                                        'toggle' => 'modal'
                                    ]
                                ]
                            ]}
					    </caption>

					    <thead>
					        <tr>
                                <th class="col-sm-2 text-center">{intl l='Reference'}</th>
                                <th class="col-sm-2 text-center">{intl l='EAN Code'}</th>
                                <th class="col-sm-1 text-center">{intl l='Stock'}</th>
								<th class="col-sm-1 text-center"><small>{intl l='Price (%currency)<br />w/o taxes' currency={$currency_symbol}}</small></th>
								<th class="col-sm-1 text-center"><small>{intl l='Price (%currency)<br />w/ taxes' currency={$currency_symbol}}</small></th>
								<th class="col-sm-1 text-center"><small>{intl l='Weight<br />(Kg)'}</small></th>
                                <th class="text-center"><small>{intl l='Default'}</small></th>
                                <th class="text-center"><small>{intl l='Sale'}</small></th>
                                <th class="text-center"><small>{intl l='New'}</small></th>
								<th class="col-sm-1 text-center"><small>{intl l='Sale price (%currency)<br />w/o taxes' currency={$currency_symbol}}</small></th>
								<th class="col-sm-1 text-center"><small>{intl l='Sale price (%currency)<br />w/ taxes' currency={$currency_symbol}}</small></th>
					        </tr>
					    </thead>

					    <tbody>
	                        {* Get number of PSE defined, assume the form have the same number of values for each fields *}

	                        {form_field field='product_sale_element_id' value_key=0}
	                           {$pse_count = $total_value_count}
	                        {/form_field}

	                        {for $idx = 0 to $total_value_count-1}
	                        <tr>
                                <td colspan="10">

                                    {form_field field='product_sale_element_id' value_key=$idx}
                                        <input type="hidden" class="pse_id_field" name="{$name}" value="{$value}" />
                                        {$current_pse_id = $value}
                                    {/form_field}

                                    <div class="btn-group">
                                        <a class="btn btn-default btn-xs pse-assoc-image pse-assoc-image-document" data-target="#pse-assoc-image-document-modal" data-id="{$value}" title="{intl l="Associate images"}">
                                            <span class="glyphicon glyphicon-picture"></span>
                                        </a>
                                        <a class="btn btn-default btn-xs pse-assoc-document pse-assoc-image-document" data-target="#pse-assoc-image-document-modal" data-id="{$value}" title="{intl l="Associate documents"}">
                                            <span class="glyphicon glyphicon-file"></span>
                                        </a>
                                        {if $VIRTUAL}
                                        <a class="btn btn-success btn-xs pse-assoc-virtual pse-assoc-image-document" data-type="virtual" data-target="#pse-assoc-image-document-modal" data-id="{$value}" title="{intl l="Associate downloadable file"}">
                                            <span class="glyphicon glyphicon-download"></span>
                                        </a>
                                        {/if}
                                    </div>

                                    <a class="btn btn-default btn-xs combination-delete" title="{intl l='Delete this combination'}"  href="#combination_delete_dialog" data-id="{$current_pse_id}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>

									{assign var='combination_list' value=array()}
									{loop name="product.sales.elements.combinations" type="attribute_combination" product_sale_elements=$current_pse_id backend_context="1" order="manual"}
										{$combination_list[$ATTRIBUTE_TITLE][] = $ATTRIBUTE_AVAILABILITY_TITLE}
									{/loop}

									{format_array_2d values=$combination_list}
								</td>

                                <td class="text-right">ID: {$current_pse_id}</td>
                            </tr>

                            <tr>
                                {form_field field='reference' value_key=$idx}
                                <td {if $error}class="has-error"{/if}><input class="form-control input-sm" type="text" name="{$name}" value="{$value}" /></td>
                                {/form_field}

                                {form_field field='ean_code' value_key=$idx}
                                <td {if $error}class="has-error"{/if}><input class="form-control input-sm" type="text" name="{$name}" value="{$value}" /></td>
                                {/form_field}

                                {form_field field='quantity' value_key=$idx}
                                <td {if $error}class="has-error"{/if}>
                                    <input class="form-control input-sm text-right" required type="text" name="{$name}" value="{$value}" />
                                </td>
                                {/form_field}

                                {form_field field='price' value_key=$idx}
                                <td {if $error}class="has-error"{/if}><input {if !$show_pricing_fields}readonly{/if} required data-price-type="price-without-tax" data-rel-price="price_with_tax_{$idx}" id="price_without_tax_{$idx}" class="price_field automatic_price_field form-control text-right input-sm" required type="text" name="{$name}" value="{$value}" /></td>
                                {/form_field}

                                {form_field field='price_with_tax' value_key=$idx}
                                <td {if $error}class="has-error"{/if}><input {if !$show_pricing_fields}readonly{/if} data-price-type="price-with-tax" data-rel-price="price_without_tax_{$idx}" id="price_with_tax_{$idx}" class="price_field automatic_price_field form-control text-right input-sm" type="text" name="{$name}" value="{$value}" /></td>
                                {/form_field}

                                {form_field field='weight' value_key=$idx}
                                <td {if $error}class="has-error"{/if}><input required class="form-control text-right input-sm" type="text" name="{$name}" value="{$value}" /></td>
                                {/form_field}


                                {form_field field='default_pse'}
                                <td class="{if $error}has-error {/if}text-center">
                                    <input class="input-sm" type="radio" name="{$name}" value="{$current_pse_id}" {if $value == $current_pse_id}checked="checked"{/if}/>
                                </td>
                                {/form_field}

                                {form_field field='onsale' value_key=$idx}
                                <td class="{if $error}has-error {/if}text-center">
                                    <input class="input-sm" type="checkbox" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}/>
                                </td>
                                {/form_field}

                                {form_field field='isnew' value_key=$idx}
                                <td class="{if $error}has-error {/if}text-center">
                                     <input class="input-sm" type="checkbox" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}/>
                                </td>
                                {/form_field}

                                {form_field field='sale_price' value_key=$idx}
                                <td {if $error}class="has-error"{/if}>
                                    <input {if !$show_pricing_fields}readonly{/if} required data-price-type="sale-price-without-tax" data-rel-price="sale_price_with_tax_{$idx}" id="sale_price_without_tax_{$idx}" class="price_field automatic_price_field form-control text-right input-sm" type="text" name="{$name}" value="{$value}"  />
                                </td>
                                {/form_field}

                                {form_field field='sale_price_with_tax' value_key=$idx}
                                <td {if $error}class="has-error"{/if}>
                                    <input {if !$show_pricing_fields}readonly{/if} data-price-type="sale-price-with-tax" data-rel-price="sale_price_without_tax_{$idx}" id="sale_price_with_tax_{$idx}" class="price_field automatic_price_field form-control text-right input-sm" type="text" name="{$name}" value="{$value}"  />
                                </td>
                                {/form_field}
                            </tr>

                            {hook name="product.combinations-row" pse=$current_pse_id idx=$idx}

	                        {/for}
					    </tbody>
					</table>

	                {hook name="product.after-combinations" location="product_after_combinations" }


                    {include
                    file = "includes/inner-form-toolbar.html"
                    hide_submit_buttons = false
                    hide_flags = true
                    page_url  = "{url path='/admin/products/update' product_id=$ID}"
                    close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}"
                    }

	            </div>
	        </div>

        </form>
        {/form}
    {/if}

    {if $has_at_least_one_combination == false}
       <div class="row">
           <div class="col-md-12">
		        <p class="title title-without-tabs">{intl l='Attribute Combinations'}</p>

		        <div class="alert alert-info">
			        <p>{intl
			             l='This product has no combination. The default price is used. <a data-toggle="modal" href="%url">Click here to create a new combination</a>.'
			             url='#combination_creation_dialog'
			        }</p>
			        <p>
			          {intl
			             l='You may also quickly create combinations from products attributes using the  <a href="%url" data-toggle="modal">Combination Builder</a>.'
			             url='#combination_builder_dialog'
			          }
			        </p>
		        </div>
		    </div>
		</div>
    {/if}
</div>

{* PSE / Image-Document combination modal *}
<div id="pse-modal-container">
    <div class="modal fade" id="pse-assoc-image-document-modal" tabindex="-1" role="dialog" aria-labelledby="associate_images_documents_label" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="associate_images_documents_label"></h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

{* -- Adding a new combination ------------------------------------------------- *}

{* Capture the dialog body, to pass it to the generic dialog *}

{capture "combination_creation_dialog"}

    <input type="hidden" name="product_id" value="{$product_id}" />
    <input type="hidden" name="current_tab" value="prices" />

	<div class="form-group">
	   <label class="control-label">{intl l="Attribute"} : </label>
	   <select  name="attribute_id" id="attribute_id" class="form-control">
	       <option value="">{intl l='Select an attribute...'}</option>
	       {loop name="product-attributes" type="attribute" order="manual" product=$product_id backend_context="1" lang=$edit_language_id}
	           <option value="{$ID}">{$TITLE}</option>
	       {/loop}
	   </select>
	   <span class="help-block">{intl l='Select an attribute and click (+) to view available values'}</span>
	</div>


	<div id="attribute_value_selector" class="hide">
	    <div class="input-group">
	        {* <label class="control-label">{intl l="Attribute values"} : </label> *}

	        <select name="attribute_value_id" id="attribute_value_id" class="form-control">
	            <option value="">{intl l='Select an attribute value...'}</option>
	        </select>

	        <span class="input-group-btn" id="add_attr_value_button">
	           <button class="btn btn-primary action-btn add-value-to-combination" type="button"><span class="glyphicon glyphicon-plus-sign"></span></button>
	        </span>
	    </div>

	    <span class="help-block">{intl l='Select a value click (+) to add it to the combination'}</span>
	</div>

	<div id="attribute_value_selector_empty" class="hide">
	    <div class="alert alert-info">
	       {intl l="No available value for this attribute"}
	   </div>
	</div>

	<div class="form-group">
	    <div class="alert alert-danger hide" id="combination_attributes_error"></div>

	    <select required="required" multiple="multiple" size="5" name="combination_attributes[]" id="combination_attributes" class="form-control">
	    </select>

	    <div class="help-block">
	        {intl l='To remove a value from the combination, select it and click "remove"'}

	        <div class="pull-right">
	            <button class="btn btn-info btn-xs remove-value-from-combination" type="button">
	                {intl l="Remove selected values"} <span class="glyphicon glyphicon-minus-sign"></span>
	            </button>
	        </div>
	    </div>
	</div>

{/capture}

{include
    file = "includes/generic-create-dialog.html"

    dialog_id    = "combination_creation_dialog"
    dialog_title = {intl l="Create a new combination"}
    dialog_body  = {$smarty.capture.combination_creation_dialog nofilter}

    dialog_ok_label     = {intl l="Create this combination"}

    form_action        = {url path='/admin/product/combination/add'}
    form_enctype       = ''
    form_error_message = ''

    ok_button_id = "combination_creation_dialog_ok"
}


{* -- Delete combination confirmation dialog ----------------------------------- *}

{capture "combination_delete_dialog"}

    <input type="hidden" name="product_id" value="{$product_id}" />
    <input type="hidden" name="current_tab" value="prices" />

    <input type="hidden" name="product_sale_element_id" id="combination_delete_id" value="" />

    {hook name="product.combination-delete-form" location="product_combination_delete_form" }

{/capture}

{include
    file = "includes/generic-confirm-dialog.html"

    dialog_id       = "combination_delete_dialog"
    dialog_title    = {intl l="Delete a combination"}
    dialog_message  = {intl l="Do you really want to delete this combination ?"}

    form_action     = {url path='/admin/product/combination/delete'}
    form_content    = {$smarty.capture.combination_delete_dialog nofilter}
}

{* -- Combination builder dialog -------------------------------------------- *}

{* Capture the dialog body, to pass it to the generic dialog *}

{form name="thelia.admin.product_combination.build"}

{capture "combination_builder_dialog"}

    {* Be sure to get the product ID and current tab, even if the form could not be validated *}
    <input type="hidden" name="product_id" value="{$product_id}" />
    <input type="hidden" name="current_tab" value="prices" />

    {form_hidden_fields}

    {form_field field='product_id'}
        <input type="hidden" name="{$name}" value="{$product_id}" />
    {/form_field}

    {if $form_error}<div class="alert alert-danger" id="combination_builder_dialog_error">{$form_error_message}</div>{/if}

    {loop type="currency" name="get-currency-symbol" id=$edit_currency_id backend_context="1"}
        {$currency_symbol = $SYMBOL}

        {form_field field='currency'}
            <input type="hidden" name="{$name}" value="{$ID}" />
        {/form_field}
    {/loop}

    {form_field field='success_url'}
         <input type="hidden" name="{$name}" value="{url path='/admin/products/update' product_id=$product_id current_tab='prices'}" />
    {/form_field}

    <div class="alert alert-info">
        {intl l='Select attribute values to combine. You may enter a default value for some of the fields of the generated combinations.'}
    </div>

    <div class="row">
        <div class="col-md-6">
		    <div class="scrollable">
		        <ul class="list-unstyled">
		        {$index = 0}
		        {loop name="product-attributes" type="attribute" order="manual" product=$product_id backend_context="1" lang=$edit_language_id}
		            {ifloop rel="product-attributes-av"}
		            <li>
		                <strong>{$TITLE}</strong>
		                <ul class="list-unstyled">
		                {loop name="product-attributes-av" type="attribute_availability" attribute=$ID order="manual" backend_context="1" lang=$edit_language_id}
		                    <li>
			                    <div class="checkbox">
			                        <label>
			                            {form_field field='attribute_av' value_key=$index}
			                            <input data-attribute-id="{$ATTRIBUTE_ID}" class="attribute_av_value" type="checkbox" name="{$name}" value="{$ATTRIBUTE_ID}:{$ID}" {if $value == "$ATTRIBUTE_ID:$ID"}checked="checked"{/if}>{$TITLE}
			                            {/form_field}
			                        </label>
			                    </div>
		                    </li>
		                    {$index = $index + 1}
		                {/loop}
		                </ul>
		            </li>
		            {/ifloop}
		        {/loop}
		        </ul>
		    </div>
		</div>
        {loop type="product_sale_elements" name="product_sale_elements_combination_form" product=$product_id default="yes" limit=1 backend_context=1}
		<div class="col-md-6">
         {form_field field='price'}
             <div class="form-group {if $error}has-error{/if}">
                 <label for="price-without-tax-modal" class="control-label">{$label} : </label>

                 <div class="input-group">
                     <input type="text" id="price-without-tax-modal" data-price-type="price-without-tax-modal" data-rel-price="price-with-tax-modal" name="{$name}" class="price_field automatic_price_field form-control" value="{if $value}{$value}{else}{$PRICE}{/if}" title="{$label}" placeholder="{intl l='Price excl. taxes'}">
                     <span class="input-group-addon">{$currency_symbol}</span>
                 </div>
             </div>
         {/form_field}

         <div class="form-group">
              <label for="price-with-tax-modal" class="control-label">{intl l="Product price including taxes"} : </label>
              <div class="input-group">
                  <input type="text" id="price-with-tax-modal" data-price-type="price-with-tax-modal" data-rel-price="price-without-tax-modal" class="price_field automatic_price_field form-control" value="{if $value}{$value}{else}{$PRICE}{/if}" title="{intl l='Product price including taxes'}" placeholder="{intl l='Price incl. taxes'}">
                  <span class="input-group-addon">{$currency_symbol}</span>
              </div>
         </div>

         {form_field field='reference'}
            <div class="form-group {if $error}has-error{/if}">
                <label for="{$label_attr.for}" class="control-label">{$label} : </label>

                <div class="form-group">
                    <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{if $value}{$value}{else}{$REF}{/if}" title="{$label}" placeholder="{intl l='Combination reference'}">
                </div>
            </div>
         {/form_field}

         {form_field field='ean_code'}
            <div class="form-group {if $error}has-error{/if}">
                <label for="{$label_attr.for}" class="control-label">{$label} : </label>
                <div class="form-group">
                    <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{if $value}{$value}{else}{$EAN_CODE}{/if}" title="{$label}" placeholder="{intl l='Combination EAN Code'}">
                </div>
            </div>
         {/form_field}

         <div class="row">
            <div class="col-md-6">
	            {form_field field='weight'}
	            <div class="form-group {if $error}has-error{/if}">
	                <label for="{$label_attr.for}" class="control-label">{$label} : </label>

	                <div class="input-group">
	                    <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{if $value}{$value}{else}{$WEIGHT}{/if}" title="{$label}" placeholder="{intl l='Product weight'}">
	                    <span class="input-group-addon">{intl l="Kg"}</span>
	                </div>
	            </div>
	            {/form_field}
	         </div>

	          <div class="col-md-6">
	          {form_field field='quantity'}
	             <div class="form-group {if $error}has-error{/if}">
	                 <label for="{$label_attr.for}" class="control-label">{intl l='Stock'} : </label>

	                 <div class="form-group">
	                     <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{if $value}{$value}{else}{$QUANTITY}{/if}" title="{$label}" placeholder="{intl l='Current quantity'}">
	                 </div>
	             </div>
	          {/form_field}
	          </div>
	     </div>

         {form_field field='sale_price'}
             <div class="form-group {if $error}has-error{/if}">
                 <label for="sale_price_without_tax" class="control-label">{$label} : </label>
                 <div class="input-group">
                     <input type="text" id="sale_price_without_tax" name="{$name}" class="price_field automatic_price_field form-control" value="{if $value}{$value}{else}{$PROMO_PRICE}{/if}" title="{$label}" placeholder="{intl l='Product price'}">
                     <span class="input-group-addon">{$currency_symbol}</span>
                 </div>
            </div>
         {/form_field}

		 {form_field field='onsale'}
	     <div class="form-group {if $error}has-error{/if}">
	        <div class="checkbox">
	            <label>
	                <input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $IS_PROMO}checked{/if}>
	                {$label}
	            </label>
	        </div>
	     </div>
	     {/form_field}

         {form_field field='isnew'}
         <div class="form-group {if $error}has-error{/if}">
             <div class="checkbox">
                 <label>
                     <input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $IS_NEW}checked{/if}>
                     {$label}
                 </label>
             </div>
         </div>
         {/form_field}
         {/loop}


         <div class="well well-sm" style="margin-bottom: 0"><b>{intl l='<span id="number_of_generated_combinations">0</span> combinations'}</b></div>
    </div>
</div>

{/capture}

{include
    file = "includes/generic-create-dialog.html"

    dialog_id    = "combination_builder_dialog"
    dialog_title = {intl l="Create combinations"}
    dialog_body  = {$smarty.capture.combination_builder_dialog nofilter}

    dialog_ok_label     = {intl l="Create combinations"}

    form_action        = {url path='/admin/product/combination/build'}
    form_enctype       = {form_enctype}
    form_error_message = ''

    ok_button_id = "combination_builder_dialog_ok"
}

{/form}
