// This file has been autogenerated from a class added in the UI designer.

using System;
using MvvmCross.Platforms.Mac.Presenters.Attributes;
using MvvmCross.Platforms.Mac.Views;
using ObjCRuntime;
using Playground.Core.ViewModels;

namespace Playground.Mac
{
    [MvxFromStoryboard("Main")]
    [MvxWindowPresentation("ToolbarWindow", "Main", Width = 500)]
    public partial class WindowView : MvxViewController<WindowViewModel>
    {
        public WindowView(NativeHandle handle) : base(handle)
        {
            Title = "Window view";
        }

        public ToolbarWindow WindowController
        {
            get { return View.Window != null ? (ToolbarWindow)View.Window.WindowController : null; }
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var set = CreateBindingSet();
            set.Bind(btnClose).To(vm => vm.CloseCommand);
            set.Apply();
        }

        public override void ViewDidAppear()
        {
            base.ViewDidAppear();

            //WindowController.MenuItemSetting.State = ViewModel.IsItemSetting ? NSCellStateValue.On : NSCellStateValue.Off;

            var set = CreateBindingSet();
            set.Bind(WindowController.TextTitle).For(v => v.StringValue).To(vm => vm.Title);
            //set.Bind(WindowController.PopupModes).To(vm => vm.Mode);
            set.Bind(WindowController.MenuItemSetting).To(vm => vm.ToggleSettingCommand);
            set.Bind(WindowController.MenuItemSetting).For(v => v.State).To(vm => vm.IsItemSetting).OneWay();
            set.Apply();

            GC.Collect();       // test to make sure WindowController does not get removed prematurely
        }
    }
}
