import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{i as n,o as r,t as i}from"./jsx-runtime-DHSfUA5-.js";import{P as a,j as o}from"./test.id-DxQrYxPk.js";import{d as s}from"./route-CPr17rXr.js";import{t as c}from"./useSuccessToast-CW8oLO3e.js";import{t as l}from"./speechRecognitionConfig-BofzFyKP.js";import{t as u}from"./speechRecognitionService-BZBQ04hz.js";import{t as d}from"./usePreference-3fMY0uE5.js";import{t as f}from"./HeaderLayoutPage-CDZOzzod.js";import{t as p}from"./useTopTips-B9oW_JMO.js";import{t as m}from"./useLoadingToast-BBb6RyKX.js";import{n as h,t as g}from"./FormPage-B0BqbKo9.js";import{t as _}from"./useForm-YVjhCM4e.js";var v=e(r(),1),y=i();function b(){let e=s(),[,r]=d(l),i=a(u),b=m(),x=c(),S=p(),[C,w]=(0,v.useState)(!1),T=_({initialValues:{autoTranscribe:!0,dataSharingConsent:!1},requiredMessage:e=>t(`settings.speechRecognition.required`,`{0} is required.`,e.label),fields:[{name:`apiKey`,label:`API Key`,type:`text`,testId:o.apiKey,required:!0},{name:`secretKey`,label:`Secret Key`,type:`password`,testId:o.secretKey,required:!0},{name:`autoTranscribe`,label:t(`settings.speechRecognition.autoTranscribe`,`Auto-transcribe voice`),type:`checkbox`,testId:o.autoTranscribe}]}),E=async()=>{if(C||!T.verify())return;if(!T.values.dataSharingConsent){S({message:t(`settings.speechRecognition.consentRequired`,`Allow sending voice audio to Baidu AI Cloud before saving.`)});return}let n={apiKey:T.values.apiKey,secretKey:T.values.secretKey},a=b({message:t(`settings.speechRecognition.testing`,`Testing connection...`)});w(!0);try{await i.testConfig(n),await r({provider:`baidu`,apiKey:n.apiKey.trim(),secretKey:n.secretKey.trim(),autoTranscribe:T.values.autoTranscribe}),x({message:t(`settings.speechRecognition.saved`,`Saved`)}),e(`/settings/speech-recognition`,{replace:!0})}catch(e){S({message:e instanceof Error?e.message:t(`settings.speechRecognition.testFailed`,`Connection failed`)})}finally{a.dispose(),w(!1)}};return(0,y.jsx)(f,{rootClassName:n.Page.SurfaceRoot,contentClassName:n.WeuiForm.PageMain,pageTestId:o.page,contentTestId:o.content,header:{showBack:!0,tone:`surface`},children:(0,y.jsxs)(g,{title:t(`settings.speechRecognition.addTitle`,`Configure Baidu AI Cloud`),description:t(`settings.speechRecognition.addFormDesc`,`Turn voice messages into text, up to 59 seconds.`),check:{label:t(`settings.speechRecognition.dataSharingConsent`,`I allow Islet to send voice message audio to Baidu AI Cloud for voice-to-text transcription.`),checked:!!T.values.dataSharingConsent,testId:o.dataSharingConsent,onChange:e=>T.setValue(`dataSharingConsent`,e)},actions:[{label:t(`common.save`,`Save`),testId:o.save,disabled:C,onClick:()=>void E()}],children:[(0,y.jsx)(h,{title:t(`settings.speechRecognition.configInfo`,`Configuration`),items:T.fields}),(0,y.jsx)(`p`,{className:n.WeuiForm.Description,children:t(`settings.speechRecognition.consoleHint`,`Create an app in the Baidu AI Cloud console and enable Short Speech Recognition Pro to get the API Key and Secret Key. These credentials are used for automatic transcription after sending voice messages and manual transcription from a voice message.`)}),(0,y.jsx)(`p`,{className:n.WeuiForm.Description,children:t(`settings.speechRecognition.dataSharingDesc`,`When voice to text runs, Islet sends the selected voice message audio to Baidu AI Cloud Short Speech Recognition Pro and saves the returned text in the same diary entry. For example, after you send a voice message, that audio may be sent to Baidu AI Cloud to generate its transcript.`)})]})})}export{b as SettingsSpeechRecognitionAddPage};
//# sourceMappingURL=add-Bnx2IIKj.js.map