<?php

namespace App\View\Composers;

use App\Models\Mall\MallCategory;
use App\Models\Mall\MallStorage;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class MallComposer
{
    /**
     * Bind data to the view.
     */
    public function compose(View $view): void
    {
        // Fetch the amount of items in storage
        $storageCount = 0;
        if (Auth::check()) {
            try {
                $storageCount = MallStorage::getUniqueItemCount(Auth::id());
            } catch (\Exception $e) {
                \Log::error('MallComposer - MallStorage error: ' . $e->getMessage());
                $storageCount = 0;
            }
        }
        $view->with('storageCount', $storageCount);

        // Fetch discount description (translatable)
        $view->with('discountDesc', __('mall/main.discount_active'));

        // Fetch the mall categories
        $view->with('categories', MallCategory::all());
    }
}
