import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';

class SubSpaceDialogButtons extends StatelessWidget {
  const SubSpaceDialogButtons({
    super.key,
    required String? selectedId,
    required this.widget,
  }) : _selectedId = selectedId;

  final String? _selectedId;
  final SubSpaceDialog widget;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 50,
      child: Row(
        children: [
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                border: Border(
                  right: BorderSide(
                    color: ColorsManager.dividerColor,
                    width: 0.5,
                  ),
                ),
              ),
              child: TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: Text(
                  'Cancel',
                  style: context.textTheme.bodyMedium?.copyWith(
                    color: ColorsManager.textGray,
                    fontSize: 18,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ),
            ),
          ),
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                border: Border(
                  left: BorderSide(
                    color: ColorsManager.dividerColor,
                    width: 0.5,
                  ),
                ),
              ),
              child: TextButton(
                onPressed: _selectedId == null
                    ? null
                    : () {
                        final selectedModel = widget.subSpaces.firstWhere(
                          (space) => space.id == _selectedId,
                          orElse: () =>
                              SubSpaceModel(id: null, name: '', devices: []),
                        );
                        Navigator.of(context)
                            .pop(selectedModel); 
                      },
                child: Text(
                  'Confirm',
                  style: context.textTheme.bodyMedium?.copyWith(
                    color: ColorsManager.secondaryColor,
                    fontSize: 14,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
