import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';

class ZtBottomSheetPicker extends StatelessWidget {
  final Function? onChanged;
  FixedExtentScrollController firstLevelControlller =
      FixedExtentScrollController();
  FixedExtentScrollController secondLevelController =
      FixedExtentScrollController();
  FixedExtentScrollController thirdLevelController =
      FixedExtentScrollController();
  final List<Widget> firstLevel;
  final List<Widget>? secondLevel;
  final List<Widget>? thirdLevel;
  double? itemHeight;
  double? popupHeight;
  final String title;
  ZtBottomSheetPicker(
      {super.key,
      this.title = '请选择',
      required this.onChanged,
      required this.firstLevel,
      this.secondLevel,
      this.thirdLevel,
      this.itemHeight = 80.0,
      this.popupHeight = 400.0});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenAdaper.height(popupHeight!),
      color: Colors.white,
      child: Column(
        children: [
          Row(
            children: [
              TextButton(
                  onPressed: () {
                    Get.back();
                  },
                  child: Text(
                    '取消',
                    style: TextStyle(fontSize: ScreenAdaper.sp(25)),
                  )),
              Expanded(
                  child: Center(
                child: Text(
                  title,
                  style: TextStyle(
                      color: AppTheme.nearlyBlack,
                      fontSize: ScreenAdaper.sp(25),
                      decoration: TextDecoration.none),
                ),
              )),
              TextButton(
                  onPressed: () {
                    Get.back();
                    onChanged!(
                      firstLevelControlller.selectedItem,
                      (secondLevel ?? []).isNotEmpty
                          ? secondLevelController.selectedItem
                          : -1,
                      (thirdLevel ?? []).isNotEmpty
                          ? thirdLevelController.selectedItem
                          : -1,
                    );
                  },
                  child: Text(
                    '确定',
                    style: TextStyle(fontSize: ScreenAdaper.sp(25)),
                  ))
            ],
          ),
          Expanded(
              child: Row(
            children: <Widget>[
              Expanded(
                child: CupertinoPicker(
                  scrollController: firstLevelControlller,
                  itemExtent: ScreenAdaper.height(itemHeight!),
                  onSelectedItemChanged: (int index) {},
                  children: firstLevel,
                ),
              ),
              if ((secondLevel ?? []).isNotEmpty)
                Expanded(
                  child: CupertinoPicker(
                    scrollController: secondLevelController,
                    itemExtent: ScreenAdaper.height(itemHeight!),
                    onSelectedItemChanged: (int index) {},
                    children: secondLevel!,
                  ),
                ),
              if ((thirdLevel ?? []).isNotEmpty)
                Expanded(
                  child: CupertinoPicker(
                    scrollController: thirdLevelController,
                    itemExtent: ScreenAdaper.height(itemHeight!),
                    onSelectedItemChanged: (int index) {},
                    children: thirdLevel!,
                  ),
                ),
            ],
          ))
        ],
      ),
    );
  }
}
