<?php

namespace Nurmuhammet\PayoutProducts;

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

class PayoutProducts extends Field
{
    use SupportsDependentFields;

    /**
     * The field's component.
     *
     * @var string
     */
    public $component = 'payout-products';

    /**
     * Products to be rendered
     *
     * @param  array  $products
     */
    public function products(array|callable|Collection $products): self
    {
        if (is_callable($products)) {
            $products = call_user_func($products);
        }

        if ($products instanceof Arrayable) {
            $products = $products->toArray();
        }

        return $this->withMeta(['products' => $products]);
    }
}
