<?php

namespace App\Traits;

use App\Models\Breadcrumb;
use Livewire\Attributes\Computed;

trait HasBreadcrumb
{
    public string $breadcrumbPage = '';

    #[Computed]
    public function breadcrumb()
    {
        if (empty($this->breadcrumbPage)) {
            return null;
        }

        return Breadcrumb::getByPage($this->breadcrumbPage);
    }

    public function getBreadcrumbImage(): string
    {
        $breadcrumb = $this->breadcrumb;
        
        if ($breadcrumb && $breadcrumb->image) {
            return url('/') . '/storage/' . $breadcrumb->image;
        }
        
        // Default fallback image
        return url('/') . '/assets/img/bg/32.jpg';
    }

    public function getBreadcrumbTitle(): string
    {
        $breadcrumb = $this->breadcrumb;
        
        return $breadcrumb ? $breadcrumb->title : 'Page Title';
    }
}
