using UnityEngine;
namespace Ashwild.Inventory
{
///
/// The view payload for the hover description panel: exactly what the panel renders (icon,
/// name, description, and an optional duration/uses bar), nothing more. The inventory manager
/// builds one of these from a hovered slot and pushes it into the view, so the panel never
/// touches ItemData or the inventory model — it just draws what it is handed.
///
public readonly struct ItemDescriptionView
{
public readonly Sprite Icon;
public readonly string Name;
public readonly string Description;
///
/// Whether the hovered item tracks uses/durability and should show its duration bar.
///
public readonly bool HasDuration;
///
/// Remaining uses as a 0..1 fill for the bar's Filled image.
///
public readonly float DurationFill;
///
/// The remaining/max label drawn over the bar, e.g. "3 / 5".
///
public readonly string DurationText;
public ItemDescriptionView(Sprite icon, string name, string description,
bool hasDuration, float durationFill, string durationText)
{
Icon = icon;
Name = name;
Description = description;
HasDuration = hasDuration;
DurationFill = durationFill;
DurationText = durationText;
}
///
/// Builds the payload for a hovered slot, including the uses bar for items that track
/// durability. Shared by the inventory grid and the hotbar so both describe an item
/// identically — they used to each build this by hand and could drift apart.
///
public static ItemDescriptionView From(InventorySlot slot)
{
ItemData item = slot.ItemData;
bool hasDuration = item.HasUses;
float fill = hasDuration && item.MaxUses > 0 ? (float)slot.CurrentUses / item.MaxUses : 0f;
string durationText = hasDuration ? $"{slot.CurrentUses} / {item.MaxUses}" : string.Empty;
return new ItemDescriptionView(item.Icon, item.ItemName, item.Description,
hasDuration, fill, durationText);
}
}
}