import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/modules/room/them/custom/room_theme_custom_page.dart';
import 'package:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
import 'package:yumi/ui_kit/components/sc_compontent.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/modules/store/store_route.dart';
import 'package:yumi/modules/user/my_items/theme/bags_theme_page.dart';
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';

import '../../../app/constants/sc_global_config.dart';

///房间主题
class RoomThemePage extends StatefulWidget {
  @override
  _RoomThemePageState createState() => _RoomThemePageState();
}

class _RoomThemePageState extends State<RoomThemePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<Widget> _pages = [];
  final List<Widget> _tabs = [];

  @override
  void initState() {
    super.initState();
    _pages.add(BagsThemePage());
    _pages.add(RoomThemeCustomPage());
    _tabController = TabController(length: _pages.length, vsync: this);
    _tabController.addListener(() {}); // 监听切换
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    _tabs.clear();
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.all));
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.custom));
    return Stack(
      children: [
        Image.asset(
          SCGlobalConfig.businessLogicStrategy.getLanguagePageBackgroundImage(),
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().screenHeight,
          fit: BoxFit.fill,
        ),
        Scaffold(
          resizeToAvoidBottomInset: false,
          backgroundColor: Colors.transparent,
          appBar: SocialChatStandardAppBar(
            title: SCAppLocalizations.of(context)!.theme,
            actions: [
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                child: Container(
                  padding: EdgeInsets.all(5.w),
                  margin: EdgeInsetsDirectional.only(end: 10.w),
                  child: Image.asset(
                    "sc_images/store/sc_icon_bag_shop.png",
                    width: 20.w,
                    height: 20.w,
                  ),
                ),
                onTap: () {
                  SCNavigatorUtils.push(
                    context,
                    StoreRoute.list,
                    replace: true,
                  );
                },
              ),
            ],
          ),
          body: SafeArea(
            top: false,
            child: Column(
              children: [
                TabBar(
                  tabAlignment: TabAlignment.center,
                  labelPadding: EdgeInsets.symmetric(horizontal: 18.w),
                  labelColor: SocialChatTheme.primaryLight,
                  isScrollable: true,
                  indicator: BoxDecoration(),
                  unselectedLabelColor: Colors.white38,
                  labelStyle: TextStyle(
                    fontSize: 15.sp,
                    fontWeight: FontWeight.w600,
                  ),
                  unselectedLabelStyle: TextStyle(
                    fontSize: 13.sp,
                    fontWeight: FontWeight.w500,
                  ),
                  indicatorColor: Colors.transparent,
                  dividerColor: Colors.transparent,
                  controller: _tabController,
                  tabs: _tabs,
                ),
                Expanded(
                  child: TabBarView(
                    controller: _tabController,
                    children: _pages,
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
