using DotVVM.Framework.Configuration;
using DotVVM.Framework.ResourceManagement;
using DotVVM.Framework.Routing;
using DotVVM.Framework.Controls.Bootstrap;

namespace ElectroShop
{
    public class DotvvmStartup : IDotvvmStartup
    {
        // For more information about this class, visit https://dotvvm.com/docs/tutorials/basics-project-structure
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.AddBusinessPackConfiguration();
            config.AddBootstrapConfiguration(new DotvvmBootstrapOptions
            {
                BootstrapCssUrl = "~/lib/bootstrap/dist/css/bootstrap.min.css",
                BootstrapJsUrl = "~/lib/bootstrap/dist/js/bootstrap.min.js"
            });
            ConfigureRoutes(config, applicationPath);
            ConfigureControls(config, applicationPath);
            ConfigureResources(config, applicationPath);
        }

        private void ConfigureRoutes(DotvvmConfiguration config, string applicationPath)
        {

            config.RouteTable.Add("Default", "", "Views/default.dothtml");
            config.RouteTable.Add("UserManagement", "UserManagement", "Views/UserManagement.dothtml");
            config.RouteTable.Add("User_Create", "user/create", "Views/user/Create.dothtml");
            config.RouteTable.Add("User_Edit", "user/edit/{Username}", "Views/user/Edit.dothtml", new { Username = "" });
            config.RouteTable.Add("User_Delete", "user/delete/{Username}", "Views/user/Delete.dothtml", new { Username = "" });
            config.RouteTable.Add("CathegoriesManagement", "CathegoriesManagement", "Views/CathegoriesManagement.dothtml");
            config.RouteTable.Add("ElectronicComponentManagement", "ElectronicComponentManagement", "Views/ElectronicComponentManagement.dothtml");
            config.RouteTable.Add("ElectronicComponentCathegory_Create", "cathegory/create", "Views/ElectronicComponentCathegory/Create.dothtml");
            config.RouteTable.Add("ElectronicComponent_Create", "component/create", "Views/ElectronicComponent/Create.dothtml");
            config.RouteTable.Add("ElectronicComponent_Edit", "component/edit/{Id}", "Views/ElectronicComponent/Edit.dothtml", new { Id = 0 });
            config.RouteTable.Add("ElectronicComponent_Detail", "component/detail/{Id}", "Views/ElectronicComponent/Detail.dothtml", new { Id = 0 });
            config.RouteTable.Add("ElectronicComponent_Delete", "component/delete/{Id}", "Views/ElectronicComponent/Delete.dothtml", new { Id = 0 });
            config.RouteTable.AutoDiscoverRoutes(new DefaultRouteStrategy(config));
        }

        private void ConfigureControls(DotvvmConfiguration config, string applicationPath)
        {
            // register code-only controls and markup controls
        }

        private void ConfigureResources(DotvvmConfiguration config, string applicationPath)
        {
            // register custom resources and adjust paths to the built-in resources
            config.Resources.Register("Styles", new StylesheetResource()
            {
                Location = new UrlResourceLocation("~/styles.css")
            });
        }
    }
}
