using Model;
using Permission;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public class MyUiLabel : UILabel, IPermissionControl
{
    [Category("MyControl")]
    [Description("控件要求的权限等级")]
    [Browsable(true)]
    [DefaultValue(PermissionLevel.操作工)]
    public PermissionLevel RequiredPermissionLevel { get => requiredPermissionLevel; set { requiredPermissionLevel = value; IsPermissionGot = currentPermissionLevel >= RequiredPermissionLevel; HandlePermissionChange(); } }
    private PermissionLevel requiredPermissionLevel = PermissionLevel.操作工;

    [Category("MyControl")]
    [Description("当前登录的权限")]
    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public PermissionLevel CurrentPermissionLevel { get => currentPermissionLevel; set { currentPermissionLevel = value; IsPermissionGot = currentPermissionLevel >= RequiredPermissionLevel; HandlePermissionChange(); } }
    private PermissionLevel currentPermissionLevel = PermissionLevel.无权限;

    [Category("MyControl")]
    [Description("控件是否获得了权限")]
    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public bool IsPermissionGot { get; private set; }

    protected virtual void HandlePermissionChange()
    {
        this.Enabled = IsPermissionGot;
    }
}

