import { DOCUMENT } from '@angular/common';
import { AfterViewInit, Component, Inject, NgZone, OnDestroy, OnInit } from '@angular/core';
import AOS from 'aos';
import { environment } from 'environments/environment';
import { I18NService } from '../../core/i18n/service';
import { BIXI_I18N_TOKEN } from '../../core/i18n/service.type';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  host: {
    '[class.home-wrapper]': 'true'
  }
})
export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
  list = [
    { type: 'basic.png' },
    { type: 'pro.png' }
  ];

  proRef = 'http://bixi-pro.datagrand.com/?utm_source=bixi&utm_medium=home';

  introduceList = [
    {
      title: 'app.home.introduce.bixi', src: './assets/img/introduce-reuse.svg',
      route: `/docs/getting-started/${this.i18n.zone}`,
      desc: 'app.home.introduce.bixi.desc', alt: 'app.home.introduce.bixi'
    },
    {
      title: 'app.home.introduce.bixi.pro', src: './assets/img/introduce-pro.svg',
      href: 'http://bixi-pro.datagrand.com/?utm_source=bixi&utm_medium=home',
      desc: 'app.home.introduce.bixi.pro.desc', alt: 'app.home.introduce.bixi.pro'
    },
    {
      title: 'app.home.introduce.bixi.cli', src: './assets/img/introduce-cli.svg',
      href: 'https://git.datagrand.com/frontend_utils/bixi_cli',
      desc: 'app.home.introduce.bixi.cli.desc', alt: 'app.home.introduce.bixi.cli'
    }
  ];

  featureList = [
    {
      title: 'app.home.feature.mature.design',
      src: './assets/img/feature-设计成熟.svg',
      desc: 'app.home.feature.mature.design.desc',
      cls: 'mature-design', alt: 'app.home.feature.mature.design'
    },
    {
      title: 'app.home.feature.stable.reliable',
      src: './assets/img/feature-稳定可靠.svg',
      desc: 'app.home.feature.stable.reliable.desc',
      cls: 'stable-reliable', alt: 'app.home.feature.stable.reliable'
    },
    {
      title: 'app.home.feature.strong.expansibility',
      src: './assets/img/feature-扩展性强.svg',
      desc: 'app.home.feature.strong.expansibility.desc',
      cls: 'strong-expansibility', alt: 'app.home.feature.strong.expansibility'
    },

    {
      title: 'app.home.feature.excellent.performance',
      src: './assets/img/feature-性能优异.svg',
      desc: 'app.home.feature.excellent.performance.desc',
      cls: 'excellent-performance', alt: 'app.home.feature.excellent.performance'
    },
    {
      title: 'app.home.feature.module.decoupling',
      src: './assets/img/feature-模块解耦.svg',
      desc: 'app.home.feature.module.decoupling.desc',
      cls: 'module-decoupling', alt: 'app.home.feature.module.decoupling'
    },
    {
      title: 'app.home.feature.rapid.development',
      src: './assets/img/feature-快速开发.svg',
      desc: 'app.home.feature.rapid.development.desc',
      cls: 'rapid-development', alt: 'app.home.feature.rapid.development'
    }
  ];

  consumerList = [
    { src: './assets/img/consumer-智能文本.svg', alt: '智能文本' },
    { src: './assets/img/consumer-智能搜索.svg', alt: '智能搜索' },
    { src: './assets/img/consumer-智能推荐.svg', alt: '智能推荐' },
    { src: './assets/img/consumer-财债通.svg', alt: '智能控制' },
    { src: './assets/img/consumer-客户洞察.svg', alt: '客户洞察' },
    { src: './assets/img/consumer-知识图谱.svg', alt: '知识图谱' },
    { src: './assets/img/consumer-事件分析.svg', alt: '事件分析' },
    { src: './assets/img/consumer-达观RPA.svg', alt: '达观RPA' },
    { src: './assets/img/consumer-新华财经.svg', alt: '新华财经' },
    { src: './assets/img/consumer-中国银行.svg', alt: '中国银行' }
  ];

  constructor(@Inject(BIXI_I18N_TOKEN) public i18n: I18NService, private ngZone: NgZone, @Inject(DOCUMENT) private doc: Document) { }

  private get body(): HTMLElement {
    return this.doc.querySelector('body') as HTMLElement;
  }

  idProd = environment.production;

  ngAfterViewInit(): void {
    this.ngZone.runOutsideAngular(() => AOS.init());
  }

  ngOnInit() {
    this.body.classList.add(`index-page`);
  }

  ngOnDestroy(): void {
    this.body.classList.remove(`index-page`);
  }
}
