// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Components;
using SelmoStudio.Hmi.Server.Alarms.Model;
using System.Globalization;

namespace SelmoStudio.Hmi.Server.Alarms.Components
{
    public partial class LastActiveAlarmComponent
    {
        private const int MaxTitleLength = 20;

        [Inject]
        private NavigationManager _navigationManager { get; set; }

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

        [Parameter]
        public Alarm LastActiveAlarm { get; set; }

        private string GetLastActiveAlarmTitleSubstring()
        {
            if (LastActiveAlarm.Title?.Length > MaxTitleLength)
            {
                return $"{LastActiveAlarm.Title.Substring(0, MaxTitleLength)}...";
            }

            return LastActiveAlarm.Title ?? string.Empty;
        }

        private string GetLastActiveAlarmDate()
        {
            return LastActiveAlarm.Created.DateTime.ToShortDateString().ToString(CultureInfo.DefaultThreadCurrentUICulture);
        }

        private string GetLastActiveAlarmTime()
        {
            return LastActiveAlarm.Created.DateTime.ToLongTimeString().ToString(CultureInfo.DefaultThreadCurrentUICulture);
        }

        private void OnClick()
        {
            _navigationManager.NavigateTo("/alarmList");
        }
    }
}