"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),y=require("@aplus-frontend/antdv"),b=require("@aplus-frontend/icon"),a=require("lodash-unified");require("../../config-provider/index.js");const C=require("./constans.js"),h=require("./style/index.js"),N=require("../../config-provider/hooks/use-namespace.js"),T=require("../../config-provider/hooks/use-locale.js"),k=n.defineComponent({name:"CopyBtn",props:C.ApCopyProps(),setup(t,{slots:f}){const{b:g,e:l,m:s}=N.useNamespace("ap-copy"),p=h.default("ap-copy"),{t:c}=T.useLocale(),x=(e,r,S)=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation(),navigator.clipboard.writeText(t.text||u()||"").then(()=>{y.message.success(r||c("ap.apCopy.copySuccess"))}).catch(()=>{y.message.error(S||c("ap.apCopy.copyError"))})},v=e=>{if(e.length===1){const r=e[0];if(r.type===n.Text||r.type.toString()==="Symbol(Text)"||n.isVNode(r)&&typeof r.children=="string")return!0}return!1},m=e=>{if(!e.length)return"";const r=e[0];return r.type===n.Text||r.type.toString()==="Symbol(Text)"?String(r.children):n.isVNode(r)&&typeof r.children=="string"?r.children:""},u=()=>{const e=f.default?.();return e&&v(e)?m(e):null},d=e=>!(a.isNull(e)||a.isUndefined(e)||typeof e=="string"&&e===""),o=n.computed(()=>{if(typeof t.textStyle=="string")switch(t.textStyle){case"link":return"text-link";case"minor":return"text-minor";case"major":return"text-major";default:return"text-major"}else if(typeof t.textStyle=="object")return{...t.textStyle};return{}}),i=n.computed(()=>u()||t.text||"");return()=>n.createVNode(n.Fragment,null,[n.createVNode("div",{class:[g(),p.value]},[n.createVNode("div",{class:[l("text"),typeof o.value=="string"&&s(o.value)],style:typeof o.value!="string"&&o.value,title:typeof o.value=="string"?i.value:"",onClick:t.onClick?()=>t.onClick():void 0},[d(i.value)?t.link&&a.isString(t.link)?n.createVNode("a",{href:t.link,target:"_blank"},[i.value]):a.isBoolean(t.link)?n.createVNode("span",{class:s("text-link")},[i.value]):i.value:"--"]),d(i.value)&&!t.disableCopy?n.createVNode("div",{class:[l("copy-btn"),"copy-btn"],onClick:t.disableCopy?void 0:e=>x(e,t.tipMessageSuccess,t.tipMessageError)},[n.createVNode(b.IconApAdLineCopy,{size:t.size},null)]):n.createVNode("div",{class:[l("copy-btn"),"copy-btn"]},null)])])}});exports.default=k;
