import 'package:cs_resources/generated/l10n.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:router/ext/auto_router_extensions.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_appbar.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_text_view.dart';
import 'package:plugin_platform/platform_export.dart';

import '../../router/page/auth_page_router.dart';
import 'tenant_doc_view_model.dart';

@RoutePage()
class TenantDocPage extends HookConsumerWidget {
  TenantDocPage({Key? key}) : super(key: key);

  //启动当前页面
  static void startInstance({BuildContext? context}) {
    if (context != null) {
      context.router.push(TenantDocPageRoute());
    } else {
      appRouter.push(TenantDocPageRoute());
    }
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final viewModel = ref.read(tenantDocViewModelProvider.notifier);
    final state = ref.watch(tenantDocViewModelProvider);

    return Scaffold(
      appBar: MyAppBar.appBar(
        context,
        "",
      ),
      backgroundColor: context.appColors.backgroundDefault,
      body: Container(
        padding: const EdgeInsets.symmetric(horizontal: 15),
        width: double.infinity,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SingleChildScrollView(
                scrollDirection: Axis.vertical,
                physics: const BouncingScrollPhysics(),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    MyTextView(
                      S.current.upload_documents,
                      fontSize: 23.5,
                      marginTop: 23,
                      marginBottom: 21,
                      textAlign: TextAlign.center,
                      isFontMedium: true,
                      textColor: context.appColors.textBlack,
                    ),
                    MyTextView(
                      state.type == "1" ? S.current.upload_doc_owner_desc : S.current.upload_doc_tenant_desc,
                      fontSize: 15,
                      marginBottom: 24,
                      isFontMedium: true,
                      textColor: context.appColors.textBlack,
                    ),
                    ImageNineGrid(
                      isSelectEnable: true,
                      maxImages: 3,
                      spacing: 10,
                      aspectRatio: 108 / 80,
                      initialImages: [],
                      onImagesChanged: (list) {
                        viewModel.setDocList(list);
                      },
                    ),
                  ],
                )).expanded(),

            //底部的按钮
            MyButton(
              onPressed: viewModel.submitDoc,
              text: S.current.next,
              textColor: Colors.white,
              backgroundColor: context.appColors.btnBgDefault,
              fontWeight: FontWeight.w500,
              type: ClickType.throttle,
              fontSize: 16,
              minHeight: 50,
              radius: 5,
            ).marginOnly(top: 50, bottom: 50, left: 18, right: 18),
          ],
        ),
      ),
    );
  }
}
