@extends('layouts.admin')

@php
    if($create){
        $title = __('adminforms.brands.title_insert');
        $formpar = array('route' => 'admin.brand.store');
    } else {
        $title = __('adminforms.brands.title_update');
        $formpar = array('route' => array('admin.brand.update', $brand->brand_id), 'method' => 'PUT');
    }

    $tr = [
        'brand name'      => __('adminforms.brands.brand_name'),
        'brand title'     => __('adminforms.brands.brand_title'),
        'brand_metadesc'  => __('adminforms.brands.brand_metadesc'),
        'brand keyw'      => __('adminforms.brands.brand_keyw'),
        'slug'            => __('adminforms.common.slug'),
    ];
@endphp

@section('title'){{$title}}@endsection
@section('header'){{$title}}@endsection
@section('header_desc') @endsection
@section('breadcumbs') @endsection

@section('content')
    <!-- Main content -->
    <section class="content">



        <div class="row">

            <div class="col-xs-12">
                @if (session('error'))
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <i class="icon fa fa-exclamation-triangle"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                        {{ session('error') }}
                    </div>
                @endif
            </div>

            {!! Form::open($formpar) !!}

            <div class="col-xs-12">



                <div class="panel panel-default">
                    {{--<div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list-alt"></i> Osnovni podaci</h3>
                    </div><!-- /. panel-heading -->--}}

                    <div class="panel-body">
                        <div class="row">

                            <div class="col-xs-12 col-sm-6 col-md-4 pbb">
                                {{Form::label('brand_name', ucfirst(__('adminforms.brands.brand_name').':'))}}
                                {{Form::text('brand_name', old('brand_name', $brand->brand_name ), ['class' => 'form-control', 'id' => 'name'])}}
                                <small class="error">{{ strtr($errors->first('brand_name'),$tr) }}</small>
                            </div>


                            @foreach(config('app.languages') as $lang)

                                @php

                                    $t_slug             = '';

                                    $route = $brand->route($lang);

                                    if($route){
                                        $t_slug             = $route->slug;
                                    }

                                @endphp


                                <div class="col-xs-12 col-sm-6 col-md-4 pbb">
                                    {{Form::label($lang.'_'.'slug', $lang.' '.ucfirst(__('adminforms.common.slug').__('adminforms.common.slug_info').':'))}}
                                    {{Form::text($lang.'_'.'slug', old($lang.'_'.'slug', $t_slug ), ['class' => 'form-control', 'id' => $lang.'slug'])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'slug'),$tr) }}</small>
                                </div>


                            @endforeach

                            <div class="col-xs-12">
                                <hr>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-4 pbb">
                                {{Form::label('brand_title', ucfirst(__('adminforms.brands.brand_title').':'))}}
                                {{Form::textarea ('brand_title', old('brand_title', $brand->brand_title), ['class' => 'form-control', 'rows' => 3])}}
                                <small class="error">{{ strtr($errors->first('brand_title'),$tr) }}</small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-4 pbb">
                                {{Form::label('brand_metadesc', ucfirst(__('adminforms.brands.brand_metadesc').':'))}}
                                {{Form::textarea ('brand_metadesc', old('brand_metadesc', $brand->brand_metadesc), ['class' => 'form-control', 'rows' => 3])}}
                                <small class="error">{{ strtr($errors->first('brand_metadesc'),$tr) }}</small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-4 pbb">
                                {{Form::label('brand_keyw', ucfirst(__('adminforms.brands.brand_keyw').':'))}}
                                {{Form::textarea ('brand_keyw', old('brand_keyw', $brand->brand_keyw), ['class' => 'form-control', 'rows' => 3])}}
                                <small class="error">{{ strtr($errors->first('brand_keyw'),$tr) }}</small>
                            </div>

                            <br clear="all">
                            <hr>
                            <div class="col-xs-12">
                                @php $btntext = ($create) ? __('adminforms.brands.btn_insert') : __('adminforms.brands.btn_update')@endphp
                                {{Form::submit($btntext, ['class' => 'btn btn-success pull-right'])}}
                            </div>

                        </div> <!-- /.row -->
                    </div> <!-- /.panel-body -->
                </div> <!-- /.panel panel-default-->

            </div> <!-- /.col -->



            {!! Form::close() !!}

        </div>
        <!-- /.row -->

    </section>
@endsection

@push('css')
@endpush


@push('scripts')
    <script>
        $(document).ready(function(){

            $('#name').keyup(function () {
                var cval = $.trim($(this).val());
                var cslug = cval.replace(/\s/g, '-').toLowerCase();
                @foreach(config('app.languages') as $lang)
                $('#{{$lang}}slug').val(cslug);
                @endforeach
            });
            $('#name').blur(function () {
                var cval = $.trim($(this).val());
                var cslug = cval.replace(/\s/g, '-').toLowerCase();
                @foreach(config('app.languages') as $lang)
                $('#{{$lang}}slug').val(cslug);
                @endforeach
            });

        });
    </script>
@endpush