Link-field: Check for all possible cases

I am testing the type field. The use can for example select a page or a link (or other types, see Link field | Kirby CMS).

If page is selected I can get the URL of the page with this code

<?= $block->link()->toPage()->permalink() ?>

Of course, this doesn’t work if the “link” is a URL. So I need a switch-statement for all 5 possible link-types). Is there a better solution I am not seeing?

Just for reference, my block:

name: Infofeld
icon: info
label: "{{ name }} - {{ kurzbeschreibung }}"
fields:
  name:
    type: text
  kurzbeschreibung:
    type: textarea
  link:
    label: Verweis
    type: link

One possible code could be

<?php if ($block->link()->toFile() || $block->link()->toPage()) : ?>
            <p><a href="<?= $block->link()->permalink() ?>">Öffnen...</a></p>
<?php else : ?>
            <p><a href="<?= $block->link()->url() ?>">Webseite öffnen…</a></p>
<?php endif; ?>

if you only allow file, link and url in the field

Calling toUrl() on the field should actually resolve all types of urls without any if statements on your side.