@extends('template')

@section('page-title') @if(empty($model->ID)) New @else Edit @endif {{$model->getLabel()}} @endsection

@section('tag-title') @if(empty($model->ID)) New @else Edit @endif  {{$model->getLabel()}} @endsection

@section('page-sub-title')

@endsection

@section('main-content')
    <div class="row">
        <div class="{{$model->getFormSize()}}">
            <div class="card">
                <div class="card-body">
                    <form method="POST"   action="@if(empty($model->getViewFormPostUrl())){{url(Request::path())}}@else{{url($model->getViewFormPostUrl())}}@endif" enctype="multipart/form-data" class="form-horizontal form-label-left input_mask">
                        {{ csrf_field() }}
                        <div class="row">
                            <?php
                            $fields = $model->getFields();
                            $primaryKey = $model->getPrimaryKey();
                            ?>
                            <input type="hidden" value="@if($model->$primaryKey!=0){{$model->$primaryKey}}@else{{0}}@endif" id="_id" name="_id">
                            @foreach($fields as $name=>$title)
                                <?php
                                if($model->getInputByLine()==1)$div_class = 'col-sm-12';
                                if($model->getInputByLine()==2)$div_class = 'col-sm-6';
                                if($model->getInputByLine()==3)$div_class = 'col-sm-4';
                                ?>
                                @include('inc.cruds.form_item')
                            @endforeach

                            <div class="col-sm-12">
                                <button type="submit"  class="btn btn-success action-btn  float-right">Save</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <style>
        label{
            font-weight: bold;
        }
    </style>
@endsection


@section('page-style')

@endsection

@section('page-script')
    <script !src="">
        $(function(e) {
            @foreach($model->getFormRequireds() as $input_required)
                $("label[for='{{$input_required}}']").append('<span class="required"> *</span>');
                @if(!in_array($input_required, $model->getRichTexts()) && !in_array($input_required, $model->getFiles()))
                    $('#{{$input_required}}').attr('required', true);
                @endif
            @endforeach
        });
    </script>
@endsection
