services:
    oro_dashboard.config_resolver:
        class: Oro\Component\Config\Resolver\SystemAwareResolver
        arguments:
            - '@service_container'

    oro_dashboard.widget_config_visibility_filter:
        class: Oro\Bundle\DashboardBundle\Filter\WidgetConfigVisibilityFilter
        arguments:
            - '@security.authorization_checker'
            - '@oro_dashboard.config_resolver'
            - '@oro_featuretoggle.checker.feature_checker'
        public: false

    oro_dashboard.widget_configs:
        class: Oro\Bundle\DashboardBundle\Model\WidgetConfigs
        arguments:
            - '@oro_dashboard.config_provider'
            - '@oro_dashboard.config_resolver'
            - '@doctrine.orm.entity_manager'
            - '@oro_dashboard.widget_config_value.provider'
            - '@translator'
            - '@event_dispatcher'
            - '@oro_dashboard.widget_config_visibility_filter'
            - '@request_stack'

    Oro\Bundle\DashboardBundle\Model\WidgetConfigs:
        alias: 'oro_dashboard.widget_configs'

    oro_dashboard.manager:
        class: Oro\Bundle\DashboardBundle\Model\Manager
        public: true
        arguments:
            - '@oro_dashboard.factory'
            - '@doctrine.orm.entity_manager'
            - '@oro_security.acl_helper'
            - '@security.token_storage'

    Oro\Bundle\DashboardBundle\Model\Manager:
        alias: oro_dashboard.manager

    oro_dashboard.factory:
        class: Oro\Bundle\DashboardBundle\Model\Factory
        lazy: true
        arguments:
            - '@oro_dashboard.config_provider'
            - '@oro_dashboard.manager.state'
            - '@oro_dashboard.widget_configs'
            - !tagged_iterator oro_dashboard.dashboard_type.config.provider

    oro_dashboard.dashboard_type.config.provider.widgets:
        class: Oro\Bundle\DashboardBundle\DashboardType\WidgetsDashboardTypeConfigProvider
        arguments:
            - '@oro_dashboard.config_provider'
        tags:
            - { name: oro_dashboard.dashboard_type.config.provider }

    oro_dashboard.manager.state:
        class: Oro\Bundle\DashboardBundle\Model\StateManager
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_security.token_accessor'

    Oro\Bundle\DashboardBundle\Model\StateManager:
        alias: oro_dashboard.manager.state

    oro_dashboard.config_provider:
        class: Oro\Bundle\DashboardBundle\Model\ConfigProvider
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/dashboards.php'
            - '%kernel.debug%'
            - '@event_dispatcher'

    Oro\Bundle\DashboardBundle\Model\ConfigProvider:
        alias: oro_dashboard.config_provider

    oro_dashboard.navigation_listener:
        class: Oro\Bundle\DashboardBundle\EventListener\NavigationListener
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_dashboard.manager'
        tags:
            - { name: kernel.event_listener, event: oro_menu.configure.application_menu, method: onNavigationConfigure }

    oro_dashboard.form.type.edit:
        class: Oro\Bundle\DashboardBundle\Form\Type\DashboardType
        arguments:
            - '@doctrine'
        tags:
            - { name: form.type, alias: "oro_dashboard" }

    oro_dashboard.form.type.select:
        class: Oro\Bundle\DashboardBundle\Form\Type\DashboardSelectType
        arguments:
            - '@oro_dashboard.manager'
        tags:
            - { name: form.type, alias: "oro_dashboard_select" }

    oro_dashboard.provider.widget_configuration_form_provider:
        class: Oro\Bundle\DashboardBundle\Provider\WidgetConfigurationFormProvider
        arguments:
            - '@oro_dashboard.config_provider'
            - '@form.factory'

    Oro\Bundle\DashboardBundle\Provider\WidgetConfigurationFormProvider:
        alias: oro_dashboard.provider.widget_configuration_form_provider

    oro_dashboard.datetime.helper:
        class: Oro\Bundle\DashboardBundle\Helper\DateHelper
        public: true
        arguments:
            - '@oro_locale.settings'
            - '@doctrine'
            - '@oro_security.acl_helper'

    Oro\Bundle\DashboardBundle\Helper\DateHelper:
        alias: oro_dashboard.datetime.helper

    oro_dashboard.event_listener.widget_configuration_load:
        class: Oro\Bundle\DashboardBundle\EventListener\WidgetConfigurationLoadListener
        arguments:
            - '@oro_datagrid.datagrid.manager.link'
            - '@oro_datagrid.datagrid.builder'
        tags:
            - { name: kernel.event_listener, event: oro_dashboard.widget_configuration_load, method: onWidgetConfigurationLoad, priority: 100 }

    oro_dashboard.event_listener.widget_items_load_data:
        class: Oro\Bundle\DashboardBundle\EventListener\WidgetItemsLoadDataListener
        tags:
            - { name: kernel.event_listener, event: oro_dashboard.widget_items_load_data, method: filterItemsByItemsChoice }
            - { name: kernel.event_listener, event: oro_dashboard.widget_items_load_data, method: filterItems }

    oro_dashboard.event_listener.widget_sort_by:
        class: Oro\Bundle\DashboardBundle\EventListener\WidgetSortByListener
        arguments:
            - '@oro_dashboard.widget_configs'
        abstract: true

    oro_dashboard.type.widget_jqueryselect2_hidden:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetEntityJquerySelect2HiddenType
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_form.autocomplete.search_registry'
            - '@oro_entity_config.provider.form'
            - '@oro_entity.doctrine_helper'
        tags:
            - { name: form.type, alias: oro_widget_entity_jqueryselect2_hidden }

    oro_dashboard.form.type.widget_date_range:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateRangeType
        arguments:
            - '@translator'
        tags:
            - { name: form.type, alias: "oro_type_widget_date_range" }

    oro_dashboard.form.type.current_date_widget_date_range:
        class: Oro\Bundle\DashboardBundle\Form\Type\CurrentDateWidgetDateRangeType
        arguments:
            - '@translator'
        tags:
            - { name: form.type }

    oro_dashboard.form.type.dependent_date_widget_date_range:
        class: Oro\Bundle\DashboardBundle\Form\Type\DependentDateWidgetDateRangeType
        arguments:
            - '@translator'
        tags:
            - { name: form.type }

    oro_dashboard.form.type.widget_datetime_range:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateTimeRangeType
        tags:
            - { name: form.type, alias: "oro_type_widget_datetime_range" }

    oro_dashboard.form.type.widget_date_range_value:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateRangeValueType
        tags:
            - { name: form.type, alias: "oro_type_widget_date_range_value" }

    oro_dashboard.form.type.widget_previous_date_range:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetPreviousDateRangeType
        tags:
            - { name: form.type, alias: "oro_type_widget_previous_date_range" }

    oro_dashboard.form.type.widget_widget_title:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetTitleType
        tags:
            - { name: form.type, alias: "oro_type_widget_title" }

    oro_dashboard.form.type.widget_items_choice:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetItemsChoiceType
        tags:
            - { name: form.type, alias: "oro_type_widget_items_choice" }

    oro_dashboard.form.type.widget_choice:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetChoiceType
        tags:
            - { name: form.type, alias: "oro_type_widget_choice" }

    oro_dashboard.form.type.widget_item:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetItemType
        tags:
            - { name: form.type, alias: oro_type_widget_item }

    oro_dashboard.form.type.widget_items:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetItemsType
        arguments:
            - '@oro_dashboard.event_listener.widget_items_form_subscriber'
        tags:
            - { name: form.type, alias: oro_type_widget_items }

    oro_dashboard.event_listener.widget_items_form_subscriber:
        class: Oro\Bundle\DashboardBundle\Form\EventListener\WidgetItemsFormSubscriber
        arguments:
            - '@oro_dashboard.widget_configs'
            - '@translator'

    oro_dashboard.widget_config_value.provider:
        class: Oro\Bundle\DashboardBundle\Provider\ConfigValueProvider
        arguments:
            - ~ # service locator for value converters

    oro_dashboard.widget_config_value.date_range.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\FilterDateRangeConverter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@oro_filter.expression.date.compiler'
            - '@translator'
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateRangeType }
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\CurrentDateWidgetDateRangeType }
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\DependentDateWidgetDateRangeType }

    oro_dashboard.widget_config_value.datetime_range.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\FilterDateTimeRangeConverter
        arguments:
            - '@oro_dashboard.widget_config_value.date_range.converter'
            - '@oro_dashboard.config_resolver'
            - '@oro_dashboard.datetime.helper'
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateTimeRangeType }

    oro_dashboard.widget_config_value.previous_date_range.converter:
          class: Oro\Bundle\DashboardBundle\Provider\Converters\PreviousFilterDateRangeConverter
          parent: oro_dashboard.widget_config_value.date_range.converter
          tags:
              - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetPreviousDateRangeType }

    oro_dashboard.widget_config_value.widget_title.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetTitleConverter
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetTitleType }

    oro_dashboard.widget_config_value.widget_items_choice.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetItemsChoiceTypeConverter
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetItemsChoiceType }

    oro_dashboard.widget_config_value.widget_choice.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetChoiceTypeConverter
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetChoiceType }

    oro_dashboard.widget_config_value.widget_sort_by.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetSortByConverter
        arguments:
            - '@oro_entity_config.provider.entity'
            - '@translator'
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\DashboardBundle\Form\Type\WidgetSortByType }

    oro_dashboard.widget_config_value.widget_entity_select.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetEntitySelectConverter
        abstract: true
        arguments:
            - '@oro_security.acl_helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_entity.doctrine_helper'
            - '@doctrine.orm.entity_manager'

    oro_dashboard.widget_config_value.widget_enum_select.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetEnumSelectConverter
        parent: oro_dashboard.widget_config_value.widget_entity_select.converter
        abstract: true

    oro_dashboard.form.type.widget_date:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateType
        tags:
            - { name: form.type, alias: "oro_type_widget_date" }

    oro_dashboard.form.type.widget_sort_by:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetSortByType
        arguments:
            - '@oro_entity.entity_field_provider'
        tags:
            - { name: form.type, alias: oro_type_widget_sort_by }

    # BigNumber
    oro_dashboard.provider.big_number.processor:
        class: Oro\Bundle\DashboardBundle\Provider\BigNumber\BigNumberProcessor
        public: true
        arguments:
            - ~ # service locator for value providers
            - '@oro_dashboard.provider.big_number.formatter'
            - '@oro_dashboard.provider.big_number.date_helper'

    oro_dashboard.provider.big_number.formatter:
        class: Oro\Bundle\DashboardBundle\Provider\BigNumber\BigNumberFormatter
        arguments:
            - '@oro_locale.formatter.number'

    oro_dashboard.provider.big_number.date_helper:
        class: Oro\Bundle\DashboardBundle\Provider\BigNumber\BigNumberDateHelper
        arguments:
            - '@doctrine'
            - '@oro_security.acl_helper'
            - '@oro_locale.settings'

    oro_dashboard.filter.date_range:
        class: Oro\Bundle\DashboardBundle\Filter\DateRangeFilter
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
            - '@oro_filter.date_filter_utility'
            - '@oro_locale.settings'
            - '@oro_filter.utils.date_filter_modifier'

    oro_dashboard.filter.date_filter_processor:
        class: Oro\Bundle\DashboardBundle\Filter\DateFilterProcessor
        arguments:
            - '@oro_dashboard.filter.date_range'
            - '@oro_filter.utils.date_filter_modifier'
            - '@oro_locale.settings'

    # Twig extension
    oro_dashboard.twig.extension:
        class: Oro\Bundle\DashboardBundle\Twig\DashboardExtension
        public: false
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_dashboard.form.type.widget_filter:
        class: Oro\Bundle\DashboardBundle\Form\Type\WidgetFilterType
        tags:
            - { name: form.type, alias: oro_dashboard_query_filter }

    oro_dashboard.config_extension.feature:
        class: Oro\Bundle\DashboardBundle\Configuration\FeatureConfigurationExtension
        tags:
            - { name: oro_feature.config_extension }

    oro_dashboard.widget_provider.filter_manager:
        class: Oro\Bundle\DashboardBundle\Filter\WidgetProviderFilterManager
        arguments:
            - !tagged_iterator oro_dashboard.widget_provider.filter

    oro_dashboard.widget_provider.filter.owners:
        class: Oro\Bundle\DashboardBundle\Filter\OwnersWidgetProviderFilter
        arguments:
            - '@oro_user.dashboard.owner_helper'
        tags:
            - { name: oro_dashboard.widget_provider.filter }

    oro_dashboard.listener.datagrid.dashboards-grid:
        class: Oro\Bundle\DashboardBundle\EventListener\DashboardTypeDatagridListener
        arguments:
            - "@doctrine"
            - "@translator"
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.dashboards-grid, method: onBuildBefore }
