import React from 'react';
import PropTypes from 'prop-types';
import { Box, Typography, Skeleton } from '@mui/material';

/**
 * 获取组织名称的首字符或首单词
 */
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function getOrgInitial(name) {
  if (!name) return '';

  // 如果是中文字符，取第一个字
  if (/[\u4e00-\u9fa5]/.test(name.charAt(0))) {
    return name.charAt(0);
  }

  // 如果是英文，取第一个单词的首字母，最多2个字符
  const words = name.trim().split(/\s+/);
  if (words.length > 1) {
    return words.slice(0, 2).map(word => word.charAt(0).toUpperCase()).join('');
  }
  return name.charAt(0).toUpperCase();
}

/**
 * 组织基本信息
 */
export default function Basic({
  org,
  loading = false
}) {
  return /*#__PURE__*/_jsxs(Box, {
    sx: {
      display: 'flex',
      alignItems: 'center',
      gap: 2
    },
    children: [/*#__PURE__*/_jsx(Box, {
      sx: {
        width: 56,
        height: 56,
        borderRadius: 1,
        backgroundColor: 'grey.100',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
      },
      children: loading ? /*#__PURE__*/_jsx(Skeleton, {
        variant: "text",
        width: 25,
        height: 25
      }) : /*#__PURE__*/_jsx(Typography, {
        sx: {
          fontSize: 30,
          fontWeight: 600
        },
        children: getOrgInitial(org.name)
      })
    }), /*#__PURE__*/_jsxs(Box, {
      sx: {
        flex: 1,
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'space-between'
      },
      children: [/*#__PURE__*/_jsx(Typography, {
        variant: "h4",
        sx: {
          overflow: 'hidden',
          display: '-webkit-box',
          WebkitLineClamp: 1,
          WebkitBoxOrient: 'vertical',
          textOverflow: 'ellipsis'
        },
        children: loading ? /*#__PURE__*/_jsx(Skeleton, {
          variant: "text",
          width: "10%",
          height: 24
        }) : org.name || '-'
      }), /*#__PURE__*/_jsx(Typography, {
        variant: "body1",
        sx: {
          fontSize: 14,
          lineHeight: 1.2,
          overflow: 'hidden',
          display: '-webkit-box',
          WebkitLineClamp: 2,
          WebkitBoxOrient: 'vertical'
        },
        children: loading ? /*#__PURE__*/_jsx(Skeleton, {
          variant: "text",
          width: "30%",
          height: 24
        }) : org.description || '-'
      })]
    })]
  });
}
Basic.propTypes = {
  org: PropTypes.shape({
    name: PropTypes.string,
    description: PropTypes.string
  }).isRequired,
  loading: PropTypes.bool
};