import 'package:app_settings/app_settings.dart';
import 'package:eitc_erm_dental_flutter/funcs.dart';
import 'package:eitc_erm_dental_flutter/generated/assets.dart';
import 'package:eitc_erm_dental_flutter/widget/main_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///未连接界面
class UnconnectedView extends StatelessWidget {
  const UnconnectedView({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
            child: SingleChildScrollView(
          child: Column(
            children: [
              _getTitleText(context),
              SizedBox(
                height: 20.h,
              ),
              _getDesc(context, getS().notConnectDesc1, [
                Assets.imagesUnconnectDescImg11,
                Assets.imagesUnconnectDescImg12,
                Assets.imagesUnconnectDescImg13,
              ]),
              SizedBox(
                height: 16.h,
              ),
              _getDesc(context, getS().notConnectDesc2, [
                Assets.imagesUnconnectDescImg21,
                Assets.imagesUnconnectDescImg22,
                Assets.imagesUnconnectDescImg23,
              ]),
            ],
          ),
        )),
        Container(
          padding: EdgeInsets.fromLTRB(16.w, 20.h, 16.w, 34.h),
          width: double.infinity,
          child: MainButton(
            onPressed: () => _onConnect(context),
            text: getS().clickToConnect,
          ),
        ),
      ],
    );
  }

  Widget _getTitleText(BuildContext context) {
    return Column(
      children: [
        SizedBox(
          height: 16.h,
        ),
        Image.asset(
          Assets.imagesUnconnectIcon,
          width: 120.w,
          height: 88.h,
        ),
        SizedBox(
          height: 8.h,
        ),
        Text(
          getS().waitingConnectDevice,
          style: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp),
        ),
      ],
    );
  }

  Widget _getDesc(BuildContext context, String text, List<String> imgs) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        children: [
          Text(text),
          SizedBox(
            height: 12.h,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: imgs
                .map((s) => Image.asset(
                      s,
                      width: 104.w,
                      height: 136.h,
                      fit: BoxFit.fill,
                    ))
                .toList(),
          )
        ],
      ),
    );
  }

  void _onConnect(BuildContext context) async {
    AppSettings.openAppSettings(
        type: AppSettingsType.wifi, asAnotherTask: true);
  }
}
