
<?php $__env->startSection('pageTitle', isset($pageTitle) ? $pageTitle : 'Page Title Here'); ?>
<?php $__env->startSection('content'); ?>

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

<div class="pd-20 card-box mb-4">
    <?php
$__split = function ($name, $params = []) {
    return [$name, $params];
};
[$__name, $__params] = $__split("admin.settings");

$__html = app('livewire')->mount($__name, $__params, 'lw-4084050292-0', $__slots ?? [], get_defined_vars());

echo $__html;

unset($__html);
unset($__name);
unset($__params);
unset($__split);
if (isset($__slots)) unset($__slots);
?>
</div>

<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        const inputFile = document.querySelector('input[type="file"][name="site_logo"]');
        const previewImage = document.getElementById("preview_site");

        inputFile.addEventListener("change", function(event) {
            const file = event.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    previewImage.src = e.target.result;
                };
                reader.readAsDataURL(file);
            }
        });
    });
    $(document).ready(function() {
        $('#updateLogoForm').submit(function(e) {
            e.preventDefault(); // Prevent default form submission

            var form = this;
            var inputFile = $(form).find('input[type="file"]');
            var inputVal = inputFile.val();
            var errorElement = $(form).find('span.text-danger');

            // Reset error message
            errorElement.text('');

            if (inputVal.length > 0) {
                var formData = new FormData(form);

                $.ajax({
                    url: $(form).attr('action'),
                    method: $(form).attr('method'),
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: 'json',
                    beforeSend: function() {

                    },
                    success: function(data) {
                        try {
                            if (data.status === 1) {
                                $(form)[0].reset();
                                toastr.success(data.message);

                                // Update all instances of the site logo
                                $('img.site_logo').each(function() {
                                    $(this).attr('src', '/' + data.image_path + '?' + new Date().getTime());
                                });
                            } else {
                                toastr.error(data.message);
                            }
                        } catch (e) {
                            console.error('Parsing error:', e);
                            toastr.error('Unexpected response format.');
                        }
                    },
                    error: function(xhr, status, error) {
                        console.error('AJAX Error:', status, error);
                        console.error('Response:', xhr.responseText);
                        toastr.error('An error occurred while uploading the logo. Please try again.');
                    }
                });
            } else {
                errorElement.text('Please select an image file.');
            }
        });
    });
    document.addEventListener("DOMContentLoaded", function() {
        const inputFile = document.querySelector('input[type="file"][name="site_favicon"]');
        const previewImage = document.getElementById("preview_site_favicon");

        inputFile.addEventListener("change", function(event) {
            const file = event.target.files[0];
            if (file) {
                const allowedExtensions = ["image/png", "image/x-icon"];
                if (!allowedExtensions.includes(file.type)) {
                    alert("Only PNG and ICO files are allowed.");
                    inputFile.value = "";
                    return;
                }
                const reader = new FileReader();
                reader.onload = function(e) {
                    const img = new Image();
                    img.src = e.target.result;
                    img.onload = function() {
                        if (img.width !== img.height) {
                            alert("Please upload a square image.");
                            inputFile.value = "";
                            return;
                        }
                        previewImage.src = e.target.result;
                    };
                };
                reader.readAsDataURL(file);
            }
        });
    });
    $(document).ready(function() {
        $('#updateFaviconForm').submit(function(e) {
            e.preventDefault(); // Prevent default form submission

            var form = this;
            var inputFile = $(form).find('input[type="file"]');
            var inputVal = inputFile.val();
            var errorElement = $(form).find('span.text-danger');

            // Reset error message
            errorElement.text('');

            if (inputVal.length > 0) {
                var formData = new FormData(form);

                $.ajax({
                    url: $(form).attr('action'),
                    method: $(form).attr('method'),
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: 'json',
                    beforeSend: function() {

                    },
                    success: function(data) {
                        try {
                            if (data.status === 1) {
                                $(form)[0].reset();
                                var linkElement = document.querySelector('link[rel="icon"]');
                                linkElement.href='/'+data.image_path;
                                toastr.success(data.message);

                                // Update all instances of the site logo
                                $('img.site_logo').each(function() {
                                    $(this).attr('src', '/' + data.image_path + '?' + new Date().getTime());
                                });
                            } else {
                                toastr.error(data.message);
                            }
                        } catch (e) {
                            console.error('Parsing error:', e);
                            toastr.error('Unexpected response format.');
                        }
                    },
                    error: function(xhr, status, error) {
                        console.error('AJAX Error:', status, error);
                        console.error('Response:', xhr.responseText);
                        toastr.error('An error occurred while uploading the logo. Please try again.');
                    }
                });
            } else {
                errorElement.text('Please select an image file.');
            }
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('back.layout.page-layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\larablog\resources\views/back/pages/settings/general_settings.blade.php ENDPATH**/ ?>