How to filter arrays in a kirby blueprint query

I’d like to filter an array in a blueprint query in kirby 3.6. The idea is in the first step to select a set of tags from a global options array (to narrow down options for step 2). Step 2 is to select from the narrowed down array into a structure field. The thing is that I want to kind of sort them and remove already used tags from the list of available tags. So tags can only be used once inside the structure rows.

enter image description here

The page blueprint looks like the following. The structure needs a page refresh before the selected options become available with everything in one yml. The main problem however is how to filter the arrays without having to create a whole new plugin.:

title: Sandbox

fields:
  ids:
    type: multiselect
    options:
      - A
      - B
      - C
      - D
      - E
      - F
      - G

  sorted:
    type: structure
    fields:
      tags:
        type: multiselect
        options: query
        query: # how to combine the following 2 queries?
        
        # query step 1, narrowed down ids: page.ids.split(",")
        # query step 2, already used ids:  page.sorted.toStructure.pluck("tags", ",", true)
        
        # works for collections, but not arrays: page.ids.without(page.sorted)
        # equivalent in php, not KQL: array_diff($all_ids, $used_ids)

As far as I understand, page methods/models are only for access in the template, but not in the panel. I want to avoid writing an extra plugin for this, but it seems the learning curve is getting steep quite quickly.

Any ideas are appreciated. I’m new to kirby, please give me the idiot proof explanation, thank you!!!

You would need a custom page method or (page model method) which you register in a plugin: Page methods | Kirby CMS

That’s not true, those methods are also available in the Panel.
Inside this method, you can merge both arrays as you would in PHP.

But note that it wouldn’t give you on the fly data, but only that data that is already stored, so to get the difference when you add something new in the structure field, you would have to save and refresh the page. This is most likely not what you are looking for.

That did the trick! Thank you!