<?php

namespace App\Nova\Resources\Branch\Concerns;

use App\Models\System\Location\Province;
use Closure;

class BranchNovaRepo
{
    /**
     * Depends on region
     */
    public static function dependsOnRegion(string $attribute = 'region'): Closure
    {
        return function ($field, $request, $formData) use ($attribute) {
            $field->options(
                $formData->{$attribute}
                    ? Province::where('region', $formData->{$attribute})->pluck('name', 'id')
                    : []
            );
        };
    }
}
