package com.bbitcn.silk.ui.activity;

import android.content.Intent;

import com.bbitcn.silk.base.BaseActivity;
import com.bbitcn.silk.databinding.ActivityUserBinding;
import com.bbitcn.silk.ui.dialog.ConfirmDialog;
import com.bbitcn.silk.ui.dialog.SpinnerDialog;
import com.bbitcn.silk.ui.dialog.TipsDialog;
import com.bbitcn.silk.utils.MMKVUtil;
import com.bbitcn.silk.utils.MyUtil;
import com.bbitcn.silk.utils.database.TareDataBase;
import com.bbitcn.silk.utils.global.Global;
import com.bbitcn.silk.utils.global.SpinnerList;
import com.blankj.utilcode.util.ActivityUtils;

/**
 * @Description 用户中心界面
 * @Author DuanKaiji
 * @CreateTime 2024年03月27日 15:12
 */
public class UserActivity extends BaseActivity<ActivityUserBinding, UserActivityPresenter> {

    @Override
    public void initView() {
        binding.tvVersion.setText(MyUtil.getVersionName(mContext));
        binding.tvAuthInfo.setText(Global.getCompanyId());
        binding.tvUnit.setText(Global.getUnit());
        binding.tvUserInfo.setText(Global.getUserName());
        binding.tvCompanyName.setText(Global.getCompanyName());
        binding.tvStationName.setText(Global.getStationName());
    }

    @Override
    public void initListener() {
        super.initListener();
        // 返回
        binding.ivBack.setOnClickListener(v -> finish());
        // 退出登录
        binding.btnLogOut.setOnClickListener(v -> {
            new ConfirmDialog(mContext, "退出登录", "确定退出登录吗？", () -> {
                MMKVUtil.put(Global.TOKEN, null);
                MMKVUtil.put(Global.PASSWORD, null);
                ActivityUtils.finishAllActivities();
                startActivity(new Intent(mContext, LoginActivity.class));

            }).show();
        });
        binding.clUnit.setOnClickListener(view -> new SpinnerDialog(mContext, "默认定价单位", "请选择单位", SpinnerList.UNIT, selString -> {
            MMKVUtil.put(Global.UNIT, selString);
            binding.tvUnit.setText(selString);
            new TipsDialog(mContext, "设置成功").show();
        }).show());
        binding.clAbout.setOnClickListener(v -> startActivity(new Intent(mContext, AboutActivity.class)));
        binding.clClear.setOnClickListener(v -> {
            TareDataBase.removeCatch();
            successTips("已清空缓存");
        });
    }

}
