import { Component, OnInit } from '@angular/core';
import { GeneralHttpService } from '@core';
import { CacheService } from '@delon/cache';
import { environment } from '@env/environment';

@Component({
  selector: 'layout-passport',
  templateUrl: './passport.component.html',
  styleUrls: ['./passport.component.less']
})
export class LayoutPassportComponent implements OnInit {
  links = [
    {
      title: '帮助',
      href: ''
    },
    {
      title: '隐私',
      href: ''
    },
    {
      title: '条款',
      href: ''
    }
  ];

  styleMessage: any = {};
  logoSrc = '';
  loginTitle = '';
  loginicon = '';

  constructor(private httpUtils: GeneralHttpService, public srv: CacheService) {}

  ngOnInit(): void {
    const queryInfos = { enabled: 'Y' };
    let loginConfig = this.srv.get('formData-sys_login_config', { mode: 'none', type: 'm' });
    if (loginConfig) {
      this.handleLoginConfig(loginConfig);
    } else {
      this.httpUtils.getLoginConfigList(queryInfos).subscribe(res => {
        if (res) {
          if (res.data.length > 0) {
            loginConfig = res.data[0];
            const urls = loginConfig.loginbackgroud.split('-;-');
            // 缓存
            this.srv.set('formData-sys_login_config', loginConfig, { type: 'm' });
            this.handleLoginConfig(loginConfig);
          }
        }
      });
    }
  }

  /* #region  处理登录页配置 */
  handleLoginConfig(loginConfig: any) {
    if (loginConfig.roption) {
      const option = JSON.parse(loginConfig.roption);
      console.log('option', option);
      //
      if (option?.loginRight?.width && option?.loginLeft?.display && option.loginLeft.display === 'none') {
        option.loginRight.width = 'auto';
        option.loginRight.padding = '0 64px';
      }
      if (option?.myStyles) {
        delete option.myStyles;
      }
      if (option?.loginRight) {
        option.loginRight.width = '100%';
        option.loginRight.background = 'rgb(0,0,0,0)';
      }
      delete option.loginContainer.height;
      delete option.loginContainer.width;
      this.styleMessage = option;
    }
    if (loginConfig.logintitile) {
      this.loginTitle = loginConfig.logintitile;
    }
  }
  /* #endregion */
}
