Hierarchical dynamic select field

I have 3 tables that are hierarchical of each other Classes is a dependent of Sections and Sections is a dependent of Departments or I can say Department is the parent, sections is a child of department and classes is a child of sections and a grandchild of department.
My question is how do I use a form that will let me conditional select sections that belong to a department and classes that belong to a sections.
So for my example if I select my department as Indoor Exhibit, a new select field would show up with all the sections that have a relation with the department of indoor exhibit and then when I select photo as my section a new select field shows up with all of the classes that relate to the photo section.
Do I this with conditional logic? Is there a way to dynamic show using a query builder based on the previous selected field? Or do I have to have 100’s of conditional logic fields for all of the sections and classes that I have?

You just need 3 server actions each containing a database query for the 3 selects - departments, sections and classes. Use these 3 server actions to populate 3 dynamic dropdowns on the page.
You filter the sections database query with the value returned by the departments select menu.
Then you filter the classes database query with the value returned by the sections select.