import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:vitalapp/components/button.dart';
import 'package:vitalapp/pages/home/personal_center/controller.dart';

class SignaturePage extends GetView<PersonalCenterController> {
  const SignaturePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        _buildPreview(),
        const SizedBox(height: 20),
        _buildOperateRow(),
      ],
    );
  }

  Widget _buildOperateRow() {
    return VButton(
      label: "设  置",
      onTap: controller.rewrite,
    );
  }

  Widget _buildPreview() {
    return Obx(() {
      final imageWidget = controller.state.signaturUrl != null
          ? _buildBase64Preview()
          : _buildEmptyPreview();
      return Container(
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: Colors.grey),
        ),
        width: 420,
        height: 270,
        child: imageWidget,
      );
    });
  }

  Widget _buildBase64Preview() {
    final url = controller.state.signaturUrl!;
    return Image.network(
      url,
      fit: BoxFit.contain,
    );
  }

  Widget _buildEmptyPreview() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      mainAxisSize: MainAxisSize.min,
      children: const [
        Icon(
          Icons.person_4_outlined,
          size: 56,
        ),
        SizedBox(height: 12),
        Text(
          "未设置",
          style: TextStyle(fontSize: 32),
        ),
      ],
    );
  }
}
