@extends('layouts.app')
@php
    $labelWidth = 5;
    $inputWidth = 7;
@endphp
@section('content')
    <div class="container">
        <div class="row">
            <div class="{{ $containerSize }}">
                @include('layouts.alerts')

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>@lang($heading) {{ $customHeading?$singular:'' }}</strong>
                        <div class="pull-right hidden-xs">
                            @lang('Last edit at') {{ $result->updated_at }}
                        </div>
                    </div>
                    {!! Form::open(['route' => [$router . '.update', 'id' => $objectId, 'classId' => $classId], 'method' => 'put', 'class' => 'form-horizontal', 'role' => 'form']) !!}
                    <div class="panel-body">

                        <div class="form-group">
                            {!! Form::label('id', Lang::getFromJson('id'), ['class' => "col-md-$labelWidth control-label"]) !!}
                            <div class="col-md-{{$inputWidth}}">
                                {!! Form::text('id', $result->id, [
                                    'class' => 'form-control',
                                    'disabled'
                                ]) !!}
                            </div>
                        </div>
                        @if(count($result->possible_states) > 1)
                            <div class="form-group">
                                {!! Form::label('state_id', Lang::getFromJson('State'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! Form::select('state_id', $result->possible_states, Input::old('state_id'), [
                                        'class' => 'form-control',
                                        'required' => 'required'
                                    ]) !!}
                                </div>
                            </div>
                        @endif
                        {!! \App\Http\ViewHelpers\HtmlAggregator::entityParametersToHtml($result->class, $labelWidth, $inputWidth, $result) !!}
                        @if($location !== null)
                            <div class="form-group">
                                {!! Form::label('location', Lang::getFromJson('Location Name'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! $location /* viewFeeder->autoComplete */ !!}
                                </div>
                            </div>
                        @endif
                        @if($manufacturer !== null)
                            <div class="form-group">
                                {!! Form::label('manufacturer', Lang::getFromJson('Manufacturer Name'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! $manufacturer /* viewFeeder->autoComplete */ !!}
                                </div>
                            </div>
                        @endif
                        @if($supplier !== null)
                            <div class="form-group">
                                {!! Form::label('supplier', Lang::getFromJson('Supplier Name'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! $supplier /* viewFeeder->autoComplete */ !!}
                                </div>
                            </div>
                        @endif
                        @if($result->class->type_id !== null)
                            <div class="form-group">
                                {!! Form::label('type_id', $result->class->type_name . ' Id', ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! Form::number('type_id', $result->type_id, [
                                        'class' => 'form-control',
                                        'autofocus',
                                        'min' => 1,
                                        'placeholder' => Lang::getFromJson('Insert valid Id of') . ' ' . $result->class->type_name
                                    ]) !!}
                                </div>
                            </div>
                        @endif
                        @if(count($result->class->parents) > 0)
                            <div class="form-group">
                                {!! Form::label('parent_entity_class_id', Lang::getFromJson('Entity'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    @if(count($result->class->parents) > 1)
                                        {!! Form::select('parent_entity_class_id', $result->class->parents, Input::old('parent_entity_class_id'), [
                                            'class' => 'form-control',
                                            'required' => $result->class->require_parent ? 'required' : null,
                                            'placeholder' => Lang::getFromJson('Select parent Entity Class')
                                        ]) !!}
                                    @else
                                        {!! Form::select('parent_entity_class_id', $result->class->parents, Input::old('parent_entity_class_id'), [
                                            'class' => 'form-control',
                                            'required' => $result->class->require_parent ? 'required' : null
                                        ]) !!}
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                {!! Form::label('parent_entity_id', Lang::getFromJson('Parent Entity Id'), ['class' => "col-md-$labelWidth control-label"]) !!}
                                <div class="col-md-{{$inputWidth}}">
                                    {!! Form::number('parent_entity_id', $result->parent_id, [
                                        'class' => 'form-control',
                                        'autofocus',
                                        'required' => $result->class->require_parent ? 'required' : null,
                                        'min' => 1,
                                        'placeholder' => Lang::getFromJson('Insert valid Entity parent Id')
                                    ]) !!}
                                </div>
                            </div>
                        @endif
                    </div>
                    <div class="panel-footer">
                        <a class="btn btn-default hidden-xs"
                           href="{{ route($router . '.show', ['id' => $objectId, 'classId' => $classId]) }}">
                            <i class="glyphicon glyphicon-arrow-left"></i>
                            @lang('Go to Detail')
                        </a>
                        <div class="pull-right">
                            <button type="submit" class="btn btn-primary">
                                @lang('Confirm Update')
                                <i class="glyphicon glyphicon-arrow-right"></i>
                            </button>
                        </div>
                    </div>
                    {!! Form::close() !!}
                </div>
            </div>
        </div>
    </div>
@endsection
