// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using SelmoStudio.Hmi.Server.SelmoHmi.Shared.WellKnownConstants;
using SelmoStudio.Hmi.Server.Shared.Resources;

namespace SelmoStudio.Hmi.Server.Shared.Components.BaseComponents
{
    public partial class TitleBarComponent
    {
        [Inject]
        private IStringLocalizer<HmiResource> _localizer { get; set; }

        [Parameter]
        public string Id { get; set; }

        [Parameter]
        public string ClassString { get; set; }

        [Parameter]
        public string StyleString { get; set; }

        [Parameter]
        public string TitleResourceKey { get; set; }

        [Parameter]
        public string TitleClassString { get; set; }

        [Parameter]
        public string TitleStyleString { get; set; }

        [Parameter]
        public RenderFragment Content { get; set; }

        private string GetClassString()
        {
            var baseClasses = "row headline-container";

            return string.IsNullOrEmpty(ClassString) ? baseClasses : $"{baseClasses} {ClassString}";
        }

        private string GetStyleString()
        {
            var baseStyle = $"padding: {WellKnownStyleConstants.GlobalSpacing}px 0px {WellKnownStyleConstants.GlobalSpacing}px 0px;";

            return string.IsNullOrEmpty(StyleString) ? baseStyle : $"{StyleString} {baseStyle}";
        }

        private string GetContentStyleString()
        {
            return $"min-height: {WellKnownStyleConstants.LargeElementHeight}px; height: auto;";
        }

        private string GetPageTitle()
        {
            var localizedString = _localizer.GetString(TitleResourceKey);

            return localizedString.ResourceNotFound ? string.Empty : localizedString.Value;
        }
    }
}
