import{d as e,l as t,o as n}from"./fillPublishForm-SvRJN5-l.js";function r(e){return new Promise(t=>setTimeout(t,e))}function i(e){if(!e||!(e instanceof HTMLElement)||!e.isConnected)return!1;let t=getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`||Number(t.opacity)===0)return!1;let n=e.getBoundingClientRect();return n.width>0&&n.height>0}function a(){for(let e of[`.el-form-item.channelCat .custom-cascader`,`.channelCat .custom-cascader`]){let t=document.querySelector(e);if(t)return t}return[...document.querySelectorAll(`label.el-form-item__label`)].find(e=>{let t=(e.textContent??``).replace(/\s/g,``);return t.includes(`商品分类`)||t.includes(`商品类目`)})?.closest(`.el-form-item`)?.querySelector(`.custom-cascader`)??null}function o(){let e=a(),t=[],n=e?.querySelector(`.custom-cascader-panel`);n&&t.push(n);for(let e of document.querySelectorAll(`.custom-cascader-panel`))t.includes(e)||t.push(e);return t.find(i)??null}function s(){let e=o();return i(e)?e.querySelector(`.custom-cascader-node`)!==null:!1}function c(){let e=o();return e?[...e.querySelectorAll(`:scope > .custom-cascader-menu`)]:[]}function l(e){let t=c()[e];return t?[...t.querySelectorAll(`.custom-cascader-node`)].map(e=>({text:(e.textContent??``).replace(/\s+/g,` `).trim(),hasChildren:e.classList.contains(`is-suffix`),el:e})).filter(e=>e.text):[]}function u(e){e.scrollIntoView({block:`nearest`,inline:`nearest`});let t=e.getBoundingClientRect(),n={bubbles:!0,cancelable:!0,view:window,clientX:t.left+Math.min(8,t.width/2),clientY:t.top+Math.min(8,t.height/2),button:0};typeof PointerEvent<`u`&&e.dispatchEvent(new PointerEvent(`pointerdown`,{...n,pointerId:1,pointerType:`mouse`})),e.dispatchEvent(new MouseEvent(`mousedown`,n)),typeof PointerEvent<`u`&&e.dispatchEvent(new PointerEvent(`pointerup`,{...n,pointerId:1,pointerType:`mouse`})),e.dispatchEvent(new MouseEvent(`mouseup`,n)),e.dispatchEvent(new MouseEvent(`click`,n))}async function d(e){let t=Date.now();for(;Date.now()-t<e;){if(s())return!0;await r(120)}return s()}async function f(){if(s())return!0;let t=a();if(!t)return console.warn(`[xyxp-xgj] fillCategory: 未找到商品分类控件`),!1;let n=t.querySelector(`.el-input__inner`),i=t.querySelector(`.el-input`),o=t.querySelector(`.el-input__suffix`)??t.querySelector(`.icon-zhankai1`)?.parentElement??null;return n?.focus(),n&&u(n),await r(180),!s()&&i&&u(i),await r(180),!s()&&o&&u(o),await r(180),!s()&&n&&(n.dispatchEvent(new FocusEvent(`focus`,{bubbles:!0})),n.dispatchEvent(new KeyboardEvent(`keydown`,{key:`ArrowDown`,bubbles:!0}))),await d(5e3)?!0:(n&&await e(n),d(8e3))}async function p(e,n=12e3){return!!await t(()=>{let t=l(e);return t.length?t[0].el:null},n)}async function m(e=15e3){return!!await t(()=>a(),e)}async function h(e){let t=e.map(e=>e.trim()).filter(Boolean);if(!t.length)return!1;if(!await m(15e3))return console.warn(`[xyxp-xgj] fillCategory: 商品分类控件未出现`),!1;if(!await f())return console.warn(`[xyxp-xgj] fillCategory: 未能展开类目面板`),!1;if(!await p(0))return console.warn(`[xyxp-xgj] fillCategory: 一级类目未加载`),!1;for(let e=0;e<t.length;e++){let i=t[e],a=l(e),o=a.find(e=>e.text===i);if(!o)return console.warn(`[xyxp-xgj] fillCategory: 未找到节点`,e+1,i,a.map(e=>e.text)),!1;if(u(o.el),e!==t.length-1){if(await n(),!await p(e+1))return console.warn(`[xyxp-xgj] fillCategory: 子列加载超时`,e+2,t[e+1]),!1}else await r(200)}return!0}export{h as fillXianguanjiaCategory};