import _ from 'lodash';
import searchFilterTpl from 'scripts/liveblog-marketplace/views/search-filter.ng1';

lbSearchFilter.$inject = ['MarketplaceActions'];

export default function lbSearchFilter(MarketplaceActions) {
    return {
        templateUrl: searchFilterTpl,
        scope: {
            filters: '=',
            terms: '=',
            title: '@',
            key: '@',
            id: '@',
        },
        link: function(scope) {
            scope.toggleFilter = function(type, value) {
                MarketplaceActions.toggleFilter(scope.filters, type, value);
            };

            scope.hasFilter = (type, value) => scope.filters
                && _.has(scope.filters, type)
                && scope.filters[type] === value;
        },
    };
}
