import shieldData from '../data/shield';

import user from '$utils/control/user';

import {UserConfigType} from '$utils/control/user/const';


export default <LibMixins>{

    data(){
        return {
            shieldData,
            shieldConfig: user.getData(UserConfigType.shield)
        }
    },

    computed:{
      shieldAll(){

          let i = 0;
          for (let key in this.shieldConfig) {
              if (this.shieldConfig.hasOwnProperty(key) && this.shieldConfig[key]) {
                  i++;
              }
          }

          return i >= this.shieldData.length;
      }
    },

    methods:{

        changeShieldConfig(index){
            this.shieldConfig[shieldData[index].key] = !this.shieldConfig[shieldData[index].key];
            return user.setDataItem(UserConfigType.shield, shieldData[index].key,this.shieldConfig[shieldData[index].key]);
        },

        triggerShield(){
            if (this.shieldAll) {
                this.shieldConfig = {};
            } else {
                for (let key in this.shieldData) {
                    if (this.shieldData.hasOwnProperty(key)) {
                        this.shieldConfig[this.shieldData[key].key] = true;
                    }
                }
            }
            return user.setData(UserConfigType.shield, this.shieldConfig);
        }

    }





}
