<?php

namespace Nurmuhammet\InventoryHistoryItems;

use Illuminate\Support\Collection;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\SupportsDependentFields;

class InventoryHistoryItems extends Field
{
    use SupportsDependentFields;

    /**
     * The field's component.
     *
     * @var string
     */
    public $component = 'inventory-history-items';

    /**
     * Set the options for the select menu.
     *
     * @param  array<string|int, array<string, mixed>|string>|\Closure|callable|\Illuminate\Support\Collection  $options
     *
     * @phpstan-param TOption|(callable(): (TOption))|(\Closure(): (TOption)) $options
     *
     * @return $this
     */
    public function options(array|Collection $options): self
    {
        return $this->withMeta([
            'options' => $this->serializeOptions($options),
        ]);
    }

    /**
     * Serialize Options
     *
     * @param  Collection  $options
     */
    public function serializeOptions(array|Collection $options): array|Collection
    {
        return collect($options)->map(fn ($label, $value) => ['label' => $label, 'value' => $value]);
    }
}
