@extends('back.layout.pages-layout')
@section('pageTitle', isset($pageTitle) ? $pageTitle : 'Page Title here')
@section('content')

    <div class="page-header">
        <div class="row">
            <div class="col-md-12 col-sm-12">
                <div class="title">
                    <h4>Profile</h4>
                </div>
                <nav aria-label="breadcrumb" role="navigation">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="{{ route('admin.dashboard') }}">Home</a>
                        </li>
                        <li class="breadcrumb-item active" aria-current="page">
                            Profile
                        </li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>

    @livewire('admin.profile')
    @push('scripts')
        <script>
            const cropper = new Kropify('input[type="file"][id="profilePictureFile"]', {
                aspectRatio: 1,
                viewMode: 1,
                preview: 'img#profilePicturePreview',
                processURL: '{{ route('admin.update_profile_picture') }}', // or processURL:'/crop'
                maxSize: 2 * 1024 * 1024, // 2MB
                allowedExtensions: ['jpg', 'jpeg', 'png'],
                showLoader: true,
                animationClass: 'pulse',
                cancelButtonText: 'Cancel',
                resetButtonText: 'Reset',
                cropButtonText: 'Crop & Upload',
                maxWoH: 255,
                onError: function(response) {
                    toastr.options = {
                        closeButton: true,
                        newestOnTop: false,
                        progressBar: true,
                        positionClass: "toast-bottom-right",
                        preventDuplicates: false,
                        onclick: null,
                        showDuration: "300",
                        hideDuration: "1000",
                        timeOut: "5000",
                        extendedTimeOut: "1000",
                        showEasing: "swing",
                        hideEasing: "linear",
                        showMethod: "fadeIn",
                        hideMethod: "fadeOut"
                    };

                    // Je nach Antwortstruktur anpassen:
                    const message = response.message || "Es ist ein Fehler aufgetreten.";

                    if (response.status === 0 || response.status === false) {
                        toastr.error(message);
                    } else {
                        toastr.error(message);
                    }
                },

                onDone: function(response) {
                    toastr.options = {
                        closeButton: true,
                        newestOnTop: false,
                        progressBar: true,
                        positionClass: "toast-bottom-right",
                        preventDuplicates: false,
                        onclick: null,
                        showDuration: "300",
                        hideDuration: "1000",
                        timeOut: "5000",
                        extendedTimeOut: "1000",
                        showEasing: "swing",
                        hideEasing: "linear",
                        showMethod: "fadeIn",
                        hideMethod: "fadeOut"
                    };

                    if (response.status === 1) {
                        toastr.success(response.message || "Erfolgreich gespeichert.");

                        Livewire.dispatch('updateTopUserInfo', []);
                        Livewire.dispatch('updateProfile', []);
                    } else {
                        toastr.error(response.message || "Etwas ist schiefgelaufen.");
                    }
                }
            });
        </script>
    @endpush
@endsection
