import {observable, action} from 'mobx';
import {WeaTools, WeaLocaleProvider} from 'ecCom';

const {getLabel} = WeaLocaleProvider;

export default class HomePageStore {
    // 加载状态
    @observable loading = false;
    
    // 功能集成
    @observable functionals = [];
    
    // 产品集成
    @observable products = [];

    // 统一认证中心
    @observable auth_center_server = [];
    @observable auth_center_client = [];
    @observable auth_center_other = [];

    // weatab的数据
    @observable tabDatas = [{
      key: "0",
      title: getLabel(32213, '功能集成')
    }, {
      key: "1",
      title: getLabel(32300, '产品集成')
    }, {
      key: "2",
      title: getLabel(381908, '统一认证中心')
    }];
    @observable selectedKey = "0";
    // 展示的数据格式化为数组
    @observable showDatas = [];

    @action
    getApps() {
        this.loading = true;
        this.selectedKey = "0";
        this.showDatas = [];
        WeaTools.callApi('/api/integration/homepage/getApps', 'GET', {}).then(result => {
            const {data} = result;
            data && data.functional && (this.functionals = data.functional);
            data && data.product && (this.products = data.product);
            data && data.auth_center_server && (this.auth_center_server = data.auth_center_server);
            data && data.auth_center_client && (this.auth_center_client = data.auth_center_client);
            data && data.auth_center_other && (this.auth_center_other = data.auth_center_other);
            // this.showDatas = {
            //   "0": {
            //     datas: data.functional 
            //   },
            //   "1": {
            //     datas: data.product
            //   }, 
            //   "2": {
            //     datas: [],
            //     child: [{
            //       key: "0",
            //       title: getLabel('516457','认证服务管理'),
            //       datas: data.auth_center_server || []
            //     }, {
            //       key: "1",
            //       title: getLabel('516740','认证接入管理'),
            //       datas: data.auth_center_client || []
            //     }, {
            //       key: "2",
            //       title: getLabel('25740','其他'),
            //       datas: data.auth_center_other || []
            //     }]
            //   }
            // };
            this.loading = false;
        });
    }
}