﻿using Contrib.RewriteRules.Models;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization;

namespace Contrib.RewriteRules.Handlers {
    public class RedirectSettingsPartHandler : ContentHandler {
        public RedirectSettingsPartHandler(IRepository<RedirectSettingsPartRecord> repository) {
            T = NullLocalizer.Instance;
            Filters.Add(new ActivatingFilter<RedirectSettingsPart>("Site"));
            Filters.Add(StorageFilter.For(repository));
            Filters.Add(new TemplateFilterForRecord<RedirectSettingsPartRecord>("RewriteRulesSettings", "Parts/RewriteRules.RedirectSettings").Group("Rewrite Rules"));
        }

        public Localizer T { get; set; }

        protected override void GetItemMetadata(GetContentItemMetadataContext context) {
            if (context.ContentItem.ContentType != "Site")
                return;
            base.GetItemMetadata(context);
            context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Rewrite Rules")));
        }
    }
}