@extends('layouts.default')

@section('title')
@parent
Редактировать информацию о продукте
@stop

@section('js')
	<script>
		if($('.action-container .action-item.hide').length) {
			$('#action-add-btn').removeClass('hide');
		}
		else {
			$('#action-add-btn').addClass('hide');
		}
		$('#action-add-btn').unbind('click').on('click', function(){
			$('.action-container .action-item.hide:first').removeClass('hide');
			if(!$('.action-container .action-item.hide').length) {
				$('#action-add-btn').addClass('hide');
			}
			return false;
		});
		$('.action-delete-btn ').unbind('click').on('click', function(){
			$(this).parent().addClass('hide');
			$(this).parent().find('input').val('');
			$('#action-add-btn').removeClass('hide');
			return false;
		});
	</script>
@stop

@section('content')
<div class="row">
	<div class="col-md-6 col-md-offset-3">
		{{ Form::open(array('action' => array('ProductsController@update', $project->id, $product->id), 'method' => 'put')) }}
		<h2>Редактировать информацию о продукте</h2>

		@if(count($suppliers))
		<div class="form-group">
			{{ Form::label( 'supplier_id', 'Поставщик:', array('class' => 'control-label') ) }}
			{{ Form::select('supplier_id', $suppliers, $product->supplier_id, array('class' => 'form-control', 'id' => 'supplier_id')) }}
		</div>
		@endif

		<div class="form-group {{ ($errors->has('article')) ? 'has-error' : '' }}">
			{{ Form::label( 'article', 'Артикул:', array('class' => 'control-label') ) }}
			{{ Form::text('article', $product->article, array('class' => 'form-control', 'autofocus')) }}
			{{ ($errors->has('article') ? $errors->first('article') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('name')) ? 'has-error' : '' }}">
			{{ Form::label( 'name', 'Название:', array('class' => 'control-label') ) }}
			{{ Form::text('name', $product->name, array('class' => 'form-control', 'autofocus')) }}
			{{ ($errors->has('name') ? $errors->first('name') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('price_purchase')) ? 'has-error' : '' }}">
			{{ Form::label( 'price_purchase', 'Закупочная цена:', array('class' => 'control-label') ) }}
			{{ Form::text('price_purchase', $product->price_purchase, array('class' => 'form-control')) }}
			{{ ($errors->has('price_purchase') ? $errors->first('price_purchase') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('price')) ? 'has-error' : '' }}">
			{{ Form::label( 'price', 'Цена продажи:', array('class' => 'control-label') ) }}
			{{ Form::text('price', $product->price, array('class' => 'form-control')) }}
			{{ ($errors->has('price') ? $errors->first('price') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('weight')) ? 'has-error' : '' }}">
			{{ Form::label( 'weight', 'Вес в граммах:', array('class' => 'control-label') ) }}
			{{ Form::text('weight', $product->weight, array('class' => 'form-control')) }}
			{{ ($errors->has('weight') ? $errors->first('weight') : '') }}
		</div>

		<div class="action-container">
			<div class="action-item well @if(!$product->action_name1 && !$product->action_price1) hide @endif">
				<div class="form-group {{ ($errors->has('action_name1')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name1', 'Название акции №1:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name1', $product->action_name1, array('class' => 'form-control')) }}
					{{ ($errors->has('action_name1') ? $errors->first('action_name1') : '') }}
				</div>

				<div class="form-group {{ ($errors->has('action_price1')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_price1', 'Цена по акции №1:', array('class' => 'control-label') ) }}
					{{ Form::text('action_price1', $product->action_price1, array('class' => 'form-control')) }}
					{{ ($errors->has('action_price1') ? $errors->first('action_price1') : '') }}
				</div>

				<button class="action-delete-btn btn btn-xs btn-danger pull-right">Удалить акцию</button>
				<div class="clearfix"></div>
			</div>
			<div class="action-item well @if(!$product->action_name2 && !$product->action_price2) hide @endif">
				<div class="form-group {{ ($errors->has('action_name2')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name2', 'Название акции №2:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name2', $product->action_name2, array('class' => 'form-control')) }}
					{{ ($errors->has('action_name2') ? $errors->first('action_name2') : '') }}
				</div>

				<div class="form-group {{ ($errors->has('action_price2')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_price2', 'Цена по акции №2:', array('class' => 'control-label') ) }}
					{{ Form::text('action_price2', $product->action_price2, array('class' => 'form-control')) }}
					{{ ($errors->has('action_price2') ? $errors->first('action_price2') : '') }}
				</div>

				<button class="action-delete-btn btn btn-xs btn-danger pull-right">Удалить акцию</button>
				<div class="clearfix"></div>
			</div>
			<div class="action-item well @if(!$product->action_name3 && !$product->action_price3) hide @endif">
				<div class="form-group {{ ($errors->has('action_name3')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name3', 'Название акции №3:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name3', $product->action_name3, array('class' => 'form-control')) }}
					{{ ($errors->has('action_name3') ? $errors->first('action_name3') : '') }}
				</div>

				<div class="form-group {{ ($errors->has('action_price3')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_price3', 'Цена по акции №3:', array('class' => 'control-label') ) }}
					{{ Form::text('action_price3', $product->action_price3, array('class' => 'form-control')) }}
					{{ ($errors->has('action_price3') ? $errors->first('action_price3') : '') }}
				</div>

				<button class="action-delete-btn btn btn-xs btn-danger pull-right">Удалить акцию</button>
				<div class="clearfix"></div>
			</div>
			<button id="action-add-btn" class="btn btn-sm btn-info pull-right">Добавить акцию</button>
			<br/><br/>
		</div>

		{{ Form::hidden('id', $product->id) }}
		{{ Form::submit('Сохранить изменения', array('class' => 'btn btn-primary')) }}
		{{ Form::button('Отмена', array('class' => 'btn btn-default', 'onclick'=>'location="'.URL::to('projects').'/'.$project->id.'/products"')) }}

    {{ Form::close() }}
	</div>
</div>

@stop