{extends file="helpers/form/form.tpl"}
{block name="input"}
	{if $input.type == 'gallery'}
		{* start gallery *}
		<div class="text_{$input.name}_multiple_parent">
			{if isset($input.defaults) && !empty($input.defaults)}
				<input type="hidden" name="{$input.name}_delete" class="{$input.name}_delete_class" id="{$input.name}_delete_id"
					value="{* {if isset($input.defaults_str)}{$input.defaults_str}{/if} *}">
				{foreach from=$input.defaults key=$key item=$defaul}
					<div id="{$input.name}_{$key}" class="row {$input.name}_class_parent">
						<div class="col-sm-3">
							<img src="{$input.url}{$defaul}" width="90" height="auto" style="margin:0 0 5px 0;">
						</div>
					<div class="col-sm-3"> 
							<button type="button" class="btn btn-default {$input.name}_cros_class" data-val="{$key}" style="margin:auto 0">
							<i class="icon-trash"></i> Delete</button>
						</div>
					</div>
				{/foreach}
			{else}
				<div class="row {$input.name}_class_parent">
					<div class="col-sm-6">
						<div class="dummyfile input-group">
							<span class="input-group-addon"><i class="icon-file"></i></span>
							<input id="post_gallery_show" type="text" name="show[]" readonly="" class="{$input.name}_class_input">
							<span class="input-group-btn">
								<button id="post_gallery-selectbutton" type="button" name="submitAddAttachments" class="btn btn-default {$input.name}_open_file">
									<i class="icon-folder-open"></i> Ajouter un fichier</button>
								<input id="post_gallery" type="file" class="{$input.name}_class" name="{$input.name}[]" style="display:none;">
							</span>
						</div>
					</div>
					<div class="col-sm-3">
					<div class="input-group">
						<button type="button" class="btn btn-default {$input.name}_cros_class"><i class="icon-trash"></i> Delete</button>
						</div>
					</div>
				</div>


			{/if}
			<div class="col-sm-12 input-group">
				<button type="button" class="btn btn-default {$input.name}_add_class"><i class="process-icon-new"></i> Ajouter une image</button>
			</div>

			<script>
				function adddeleteimages(id) {
					if (typeof id !== 'undefined') {
						if($("#{$input.name}_delete_id").val() == ''){
						$("#{$input.name}_delete_id").val(id);
					} else {
						$("#{$input.name}_delete_id").val($("#{$input.name}_delete_id").val()+','+id);
					}
				}
				}
				$(".{$input.name}_add_class").on("click",function() {
				$(this).before('\
					<div class="row {$input.name}_class_parent">\
						<div class="col-sm-6">\
							<div class="dummyfile input-group">\
								<span class="input-group-addon"><i class="icon-file"></i></span>\
								<input id="post_gallery_show" type="text" name="show[]" readonly="" class="{$input.name}_class_input">\
								<span class="input-group-btn">\
									<button id="post_gallery-selectbutton" type="button" name="submitAddAttachments" class="btn btn-default {$input.name}_open_file">\
										<i class="icon-folder-open"></i> Ajouter un fichier</button>\
									<input id="post_gallery" type="file" class="{$input.name}_class" name="{$input.name}[]" style="display:none;">\
								</span>\
							</div>\
						</div>\
						<div class="col-sm-3">\
						<div class="input-group">\
							<button type="button" class="btn btn-default {$input.name}_cros_class"><i class="icon-trash"></i> Delete</button>\
							</div>\
						</div>\
					</div>');
				
				});

				
				$(".text_{$input.name}_multiple_parent").on("click",".{$input.name}_open_file",function() {
						$(this).next().trigger('click');


					});

					$(".text_{$input.name}_multiple_parent").on("change",".{$input.name}_class",function() {
						var name = $(this).val().split(/[\\/]/);
						$(this).closest(".{$input.name}_class_parent").find(".{$input.name}_class_input").val(name[name.length - 1]);
					});

				$(".text_{$input.name}_multiple_parent").on("click",".{$input.name}_cros_class",function() {
						adddeleteimages($(this).data("val"));
						$(this).closest(".{$input.name}_class_parent").remove();
				});
			</script>
		</div>
		{* End gallery *}
	{elseif $input.type == 'text_multiple'}
		{* start text multiple *}
		<div class="text_{$input.name}_multiple_parent">
			{if isset($input.defaults) && !empty($input.defaults)}
				{foreach $input.defaults AS $defaul}
					<div class="row {$input.name}_class_parent">
						<div class="col-sm-9">
							<input type="text" class="{$input.name}_class" name="{$input.name}[]" value="{$defaul}">
						</div>
						<div class="col-sm-3">
							<button type="button" class="btn btn-default {$input.name}_cros_class">X</button>
						</div>
					</div>
				{/foreach}
			{else}
				<div class="row {$input.name}_class_parent">
					<div class="col-sm-9">
						<input type="text" class="{$input.name}_class" name="{$input.name}[]">
					</div>
				</div>
			{/if}
			<button type="button" class="btn btn-default {$input.name}_add_class"><i class="icon-folder-open"></i> Ajouter un fichier</button>

			
			<script>
				$(".{$input.name}_add_class").on("click",function() {
				$(this).before('<div class="row {$input.name}_class_parent"><div class="col-sm-9"><input type="text" class="{$input.name}_class" name="{$input.name}[]"></div><div class="col-sm-3"><button type="button" class="btn btn-default {$input.name}_cros_class">X</button></div></div>');
				});
				$(".text_{$input.name}_multiple_parent").on("click",".{$input.name}_cros_class",function() {
				// console.log($(this).closest(".{$input.name}_class_parent"));
				$(this).closest(".{$input.name}_class_parent").remove();
				});
			</script>
		</div>
		{* end text multiple *}
	{elseif $input.type == 'select_multiple'}
		<div class="text_{$input.name}_multiple_parent">
			{if isset($input.defaults) && !empty($input.defaults)}
				{foreach $input.defaults AS $defaul}
					<div class="row {$input.name}_class_parent" style="margin-top:5px;">
						<div class="col-sm-9">
							{*$input|print_r*}
							{*<input type="text" class="{$input.name}_class" name="{$input.name}[]">*}
							<select name="{$input.name}[]" class="{$input.name}_class">
								{foreach $input.options.query as $option}
									<option value="{$option.id}" {if $option.id == $defaul} selected="selected" {/if}>{$option.name}
									</option>

								{/foreach}
							</select>
						</div>
						<div class="col-sm-3">
							<button type="button" class="btn btn-default {$input.name}_cros_class" style="margin:auto 0">
							<i class="icon-trash"></i> Delete</button>
						</div>
					</div>
				{/foreach}
			{else}
				<div class="row {$input.name}_class_parent">
					<div class="col-sm-9">
						{*$input|print_r*}
						{*<input type="text" class="{$input.name}_class" name="{$input.name}[]">*}
						<select name="{$input.name}[]" class="{$input.name}_class">
							{foreach $input.options.query as $option}
								<option value="{$option.id}">{$option.name}</option>
							{/foreach}
						</select>
					</div>
				</div>
			{/if}
			<button type="button" class="btn btn-default {$input.name}_add_class"  style="margin-top:5px;"><i class="icon-folder-open"></i> Ajouter un produit</button>
			<script>
				var options = '<div class="row {$input.name}_class_parent" style="margin-top:5px;">';
				options += '<div class="col-sm-9">';
				options += '<select name="{$input.name}[]" class="{$input.name}_class">';
				{foreach $input.options.query as $option}
					options +='<option value="{$option.id}">{$option.name|escape}</option>';
				{/foreach}
				options += '</select></div>';
				options += '<div class="col-sm-3">';
				options += '<button type="button" class="btn btn-default {$input.name}_cros_class"><i class="icon-trash"></i> Delete</button></div></div>';
				
				$(".{$input.name}_add_class").on("click",function() {
					$(this).before(options);
				});
				$(".text_{$input.name}_multiple_parent").on("click",".{$input.name}_cros_class",function() {
					$(this).closest(".{$input.name}_class_parent").remove();
				});
			</script>




		</div>
	{else}
		{$smarty.block.parent}
	{/if}
{/block}