package com.danding.yang800;

import android.app.DatePickerDialog;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.danding.yang800.Fragment.MarketPlatformFrag;
import com.danding.yang800.Fragment.MarketShopFrag;
import com.danding.yang800.Util.LogUtil;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.yanzhenjie.sofia.Sofia;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MarketActivity extends BaseActivity {
    @BindView(R.id.market_platformLayout)
    RelativeLayout market_platformLayout;
    @BindView(R.id.market_shopLayout)
    RelativeLayout market_shopLayout;
    @BindView(R.id.market_backTv)
    TextView market_backTv;
    private FragmentManager fm = this.getFragmentManager();
    private FragmentTransaction ft;
    private MarketPlatformFrag platFrag;
    private MarketShopFrag shopFrag;
    @BindView(R.id.market_content)
    FrameLayout market_content;
    @BindView(R.id.market_platformTv)
    TextView market_platformTv;
    @BindView(R.id.market_platformIv)
    TextView market_platformIv;
    @BindView(R.id.market_shopTv)
    TextView market_shopTv;
    @BindView(R.id.market_shopIv)
    TextView market_shopIv;
    @BindView(R.id.market_createTv)
    TextView market_createTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        int type = StatusColorUtil.StatusBarLightMode(this);
//        if (type > 0) {
//            StatusColorUtil.setStatusBarColor(this, R.color.white);
//            StatusColorUtil.StatusBarLightMode(this, type);
//        }
        setContentView(R.layout.activity_market);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        initFrag();
    }

    private void initFrag() {
        ft = fm.beginTransaction();
        showPlat();
        ft.commit();
    }

    private void getDate() {
    }

    @SuppressWarnings("ResourceType")
    @OnClick({R.id.market_backTv, R.id.market_platformLayout, R.id.market_shopLayout, R.id.market_createTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.market_backTv:
                finish();
                break;
            case R.id.market_platformLayout:
                market_platformTv.setTextColor(ContextCompat.getColor(this, R.color.pink));
                market_platformIv.setVisibility(View.VISIBLE);
                market_shopTv.setTextColor(ContextCompat.getColor(this, R.color.gray));
                market_shopIv.setVisibility(View.INVISIBLE);
                market_createTv.setVisibility(View.GONE);
                ft = fm.beginTransaction();
                setSelected();
                showPlat();
                ft.commit();
                break;
            case R.id.market_shopLayout:
//                market_shopTv.setTextColor(ContextCompat.getColor(this, R.color.pink));
//                market_shopIv.setVisibility(View.VISIBLE);
//                market_platformTv.setTextColor(ContextCompat.getColor(this, R.color.gray));
//                market_platformIv.setVisibility(View.INVISIBLE);
//                market_createTv.setVisibility(View.GONE);
//                ft = fm.beginTransaction();
//                setSelected();
//                showShop();
//                ft.commit();
                break;
            case R.id.market_createTv:
                startActivity(EditMarketActivity.class);
                break;

        }
    }

    private void setSelected() {
        if (platFrag != null) {
            ft.hide(platFrag);
        }
        if (shopFrag != null) {
            ft.hide(shopFrag);
        }

    }

    private void showPlat() {
        if (platFrag == null) {
            platFrag = new MarketPlatformFrag(this);
            ft.add(R.id.market_content, platFrag);
        } else {
            ft.show(platFrag);
        }
    }

    private void showShop() {
        if (shopFrag == null) {
            shopFrag = new MarketShopFrag(this);
            ft.add(R.id.market_content, shopFrag);
        } else {
            ft.show(shopFrag);
        }
    }

}
