import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/utils/date_time.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:fis_jsonrpc/services/researchEdition.m.dart';
import 'package:flyinsono/managers/interfaces/product_key.dart';
import 'package:get/get.dart';
import 'package:flyinsono/global.dart';

class AboutPart extends StatefulWidget {
  const AboutPart({super.key});

  @override
  State<AboutPart> createState() => _AboutPartState();
}

class _AboutPartState extends State<AboutPart> {
  var productKeyManager = Get.find<IProductKeyManager>();
  LicenseInfoDTO? licenseInfoDTO;
  @override
  void initState() {
    super.initState();
    _load();
  }

  void _load() async {
    licenseInfoDTO = await productKeyManager.getLicenseInfoAsync();
    if (licenseInfoDTO != null) {
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(child: Container()),
          SizedBox(height: 40),
          _buildLogo(),
          SizedBox(height: 40),
          _buildVersionInfo(),
          SizedBox(height: 40),
          _buildLicenseInfo(),
          SizedBox(height: 40),
          Expanded(child: Container()),
          _buildCopyrightInfo(),
          SizedBox(height: 20),
        ],
      ),
    );
  }

  Widget _buildLogo() {
    return Column(
      children: [
        Global.isVStationSlave
            ? Container(
                height: 120,
              )
            : Container(
                height: 120,
                child: ColorFiltered(
                  colorFilter:
                      ColorFilter.mode(LabColors.base600, BlendMode.srcIn),
                  child: Image.asset(
                    "assets/images/logo_icon.png",
                    filterQuality: FilterQuality.medium,
                    isAntiAlias: true,
                    fit: BoxFit.contain,
                  ),
                ),
              ),
        Text(
          "FLYINSONO LAB",
          style: TextStyle(
            fontSize: 36,
            fontWeight: FontWeight.w900,
            color: LabColors.text700,
          ),
        ),
      ],
    );
  }

  Widget _buildLicenseInfo() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(
          licenseInfoDTO?.licenseType == 1 ? "正式版" : "试用版",
          style: TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.bold,
            color: LabColors.text700,
          ),
        ),
        SizedBox(width: 10),
        if (licenseInfoDTO?.licenseType == 0)
          Text(
            "${DateTimeClass.getLocalTime(
              licenseInfoDTO!.expirationUtcDate!.toString(),
            )}",
            style: TextStyle(
              fontSize: 16,
              color: LabColors.text600,
            ),
          ),
      ],
    );
  }

  Widget _buildVersionInfo() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(
          "当前版本",
          style: TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.bold,
            color: LabColors.text700,
          ),
        ),
        SizedBox(width: 10),
        Text(
          "v1.0.0-beta",
          style: TextStyle(
            fontSize: 16,
            color: LabColors.text600,
          ),
        ),
      ],
    );
  }

  Widget _buildCopyrightInfo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text(
          "飞依诺科技股份有限公司",
          style: TextStyle(
            fontSize: 14,
            color: LabColors.base600,
          ),
        ),
        SizedBox(height: 5),
        Text(
          "@2017 Vinno Corporation. All rights reserved.",
          style: TextStyle(
            fontSize: 14,
            color: LabColors.base600,
          ),
        ),
      ],
    );
  }
}
