import{bb as r,r as y,ba as e,B as j}from"./createLucideIcon-BcINIXoS.js";import{c as S,a as f,g as k,o as K}from"./openrouter-Df8bB4Fu.js";import{T as A,c as N,F as d,H as w}from"../assets/admin-D0g83suT.js";import{S as _}from"./index-Djba9N7u.js";import{I}from"./index-ChG3lseq.js";import{u as B}from"./useSaveSettingHook-DNBrmYDn.js";import{s as C}from"./index-CEhw70mX.js";import{A as P}from"./index-BeAu3ZUr.js";import"./Input-gYODSeX_.js";import"./EyeOutlined-B40DaD3_.js";import"./SearchOutlined-B5_bI2oW.js";/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const T=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],z=r("chevron-down",T);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const F=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],L=r("chevron-up",F);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],x=r("circle-check",$);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const G=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],O=r("external-link",G);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const q=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],E=r("key",q),{Title:H,Text:M}=A,{Password:R}=I;function l({title:m,subtitle:i,icon:c,prefix:s,placeholder:o,theme:p,hasKey:t,linkUrl:n,linkText:h}){const[a,u]=y.useState(!1),v=s==="api_key"?"api_key_enabled":`${s}_api_key_enabled`,b=s==="api_key"?"api_key":`${s}_api_key`,g=o.replace("...","••••••••••••••••••••••••••••••");return e.jsxs("div",{className:`cai-border cai-border-solid ${p.border} cai-bg-white cai-rounded-2xl cai-p-5 cai-mb-5 cai-shadow-sm cai-transition-all cai-duration-300`,children:[e.jsxs("div",{className:"cai-flex cai-items-center cai-justify-between",children:[e.jsxs("div",{className:"cai-flex cai-items-center cai-gap-4",children:[e.jsx("div",{className:"cai-w-12 cai-h-12 cai-rounded-2xl cai-bg-white cai-border cai-border-slate-100 cai-flex cai-items-center cai-justify-center cai-shadow-sm",children:c}),e.jsxs("div",{children:[e.jsxs("div",{className:"cai-flex cai-items-center cai-gap-2",children:[e.jsx(H,{level:5,className:"!cai-m-0 !cai-text-slate-800 !cai-font-semibold !cai-text-[15px]",children:m}),t&&e.jsxs(N,{color:"success",className:"!cai-m-0 !cai-text-[11px] !cai-px-1.5 !cai-py-0 !cai-rounded-md cai-inline-flex cai-items-center cai-gap-1",children:[e.jsx(x,{size:11})," Saved"]})]}),e.jsxs(M,{className:"cai-text-slate-500 cai-text-[13px]",children:[i,n&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"cai-text-indigo-600 hover:cai-text-indigo-700 cai-font-medium cai-inline-flex cai-items-center cai-gap-1",children:[h||"Learn more",e.jsx(O,{size:12})]})]})]})]})]}),e.jsxs("div",{className:"cai-flex cai-items-center cai-gap-4",children:[t&&!a&&e.jsx("span",{className:"cai-text-slate-400 cai-text-[13px] cai-font-mono cai-hidden sm:cai-inline-block",children:g}),e.jsxs("button",{onClick:()=>u(!a),type:"button",className:"cai-flex cai-items-center cai-px-3 cai-py-1.5 cai-rounded-full cai-border cai-border-solid cai-border-slate-200 cai-text-slate-600 cai-text-[13px] cai-font-medium cai-bg-white hover:cai-bg-slate-50 cai-cursor-pointer cai-transition-colors",children:[e.jsx(E,{size:14,className:"cai-mr-1.5"})," Key ",a?e.jsx(L,{size:14,className:"cai-ml-1.5"}):e.jsx(z,{size:14,className:"cai-ml-1.5"})]}),e.jsx(d.Item,{name:v,valuePropName:"checked",noStyle:!0,children:e.jsx(_,{className:"[&.ant-switch-checked]:!cai-bg-[#20c997]"})})]})]}),e.jsxs("div",{className:`cai-overflow-hidden cai-transition-all cai-duration-300 ${a?"cai-max-h-36 cai-opacity-100 cai-mt-5":"cai-max-h-0 cai-opacity-0 cai-mt-0"}`,children:[e.jsx(d.Item,{name:b,noStyle:!0,children:e.jsx(R,{placeholder:t?"Key is saved. Enter new key to update...":o,autoComplete:"new-password",className:"!cai-rounded-xl !cai-py-2.5 cai-shadow-sm !cai-border-slate-200"})}),t&&e.jsxs("div",{className:"cai-text-[12px] cai-text-emerald-600 cai-mt-1.5 cai-flex cai-items-center cai-gap-1",children:[e.jsx(x,{size:13})," An API key is currently saved and active. Leave blank to keep existing key."]})]})]})}function ie({setHasApiKey:m}){const i=window.replyan_ai_admin||{},[c,s]=y.useState({apiKeySaved:!!i.apiKeySaved,anthropicApiKeySaved:!!i.anthropicApiKeySaved,geminiApiKeySaved:!!i.geminiApiKeySaved,openrouterApiKeySaved:!!i.openrouterApiKeySaved}),[o]=d.useForm(),[p,t]=C.useNotification(),{saving:n,saveSettings:h}=B({form:o,api:p,setHasApiKey:m,onSuccess:a=>{a&&(s({apiKeySaved:!!a.apiKeySaved,anthropicApiKeySaved:!!a.anthropicApiKeySaved,geminiApiKeySaved:!!a.geminiApiKeySaved,openrouterApiKeySaved:!!a.openrouterApiKeySaved}),i&&(i.apiKeySaved=!!a.apiKeySaved,i.anthropicApiKeySaved=!!a.anthropicApiKeySaved,i.geminiApiKeySaved=!!a.geminiApiKeySaved,i.openrouterApiKeySaved=!!a.openrouterApiKeySaved))}});return e.jsxs("div",{className:"cai-max-w-4xl cai-mx-auto cai-py-6",children:[t,e.jsx(P,{message:"Your API Keys Are Stored Locally & Securely",description:"All API keys are encrypted and saved directly in your WordPress database. They are never sent to external servers or third parties other than your chosen AI provider.",type:"info",showIcon:!0,className:"cai-mb-6 cai-rounded-xl cai-border-blue-200 cai-bg-blue-50/60"}),e.jsxs(d,{form:o,layout:"vertical",onFinish:h,initialValues:w(i.settings||{}),children:[e.jsx(l,{title:"OpenAI",subtitle:"GPT-4o, 4.1, mini and 5",prefix:"api_key",icon:e.jsx("img",{src:S,alt:"ChatGPT",className:"cai-w-7 cai-h-7 cai-object-contain"}),placeholder:"sk-proj-...",hasKey:c.apiKeySaved,theme:{border:"cai-border-emerald-200"}}),e.jsx(l,{title:"Anthropic",subtitle:"Claude 4 Opus, Sonnet, Haiku",prefix:"anthropic",icon:e.jsx("img",{src:f,alt:"Claude",className:"cai-w-7 cai-h-7 cai-object-contain"}),placeholder:"sk-ant-...",hasKey:c.anthropicApiKeySaved,theme:{border:"cai-border-orange-200"}}),e.jsx(l,{title:"Google Gemini",subtitle:"Gemini 2.5 Pro, Flash, and more",prefix:"gemini",icon:e.jsx("img",{src:k,alt:"Gemini",className:"cai-w-7 cai-h-7 cai-object-contain"}),placeholder:"AIza...",hasKey:c.geminiApiKeySaved,theme:{border:"cai-border-blue-200"}}),e.jsx(l,{title:"OpenRouter",subtitle:"One API key for OpenAI, Claude, DeepSeek, Llama & 100+ models",prefix:"openrouter",icon:e.jsx("img",{src:K,alt:"OpenRouter",className:"cai-w-7 cai-h-7 cai-object-contain cai-text-indigo-500"}),placeholder:"sk-or-v1-...",hasKey:c.openrouterApiKeySaved,theme:{border:"cai-border-indigo-200"},linkUrl:"https://openrouter.ai/models",linkText:"Learn more"}),e.jsx("div",{className:"cai-mt-6",children:e.jsx(j,{type:"primary",htmlType:"submit",loading:n,children:"Save Changes"})})]})]})}export{ie as default};
