import React, { useState, useEffect } from 'react';
import { Button, Input } from 'antd';
import styles from './index.less';
import { createSecretKey, getSecretKey } from '@/services/System/secretKey';

const { TextArea } = Input;

const SecretKey: React.FC = () => {
  const [secretKey, setSecretKey] = useState('');

  const create = async () => {
    await createSecretKey({});
  };

  const getUserSecretKey = async () => {
    const data = await getSecretKey();
    setSecretKey(data + '');
  };

  useEffect(() => {
    getUserSecretKey();
  }, []);

  return (
    <div className={styles.container}>
      <Button className={styles.button} type="primary" onClick={create}>
        创建密钥
      </Button>
      <TextArea className={styles.textarea} rows={16} value={secretKey} />
    </div>
  );
};

export default SecretKey;
