package com.tjzhxx.union;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.tjzhxx.union.activity.LoginActivity;
import com.tjzhxx.union.activity.SetActivity;
import com.tjzhxx.union.entity.UserInfo;
import com.tjzhxx.union.public_store.ConstDefine;
import com.tjzhxx.union.system.BaseFragment;
import com.tjzhxx.union.system.WebviewActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.annotations.Nullable;

/**
 * 描述:
 *
 * @author yanghuaxiong
 * @create 2021/9/1 11:44 AM
 */

public class MyFragment extends BaseFragment {
    @BindView(R.id.avator)
    ImageView avator;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.image_member)
    ImageView imageMember;
    @BindView(R.id.image_member2)
    ImageView imageMember2;
    private UserInfo userInfo;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        userInfo = ConstDefine.userInfo;
        if (userInfo != null){
            name.setText(ConstDefine.userInfo.getWname());
            if (userInfo.getIsactive().equals("1")) {
                imageMember.setVisibility(View.VISIBLE);
            }else {
                imageMember.setVisibility(View.GONE);
            }
        }else {
            name.setText("点击登录/注册");
            imageMember.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.image_member, R.id.image_member2, R.id.set, R.id.personal, R.id.jz, R.id.px, R.id.js, R.id.wt, R.id.fl})
    public void onClick(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.image_member:
                imageMember.setVisibility(View.GONE);
                imageMember2.setVisibility(View.VISIBLE);
                break;
            case R.id.image_member2:
                imageMember.setVisibility(View.VISIBLE);
                imageMember2.setVisibility(View.GONE);
                break;
            case R.id.set:
                intent.setClass(getActivity(), SetActivity.class);
                startActivity(intent);
                break;
            case R.id.personal:
                if (userInfo == null){
                    intent.setClass(getActivity(), LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.jz:
                if (userInfo == null){
                    showSnackBar("请先登录");
                    return;
                }
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra("url", ConstDefine.HttpAdressH5+"/index.html#/userrescuelist");
                intent.putExtra("title", "我的救助");
                intent.putExtra("UserInfo",userInfo);
                startActivity(intent);
                break;
            case R.id.px:
                if (userInfo == null){
                    showSnackBar("请先登录");
                    return;
                }
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra("url", ConstDefine.HttpAdressH5+"/index.html#/usertrainlist?type=jnpx");
                intent.putExtra("title", "我的培训");
                intent.putExtra("UserInfo",userInfo);
                startActivity(intent);
                break;
            case R.id.js:
                if (userInfo == null){
                    showSnackBar("请先登录");
                    return;
                }
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra("url", ConstDefine.HttpAdressH5+"/index.html#/usertrainlist?type=ldjs");
                intent.putExtra("title", "我的竞赛");
                intent.putExtra("UserInfo",userInfo);
                startActivity(intent);
                break;
            case R.id.wt:
                if (userInfo == null){
                    showSnackBar("请先登录");
                    return;
                }
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra("url", ConstDefine.HttpAdressH5+"/index.html#/usertrainlist?type=wthd");
                intent.putExtra("title", "我的文体活动");
                intent.putExtra("UserInfo",userInfo);
                startActivity(intent);
                break;
            case R.id.fl:
                if (userInfo == null){
                    showSnackBar("请先登录");
                    return;
                }
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra("url", ConstDefine.HttpAdressH5+"/index.html#/usertrainlist?type=flyz");
                intent.putExtra("title", "我的法律援助");
                intent.putExtra("UserInfo",userInfo);
                startActivity(intent);
                break;
        }
    }
}
