(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@tachybase/client"),require("@tachybase/module-auth/client"),require("react/jsx-runtime"),require("react"),require("@ant-design/icons"),require("antd"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-auth/client","react/jsx-runtime","react","@ant-design/icons","antd","react-router-dom"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@tachybase/plugin-auth-dingtalk"]={},e["@tachybase/client"],e["@tachybase/module-auth"],e.jsxRuntime,e.react,e["@ant-design/icons"],e.antd,e["react-router-dom"]))})(this,function(e,t,a,n,i,g,s,u){"use strict";var x=(e,t,a)=>new Promise((n,i)=>{var g=r=>{try{u(a.next(r))}catch(d){i(d)}},s=r=>{try{u(a.throw(r))}catch(d){i(d)}},u=r=>r.done?n(r.value):Promise.resolve(r.value).then(g,s);u((a=a.apply(e,t)).next())});const r="dingtalk",d="dingtalk";function S(){return t.useTranslation([d,"core"],{nsMode:"fallback"})}const q=()=>{const{t:o}=S(),c=t.useApp(),m=i.useMemo(()=>c.getApiUrl("dingtalk:redirect"),[c]),l=f=>{navigator.clipboard.writeText(f),s.message.success(o("Copied"))};return n.jsxs("div",{children:[n.jsx(t.SchemaComponent,{scope:{t:o},schema:{type:"object",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox",default:!0}}},dingtalk:{type:"object",properties:{clientId:{"x-decorator":"FormItem","x-component":"Input",type:"string",required:!0,title:'{{t("Client ID")}}'},clientSecret:{"x-decorator":"FormItem","x-component":"Input",type:"string",required:!0,title:'{{t("Client Secret")}}'}}}}}}),n.jsxs("div",{children:[n.jsxs(s.Typography.Title,{level:5,style:{fontSize:"14px"},children:[o("Redirect URL"),n.jsx("span",{style:{marginLeft:"2px"},children:":"})]}),n.jsx(s.Input,{value:m,disabled:!0,addonBefore:n.jsx(g.CopyOutlined,{onClick:()=>l(m)})})]})]})},C=({authenticator:o})=>{const[c,m]=i.useState(),{t:l}=S(),f=t.useAPIClient(),I=u.useLocation(),y=new URLSearchParams(I.search),j=y.get("redirect");i.useEffect(()=>{c&&(window.location.href=c)},[c]),i.useEffect(()=>{const p=y.get("authenticator"),h=y.get("error");if(p===o.name&&h){s.message.error(l(h));return}});const v=()=>x(null,null,function*(){var k,T;const p=yield f.request({method:"post",url:"dingtalk:getAuthUrl",headers:{"X-Authenticator":o.name},data:{redirect:j}}),h=(T=(k=p==null?void 0:p.data)==null?void 0:k.data)==null?void 0:T.url;h&&m(h)});return n.jsx(s.Button,{block:!0,icon:n.jsx(g.LoginOutlined,{}),shape:"round",onClick:v,children:o.title?l(o.title):l("Sign in via DingTalk")})};class b extends t.Plugin{load(){return x(this,null,function*(){this.app.pm.get(a).registerType(r,{components:{SignInButton:C,AdminSettingsForm:q}})})}}e.PluginDingding=b,e.default=b,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
