@extends('layouts.backend')

@section('title', $category->exists ? 'Editando '.$category->title : 'Crear nueva categoría')

@section('content')
    <!-- Page Header -->
    <div class="page-header">
        <div class="row align-items-end">
            <div class="col-sm mb-2 mb-sm-0">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb breadcrumb-no-gutter">
                        <li class="breadcrumb-item"><a class="breadcrumb-link" href="javascript:;">Administración</a></li>
                        <li class="breadcrumb-item"><a class="breadcrumb-link" href="{{ route('backend.categories.index') }}">Categorías</a></li>
                        <li class="breadcrumb-item active" aria-current="page">@yield('title')</li>
                    </ol>
                </nav>

                <h1 class="page-header-title">@yield('title')</h1>
            </div>
        </div>
        <!-- End Row -->
    </div>
    <!-- End Page Header -->

    <!-- Step Form -->
    {!! Form::model($category, [
        'method' => $category->exists ? 'put' : 'post',
        'route' => $category->exists ? ['backend.categories.update', $category->id] : 'backend.categories.store',
        'class' => 'js-step-form py-md-5',
        'files' => true
    ]) !!}
    <div class="row justify-content-lg-center">
        <div class="col-lg-8">
            <div class="card card-lg active">
                <!-- Body -->
                <div class="card-body">
                    <!-- Form Group -->
                    <div class="row form-group">
                        <label class="col-sm-3 col-form-label input-label">Imagen</label>

                        <div class="col-sm-9">
                            <div class="d-flex align-items-center">
                                <!-- Avatar -->
                                <label class="avatar avatar-xxl avatar-uploader mr-5" for="avatarUploader">
                                    <img id="avatarImg" class="avatar-img" src="{{ asset($category->image ?? 'backend-assets/img/160x160/img1.jpg') }}" alt="Image Description">
                                    {!! Form::hidden('image', null, ['id' => 'image']) !!}
                                    <input type="file" class="js-file-attach avatar-uploader-input" id="avatarUploader" data-hs-file-attach-options='{
                                              "textTarget": "#avatarImg",
                                              "mode": "image",
                                              "targetAttr": "src",
                                              "resetTarget": ".js-file-attach-reset-img",
                                              "resetImg": "{{ asset('backend-assets/img/160x160/img1.jpg') }}",
                                              "allowTypes": [".png", ".jpeg", ".jpg"]
                                           }' name="image">

                                    <span class="avatar-uploader-trigger">
                                          <i class="tio-edit avatar-uploader-icon shadow-soft"></i>
                                        </span>
                                </label>
                                <!-- End Avatar -->

                                <button type="button" class="js-file-attach-reset-img btn btn-white" data-target="#image">Borrar</button>
                            </div>
                        </div>
                    </div>
                    <!-- End Form Group -->

                    <!-- Form Group -->
                    <div class="row form-group">
                        <label for="titleLabel" class="col-sm-3 col-form-label input-label">Nombre</label>

                        <div class="col-sm-9">
                            {!! Form::text('title', null, ['class' => 'form-control', 'id' => 'titleLabel']) !!}
                        </div>
                    </div>
                    <!-- End Form Group -->

                    <!-- Form Group -->
                    <div class="row form-group">
                        <label for="slugLabel" class="col-sm-3 col-form-label input-label">Slug <i class="tio-help-outlined text-body ml-1" data-toggle="tooltip" data-placement="top" title="URL de la categoría"></i></label>

                        <div class="col-sm-9">
                            {!! Form::text('slug', null, ['class' => 'form-control', 'id' => 'slugLabel']) !!}
                        </div>
                    </div>
                    <!-- End Form Group -->

                    <hr class="my-4">
                    <div class="form-group mb-0">
                        <!-- Toggle Switch -->
                        <label class="row toggle-switch" for="activeSwitch1">
                          <span class="col-8 col-sm-9 toggle-switch-content ml-0">
                            <span class="text-dark">Activo</span>
                          </span>
                            <span class="col-4 col-sm-3">
                            {!! Form::hidden('active', 0) !!}
                                {!! Form::checkbox('active', 1, $category->exists ? null : true, ['class' => 'toggle-switch-input', 'id' => 'activeSwitch1']) !!}
                                <span class="toggle-switch-label ml-auto">
                              <span class="toggle-switch-indicator"></span>
                            </span>
                          </span>
                        </label>
                        <!-- End Toggle Switch -->
                    </div>
                </div>
                <!-- End Body -->

                <!-- Footer -->
                <div class="card-footer d-sm-flex align-items-sm-center">
                    <div class="ml-auto">
                        <button type="submit" class="btn btn-primary">{{ $category->exists ? 'Actualizar' : 'Crear' }} categoría</button>
                    </div>
                </div>
                <!-- End Footer -->
            </div>
        </div>
    </div>
    <!-- End Row -->
    {!! Form::close() !!}
    <!-- End Step Form -->
@endsection
