import{defineComponent as U,toRefs as W,ref as X,computed as t,shallowRef as Y,watchEffect as Z,watch as S,createVNode as r,Fragment as ee}from"vue";import te from"../_util/PortalWrapper.mjs";import M from"../_util/classNames.mjs";import E from"../_util/hooks/useMergedState.mjs";import oe from"../_util/props-util/initDefaultProps.mjs";import{someType as i,objectType as le,functionType as f,stringType as ne,booleanType as ae,arrayType as re}from"../_util/type.mjs";import ue from"../vc-trigger/Trigger.mjs";import{triggerProps as se}from"../vc-trigger/interface.mjs";import pe from"./Mask.mjs";import ie from"./TourStep/index.mjs";import fe from"./hooks/useTarget.mjs";import{getPlacements as ce}from"./placements.mjs";const b={left:"50%",top:"50%",width:"1px",height:"1px"},me=()=>{const{builtinPlacements:o,popupAlign:c}=se();return{builtinPlacements:o,popupAlign:c,steps:re(),open:ae(),defaultCurrent:{type:Number},current:{type:Number},onChange:f(),onClose:f(),onFinish:f(),mask:i([Boolean,Object],!0),arrow:i([Boolean,Object],!0),rootClassName:{type:String},placement:ne("bottom"),prefixCls:{type:String,default:"rc-tour"},renderPanel:f(),gap:le(),animated:i([Boolean,Object]),scrollIntoViewOptions:i([Boolean,Object],!0),zIndex:{type:Number,default:1001}}},Te=U({name:"Tour",inheritAttrs:!1,props:oe(me(),{}),setup(o){const{defaultCurrent:c,placement:k,mask:A,scrollIntoViewOptions:j,open:R,gap:V,arrow:z}=W(o),m=X(),[n,P]=E(0,{value:t(()=>o.current),defaultValue:c.value}),[a,B]=E(void 0,{value:t(()=>o.open),postState:l=>n.value<0||n.value>=o.steps.length?!1:l??!0}),h=Y(a.value);Z(()=>{a.value&&!h.value&&P(0),h.value=a.value});const e=t(()=>o.steps[n.value]||{}),D=t(()=>e.value.placement??k.value),u=t(()=>a.value&&(e.value.mask??A.value)),F=t(()=>e.value.scrollIntoViewOptions??j.value),[w,v]=fe(t(()=>e.value.target),R,V,F),d=t(()=>v.value?typeof e.value.arrow>"u"?z.value:e.value.arrow:!1),x=t(()=>typeof d.value=="object"?d.value.pointAtCenter:!1);S(x,()=>{m.value?.forcePopupAlign()}),S(n,()=>{m.value?.forcePopupAlign()});const O=l=>{P(l),o.onChange?.(l)};return()=>{const{prefixCls:l,steps:L,onClose:H,onFinish:$,rootClassName:g,renderPanel:_,animated:q,zIndex:N,...y}=o;if(v.value===void 0)return null;const T=()=>{B(!1),H?.(n.value)},G=typeof u.value=="boolean"?u.value:!!u.value,I=typeof u.value=="boolean"?void 0:u.value,J=()=>v.value||document.body,K=()=>r(ie,{arrow:d.value,key:"content",prefixCls:l,total:L.length,renderPanel:_,onPrev:()=>{O(n.value-1)},onNext:()=>{O(n.value+1)},onClose:T,current:n.value,onFinish:()=>{T(),$?.()},...e.value},null),Q=t(()=>{const p=w.value||b,C={};return Object.keys(p).forEach(s=>{typeof p[s]=="number"?C[s]=`${p[s]}px`:C[s]=p[s]}),C});return a.value?r(ee,null,[r(pe,{zIndex:N,prefixCls:l,pos:w.value,showMask:G,style:I?.style,fill:I?.color,open:a.value,animated:q,rootClassName:g},null),r(ue,{...y,arrow:!!y.arrow,builtinPlacements:e.value.target?y.builtinPlacements??ce(x.value):void 0,ref:m,popupStyle:e.value.target?e.value.style:{...e.value.style,position:"fixed",left:b.left,top:b.top,transform:"translate(-50%, -50%)"},popupPlacement:D.value,popupVisible:a.value,popupClassName:M(g,e.value.className),prefixCls:l,popup:K,forceRender:!1,destroyPopupOnHide:!0,zIndex:N,mask:!1,getTriggerDOMNode:J},{default:()=>[r(te,{visible:a.value,autoLock:!0},{default:()=>[r("div",{class:M(g,`${l}-target-placeholder`),style:{...Q.value,position:"fixed",pointerEvents:"none"}},null)]})]})]):null}}});export{Te as default,me as tourProps};
