@extends('layouts.app')

@section('content')
<div class="container">
    <div class="col-md-8 offset-md-2">
        <h1>{{isset($supplier)?'Editar':'Nuevo'}} Proveedor</h1>
        <hr>
        @if(isset($supplier))
            {!! Form::model($supplier,['method'=>'put','id'=>'frm', 'files' => 'true']) !!}
        @else
            {!! Form::open(['id'=>'frm', 'files' => 'true']) !!}
        @endif
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
            <div class="form-group row required">
                {!! Form::label("company_name","Tu nombre o nombre de la empresa*",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("company_name",null,["class"=>"form-control".($errors->has('company_name')?" is-invalid":""),"autofocus",'placeholder'=>'Nombre de la empresa o negocio']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("cover_photo","Foto de portada",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::file("cover_photo", null) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("categories","Categorías*",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("categories",str_replace(array('[',']','"'),"",$categories_names),["id"=>"categories","class"=>"form-control".($errors->has('categories')?" is-invalid":""),"autofocus",'placeholder'=>'Categoría 1, Categoría 2,']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("tags","Palabras clave",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("tags",null,["data-role"=>"tagsinput","class"=>"form-control".($errors->has('tags')?" is-invalid":""),"autofocus",'placeholder'=>'Palabra clave 1, Palabra clave 2, Palabra clave 3']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>

            <div class="form-group row required">
                {!! Form::label("RFC","RFC",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("RFC",null,["class"=>"form-control".($errors->has('RFC')?" is-invalid":""),"autofocus",'placeholder'=>'RFC']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("CURP","CURP",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("CURP",null,["class"=>"form-control".($errors->has('CURP')?" is-invalid":""),"autofocus",'placeholder'=>'CURP']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("clabe","CLABE",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("clabe",null,["class"=>"form-control".($errors->has('clabe')?" is-invalid":""),"autofocus",'placeholder'=>'CLABE Interbancaria']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("bank","Banco",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::select("bank", $banks, isset($supplier) ? $supplier->bank_id : null) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("taxes_id","Regimen Fiscal",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::select("taxes_id", array(
                      '1' => 'Persona Física',
                      '2' => 'Persona Moral',
                    ), (isset($supplier) ? (($supplier->regimen!='Persona Moral') ? '1' : '2') : null)) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                    <br> (Sino esta registrado ante el SAT, seleccione Persona Física)
                </div>
            </div>

            <div class="form-group row required">
                {!! Form::label("minimun_fee","Tarifa de revisión",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::number("minimun_fee",'150',["class"=>"form-control".($errors->has('minimun_fee')?" is-invalid":""),"autofocus",'placeholder'=>'Mínimo $150']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("address","Dirección*",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("address",null,["class"=>"form-control".($errors->has('address')?" is-invalid":""),"autofocus",'placeholder'=>'Ingresa tu dirección']) !!}
                    <span id="error-address" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("references_options","¿Cómo supiste de nosotros?*",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::select("references_options", array(
                      '1' => 'Radio',
                      '2' => 'TV',
                      '3' => 'Redes Sociales',
                      '4' => 'Amigos',
                      '6' => 'Cámara de Comercio',
                      '5' => 'Otro',
                    ), isset($supplier->references)) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row required">
                {!! Form::label("references","Si es otro, específica",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
                <div class="col-md-8">
                    {!! Form::text("references",null,["class"=>"form-control".($errors->has('references')?" is-invalid":""),"autofocus",'placeholder'=>'Empresa o el nombre de un héroe registrado']) !!}
                    <span id="error-name" class="invalid-feedback"></span>
                </div>
            </div>
            <div class="form-group row" style="margin-bottom: 0rem;">
              {!! Form::hidden("lat",null,["id"=>"lat","class"=>"form-control".($errors->has('lat')?" is-invalid":""),"autofocus"]) !!}
            </div>
            <div class="form-group row" style="margin-bottom: 0rem;">
              {!! Form::hidden("lng",null,["id"=>"lng","class"=>"form-control".($errors->has('lng')?" is-invalid":""),"autofocus"]) !!}
            </div>
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
            <div class="form-group row">
                <div class="col-md-3 col-lg-2"></div>
                <div class="col-md-4">
                    <a href="{{url('supplier')}}" class="btn btn-danger btn-xs">
                        Atrás</a>
                    {!! Form::button("Guardar",["type" => "submit","class"=>"btn btn-primary btn-xs"])!!}
                </div>
            </div>
            {!! Form::close() !!}
            </div>
        </div>
@endsection

@section('js')
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBmkTsg0-1VKllM_vHD6V1EhPnF0YUP-88&libraries=places"></script>
<script type="text/javascript">
    var mapSearchBox = new google.maps.places.Autocomplete(document.getElementById('address'));
    google.maps.event.addListener(mapSearchBox, 'place_changed', function () {
        var place = mapSearchBox.getPlace();
        $('#lat').val(place.geometry.location.lat());
        $('#lng').val(place.geometry.location.lng());
    });

    var categories = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.whitespace,
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch: { url: "/api/categories-name" }
    });
    categories.initialize();

    $('#categories').tagsinput({
        typeaheadjs: {
            name: 'categories',
            source: categories.ttAdapter()
        }
    });
</script>
@endsection
