<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Ferienpass\AdminBundle\Controller\Dashboard\GanttController;
use Ferienpass\AdminBundle\Controller\Dashboard\HeatmapController;
use Ferienpass\AdminBundle\Controller\Dashboard\NextStepsController;
use Ferienpass\AdminBundle\Controller\Page\EditionsEditController;
use Ferienpass\AdminBundle\Controller\Page\OfferEditController;
use Ferienpass\AdminBundle\Form\Filter\AbstractFilter;
use Ferienpass\AdminBundle\Menu\ActionsBuilder;
use Ferienpass\AdminBundle\Menu\MenuBuilder;
use Knp\Menu\Twig\Helper;
use Twig\Extension\StringLoaderExtension;

return function(ContainerConfigurator $container): void {
    $services = $container->services()
        ->defaults()
        ->autoconfigure()
        ->autowire()
    ;

    $services->instanceof(AbstractFilter::class)->tag('ferienpass_admin.filter');

    $services
        ->load('Ferienpass\\AdminBundle\\', '../src/')
        ->exclude(['../src/{DependencyInjection,Entity}', '../src/LiveComponent/MultiSelect.php'])
    ;

    $services->get(NextStepsController::class)->tag('ferienpass_admin.dashboard_widget', ['priority' => 1000]);
    $services->get(HeatmapController::class)->tag('ferienpass_admin.dashboard_widget', ['priority' => 100]);
    $services->get(GanttController::class)->tag('ferienpass_admin.dashboard_widget', ['priority' => 10]);

    // Aliases for autowiring
    $services->alias(Helper::class, 'knp_menu.helper');

    $services->get(MenuBuilder::class)
        ->tag('knp_menu.menu_builder', ['method' => 'primaryNavigation', 'alias' => 'admin_primary'])
        ->tag('knp_menu.menu_builder', ['method' => 'secondaryNavigation', 'alias' => 'admin_secondary'])
        ->tag('knp_menu.menu_builder', ['method' => 'userNavigation', 'alias' => 'host_user_navigation'])
        ->tag('knp_menu.menu_builder', ['method' => 'offerActions', 'alias' => 'host_offer_actions'])
        ->tag('knp_menu.menu_builder', ['method' => 'participantListActions', 'alias' => 'host_participant_list_actions'])
    ;

    $services->get(ActionsBuilder::class)
        ->tag('knp_menu.menu_builder', ['method' => 'actions', 'alias' => 'admin_list_actions'])
    ;

    // Per-scope section component locators. SectionComponentPass walks every
    // service tagged ferienpass.admin.section_component and buckets them by
    // the static getSectionScope(); each controller is wired to the locator
    // that matches its own entity.
    $services->set('ferienpass.admin.section_component_locator.offer', \Symfony\Component\DependencyInjection\ServiceLocator::class)
        ->args([[]])
        ->tag('container.service_locator')
    ;
    $services->set('ferienpass.admin.section_component_locator.edition', \Symfony\Component\DependencyInjection\ServiceLocator::class)
        ->args([[]])
        ->tag('container.service_locator')
    ;

    $services->get(OfferEditController::class)
        ->arg('$sectionComponents', service('ferienpass.admin.section_component_locator.offer'))
    ;

    $services->get(EditionsEditController::class)
        ->arg('$sectionComponents', service('ferienpass.admin.section_component_locator.edition'))
    ;

    $services->set(StringLoaderExtension::class);
};
