1import React, { useState } from 'react';
2import { apiFetch } from '../lib/api';
3import './AIRewordButton.css';
5export default function AIRewordButton({ value, onReword, disabled, style, prompt = 'Rewrite this text to be clear and natural:' }) {
6 const [loading, setLoading] = useState(false);
8 const handleReword = async (e) => {
10 if (!value || loading) return;
13 const res = await apiFetch('/reword', {
15 headers: { 'Content-Type': 'application/json' },
16 body: JSON.stringify({ text: value, prompt })
18 const data = await res.json();
19 if (data.reworded) onReword(data.reworded);
21 alert('AI rewording failed.');
28 className="ai-reword-btn"
29 onClick={handleReword}
30 disabled={disabled || loading || !value}
33 title="Reword with AI"
36 <span className="material-symbols-outlined spinning" style={{ fontSize: 18, margin: 0, padding: 0 }}>progress_activity</span>
38 <span className="material-symbols-outlined" style={{ fontSize: 18, margin: 0, padding: 0 }}>auto_awesome</span>