import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:yumi/services/audio/rtc_manager.dart';

import '../../../../modules/room/seat/sc_seat_item.dart';



class RoomSeatWidget extends StatefulWidget {
  @override
  _RoomSeatWidgetState createState() => _RoomSeatWidgetState();
}

class _RoomSeatWidgetState extends State<RoomSeatWidget> {
  @override
  Widget build(BuildContext context) {
    return Consumer<RtcProvider>(
      builder: (context, ref, child) {
        return ref.roomWheatMap.length == 5
            ? _buildSeat5()
            : (ref.roomWheatMap.length == 10
                ? _buildSeat10()
                : (ref.roomWheatMap.length == 15
                    ? _buildSeat15()
                    : (ref.roomWheatMap.length == 20
                        ? _buildSeat20()
                        : Container(height: 180.w))));
      },
    );
  }

  _buildSeat5() {
    return Container(
      margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 0)),
              Expanded(flex: 1, child: SCSeatItem(index: 1)),
              Expanded(flex: 1, child: SCSeatItem(index: 2)),
              Expanded(flex: 1, child: SCSeatItem(index: 3)),
              Expanded(flex: 1, child: SCSeatItem(index: 4)),
            ],
          ),
        ],
      ),
    );
  }

  _buildSeat10() {
    return Container(
      margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 0)),
              Expanded(flex: 1, child: SCSeatItem(index: 1)),
              Expanded(flex: 1, child: SCSeatItem(index: 2)),
              Expanded(flex: 1, child: SCSeatItem(index: 3)),
              Expanded(flex: 1, child: SCSeatItem(index: 4)),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 5)),
              Expanded(flex: 1, child: SCSeatItem(index: 6)),
              Expanded(flex: 1, child: SCSeatItem(index: 7)),
              Expanded(flex: 1, child: SCSeatItem(index: 8)),
              Expanded(flex: 1, child: SCSeatItem(index: 9)),
            ],
          ),
        ],
      ),
    );
  }

  _buildSeat15() {
    return Container(
      margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 0)),
              Expanded(flex: 1, child: SCSeatItem(index: 1)),
              Expanded(flex: 1, child: SCSeatItem(index: 2)),
              Expanded(flex: 1, child: SCSeatItem(index: 3)),
              Expanded(flex: 1, child: SCSeatItem(index: 4)),
            ],
          ),
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 5)),
              Expanded(flex: 1, child: SCSeatItem(index: 6)),
              Expanded(flex: 1, child: SCSeatItem(index: 7)),
              Expanded(flex: 1, child: SCSeatItem(index: 8)),
              Expanded(flex: 1, child: SCSeatItem(index: 9)),
            ],
          ),
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 10)),
              Expanded(flex: 1, child: SCSeatItem(index: 11)),
              Expanded(flex: 1, child: SCSeatItem(index: 12)),
              Expanded(flex: 1, child: SCSeatItem(index: 13)),
              Expanded(flex: 1, child: SCSeatItem(index: 14)),
            ],
          ),
        ],
      ),
    );
  }

  _buildSeat20() {
    return Container(
      margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 0)),
              Expanded(flex: 1, child: SCSeatItem(index: 1)),
              Expanded(flex: 1, child: SCSeatItem(index: 2)),
              Expanded(flex: 1, child: SCSeatItem(index: 3)),
              Expanded(flex: 1, child: SCSeatItem(index: 4)),
            ],
          ),
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 5)),
              Expanded(flex: 1, child: SCSeatItem(index: 6)),
              Expanded(flex: 1, child: SCSeatItem(index: 7)),
              Expanded(flex: 1, child: SCSeatItem(index: 8)),
              Expanded(flex: 1, child: SCSeatItem(index: 9)),
            ],
          ),
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 10)),
              Expanded(flex: 1, child: SCSeatItem(index: 11)),
              Expanded(flex: 1, child: SCSeatItem(index: 12)),
              Expanded(flex: 1, child: SCSeatItem(index: 13)),
              Expanded(flex: 1, child: SCSeatItem(index: 14)),
            ],
          ),
          Row(
            children: [
              Expanded(flex: 1, child: SCSeatItem(index: 15)),
              Expanded(flex: 1, child: SCSeatItem(index: 16)),
              Expanded(flex: 1, child: SCSeatItem(index: 17)),
              Expanded(flex: 1, child: SCSeatItem(index: 18)),
              Expanded(flex: 1, child: SCSeatItem(index: 19)),
            ],
          ),
        ],
      ),
    );
  }
}
