@extends('admin.layout.master')

@section('title', 'Kategorizasyon')

@section('breadcrumb')
    <div class="container-fluid px-4">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb my-0">
                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard.index') }}">Anasayfa</a></li>
                <li class="breadcrumb-item @if (!$taxonomy) active @endif">
                    @if ($taxonomy)
                        <a href="{{ route('admin.taxonomy.index') }}">Kategorizasyon</a>
                    @else
                        <span>Kategorizasyon</span>
                    @endif
                </li>
                @foreach ($ancestors as $ancestor)
                    <li class="breadcrumb-item"><a
                            href="{{ route('admin.taxonomy.index', ['id' => $ancestor->id]) }}">{{ $ancestor->name }}</a>
                    </li>
                @endforeach
                @if ($taxonomy)
                    <li class="breadcrumb-item active"><span>{{ $taxonomy->name }}</span></li>
                @endif
            </ol>
        </nav>
    </div>
@stop

@section('content')
    <div class="container-lg px-4">

        <div class="row mb-4">
            <div class="d-flex justify-content-end">
                @if (request()->has('id'))
                    <a href="{{ route('admin.taxonomy.create', ['id' => request()->get('id')]) }}"
                        class="btn btn-sm btn-primary">
                    @else
                        <a href="{{ route('admin.taxonomy.create') }}" class="btn btn-sm btn-primary">
                @endif
                <span class="cil-plus"></span>
                    Yeni
                </a>
            </div>
        </div>

        <div class="card mb-4">
            <livewire:admin.taxonomy.index />
        </div>

    </div>

@section('css')
    <link href="{{ URL::to('admin/vendors/@coreui/icons/css/free.min.css') }}" rel="stylesheet">
    @livewireStyles
@stop

@section('js')
    @livewireScripts
    <script src="https://cdn.jsdelivr.net/gh/livewire/sortable@v1.x.x/dist/livewire-sortable.js"></script>

    <script>
        const toastConfig = {
            toast: true,
            position: 'top-end',
            showConfirmButton: false,
            timer: 2000,
            timerProgressBar: true,
        };

        document.addEventListener('livewire:init', () => {
            Livewire.on('deleteTriggered', (event) => {
                swal.fire({
                    title: 'Emin misiniz?',
                    text: 'Bu kategoriye ait tüm alt kategoriler silinecektir ve bu işlem geri alınamaz!',
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonText: 'Evet, sil!',
                    cancelButtonText: 'Vazgeç'
                }).then((result) => {
                    if (result.isConfirmed) {
                        Livewire.dispatch('delete', {
                            id: event.id
                        });
                    }
                });
            });

            Livewire.on('showAlert', (event) => {
                Swal.fire({
                    ...toastConfig,
                    text: event[0].text,
                    icon: event[0].icon,
                });
            });
        });
    </script>
@stop

@stop
