﻿
using System;
using MvvmCross.Core.ViewModels;
using OpenLearningPlayer.Shared.Auxiliary.Logger;

namespace OpenLearningPlayer.Shared.ViewModels
{
    public class StandartDialog_ViewModel : ViewModel_Base
    {
        public enum enButtons { ButtonOk = 1, ButtonYes = 2, ButtonNo = 4}

        private ILogger Logger;
        private INavigationService NavigationService;

        public ButtonModel ButtonOk { get { if (_ButtonOk == null) _ButtonOk = new ButtonModel(); return _ButtonOk; } set { Set(ref _ButtonOk, value); } }   private ButtonModel _ButtonOk;
        public ButtonModel ButtonYes { get { if (_ButtonYes == null) _ButtonYes = new ButtonModel();return _ButtonYes; } set { Set(ref _ButtonYes, value); } }    private ButtonModel _ButtonYes;
        public ButtonModel ButtonNo { get {if (_ButtonNo == null) _ButtonNo = new ButtonModel(); return _ButtonNo; } set { Set(ref _ButtonNo, value); } }  private ButtonModel _ButtonNo;

        public Label_Model TitleModel { get { if (_TitleModel == null) _TitleModel = new Label_Model(); return _TitleModel; } set { Set(ref _TitleModel, value); } } private Label_Model _TitleModel;

        public enButtons DialogResultButton { get { return _DialogResultButton; } set { Set(ref _DialogResultButton, value); } }  private enButtons _DialogResultButton;

        public string Title { get { return _Title; } set { Set(ref _Title, value); } }  private string _Title;
        public string Body { get { return _Body; } set { Set(ref _Body, value); } }  private string _Body;

        public StandartDialog_ViewModel(ILogger Logger_, INavigationService NavigationService_)
        {
            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
            }

            if (IsInDesignMode)
            {
                Title = "Hello!";
                Body = "How's it going ?";

            }

        }

        override public void OnNavigationOpenPage(ParametersOfForms param_)
        {
            StandartDialog_parameters param = (StandartDialog_parameters)param_;

            ButtonOk.Visibility  = (param.Buttons & (byte)enButtons.ButtonOk) > 0 ? VisualState.Visible : VisualState.Collapsed;
            ButtonYes.Visibility = (param.Buttons & (byte)enButtons.ButtonYes) > 0 ? VisualState.Visible: VisualState.Collapsed;
            ButtonNo.Visibility  = (param.Buttons & (byte)enButtons.ButtonNo) > 0 ? VisualState.Visible : VisualState.Collapsed;

            Title = param.Title;
            TitleModel.Visibility = string.IsNullOrEmpty(Title) ? VisualState.Collapsed : VisualState.Visible;
            Body = param.Body;
        }

        public override void CmdDispatcher(string cmd)
        {
            switch (cmd)
            {
                case "Ok":
                    DialogResultButton = enButtons.ButtonOk;
                    NavigationService.NavigateBack();
                    break;

                case "Yes":
                    DialogResultButton = enButtons.ButtonYes;
                    NavigationService.NavigateBack();
                    break;

                case "No":
                    DialogResultButton = enButtons.ButtonNo;
                    NavigationService.NavigateBack();
                    break;

                default:
                    throw new NotImplementedException();
            }
        }

    }
}
