


using System;
using System.Web;

using ASC.Data.Storage;
using ASC.Web.Core.Files;
using ASC.Web.Studio.Utility;

namespace ASC.Web.Sample.Classes
{
    public class PathProvider
    {
        public static readonly string BaseVirtualPath;
        public static readonly string BaseAbsolutePath;

        static PathProvider()
        {
            BaseVirtualPath = "~/Products/Sample/";
            try
            {
                BaseAbsolutePath = CommonLinkUtility.ToAbsolute(BaseVirtualPath);
            }
            catch (Exception)
            {
                BaseAbsolutePath = BaseVirtualPath;
            }
        }

        public static string GetFileStaticRelativePath(String fileName)
        {
            var ext = FileUtility.GetFileExtension(fileName);
            switch (ext)
            {
                case ".js":
                    return VirtualPathUtility.ToAbsolute("~/Products/Sample/js/" + fileName);
                case ".png":
                    return WebPath.GetPath("/Products/Sample/App_Themes/default/images/" + fileName);
                case ".ascx":
                    return CommonLinkUtility.ToAbsolute("~/Products/Sample/Controls/" + fileName);
                case ".css":
                case ".less":
                    return VirtualPathUtility.ToAbsolute("~/Products/Sample/App_Themes/default/css/" + fileName);
            }
            return fileName;
        }

        public static string GetVirtualPath(string physicalPath)
        {
            var rootpath = HttpContext.Current.Server.MapPath("~/");
            return "~/" + physicalPath.Replace(rootpath, string.Empty).Replace("\\", "/");
        }
    }
}