@extends('layouts.default')

@section('title')
@parent
Добавление продукта для проекта {{ $project->name }}
@stop

@section('js')
	<script>
		$('#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@store', $project->id))) }}
		<h2>Добавление продукта для проекта {{ $project->name }}</h2>

		@if(count($suppliers))
		<div class="form-group">
			{{ Form::label( 'supplier_id', 'Поставщик:', array('class' => 'control-label') ) }}
			{{ Form::select('supplier_id', $suppliers, null, array('class' => 'form-control', 'id' => 'supplier_id')) }}
		</div>
		@endif

		<div class="form-group {{ ($errors->has('name')) ? 'has-error' : '' }}">
			{{ Form::label( 'name', 'Название:', array('class' => 'control-label') ) }}
			{{ Form::text('name', null, 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', null, 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', null, 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', null, array('class' => 'form-control')) }}
			{{ ($errors->has('weight') ? $errors->first('weight') : '') }}
		</div>

		<div class="action-container">
			<div class="action-item well hide">
				<div class="form-group {{ ($errors->has('action_name1')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name1', 'Название акции №1:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name1', null, 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', null, 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 hide">
				<div class="form-group {{ ($errors->has('action_name2')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name2', 'Название акции №2:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name2', null, 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', null, 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 hide">
				<div class="form-group {{ ($errors->has('action_name3')) ? 'has-error' : '' }}">
					{{ Form::label( 'action_name3', 'Название акции №3:', array('class' => 'control-label') ) }}
					{{ Form::text('action_name3', null, 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', null, 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::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