import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../funcs.dart';
import '../../../widget/operation_button.dart';

///预览操作视图
class PreviewOperationView extends StatelessWidget {
  final void Function() onSave;
  final void Function() onCancel;

  const PreviewOperationView(
      {super.key, required this.onSave, required this.onCancel});

  @override
  Widget build(BuildContext context) {
    return OrientationBuilder(builder: (ctx, orientation) {
      Alignment alignment = orientation == Orientation.landscape
          ? Alignment.centerRight
          : Alignment.bottomCenter;
      //保存按钮
      Widget buttonSave = OperationButton(
          text: getS().save,
          onTap: onSave,
          child: const Icon(
            Icons.save,
            color: Colors.white,
          ));

      //取消按钮
      Widget buttonCancel = OperationButton(
          text: getS().retakePhoto,
          onTap: onCancel,
          child: const Icon(
            Icons.close,
            color: Colors.white,
          ));

      //根据横竖屏显示在不同位置
      return Align(
        alignment: alignment,
        child: Container(
          padding: orientation == Orientation.landscape
              ? EdgeInsets.only(right: 20.w)
              : EdgeInsets.only(bottom: 52.h),
          child: orientation == Orientation.landscape
              ? Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    buttonSave,
                    SizedBox(
                      height: 40.h,
                    ),
                    buttonCancel,
                  ],
                )
              : Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    buttonSave,
                    SizedBox(
                      width: 44.w,
                    ),
                    buttonCancel,
                  ],
                ),
        ),
      );
    });
  }
}
