using DevExpress.Entity.Model.Metadata;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Pages.Media;
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI
{
    public partial class MainPage : ContentPage
    {

        private IUserService _userService;
        private UserDTO _currentUser;

        public MainPage(IUserService userService)
        {
            InitializeComponent();
            _userService = userService;
        }

        private void SetInfo()
        {
            _currentUser = _userService.GetCurrentUser();
            DeviceId.Text = $"{_userService.DeviceId}";
            UserInfo.Text = $"{_currentUser?.LastName} {_currentUser?.FirstName}";
        }
        override protected async void OnAppearing()
        {
            base.OnAppearing();
            SetInfo();
            if (_currentUser != null)
            {
                AdminFrame.IsVisible = false;
                foreach (var role in _currentUser?.RoleDTO)
                {
                    if (role.IsAdmin) AdminFrame.IsVisible = true;

                }
            }


        }
        private async void OnButtonAction(object sender, EventArgs e)
        {
        }
        private void OnButtonDownloadAPK(object sender, EventArgs e)
        {
            Shell.Current.GoToAsync("//DownloadAPKPage");
        }
        private async void OnButtonGetUser(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new CaptureImagePage());
        }
        private async void OnButtonNFCTest(object sender, EventArgs e)
        {
            await Shell.Current.GoToAsync("//NFCTestPage");
        }
        private async void OnButtonBaseStock(object sender, EventArgs e)
        {
            await Shell.Current.GoToAsync("//BaseStockPage");
        }
        private void OnButtonLogout(object sender, EventArgs e)
        {
            _userService.SetCurrentUser(null);
            SecureStorage.Default.Remove("WFCUser");
            SecureStorage.Default.Remove("AuthToken");
            Shell.Current.GoToAsync("//LoginPage");
        }
        private void OnButtonSync(object sender, EventArgs e)
        {
            Shell.Current.GoToAsync("//SyncPage");
        }
        private async void OnButtonCheckList(object sender, EventArgs e)
        {
            await Shell.Current.GoToAsync("//CheckListPage");
        }
    }

}
