import{h as e}from"./globalCategorySettings-BuKUniuw.js";import{d as t,l as n,o as r,r as i}from"./fillPublishForm-SvRJN5-l.js";function a(e){return new Promise(t=>setTimeout(t,e))}function o(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 s(e){return e.replace(/\s/g,``).replace(/(省|市|区|县|自治区|特别行政区|壮族|回族|维吾尔|自治州|地区|盟)$/g,``)}function c(e,t){let n=s(e),r=s(t);return!n||!r?!1:n===r||n.includes(r)||r.includes(n)}function l(){let e=document.querySelectorAll(`.el-dialog__wrapper`);for(let t of e){if(!o(t))continue;let e=t.querySelector(`[aria-label="请选择发货区域"]`);if(e)return e;if(t.querySelector(`.el-dialog__title`)?.textContent?.includes(`请选择发货区域`))return t.querySelector(`.el-dialog`)??t}return null}function u(){let e=i(`region_full_name0`,{labelTextFallback:`发货地`});return e?e.closest(`.el-select`)?.querySelector(`.el-input`)??e.closest(`.el-form-item`)?.querySelector(`.el-select .el-input`)??e:null}async function d(){let e=l();if(e)return e;let r=u();return r?(await t(r),n(()=>l(),8e3)):(console.warn(`[xyxp-xgj] fillAddress: 未找到发货地控件`),null)}function f(e){return[...e.querySelectorAll(`.el-select.w-120`)]}function p(){let e=document.querySelectorAll(`.el-select-dropdown.el-popper`);for(let t of e)if(o(t))return t;return null}async function m(e,i){let a=e.querySelector(`.el-input`)??e.querySelector(`.el-input__inner`);if(!a)return!1;await t(a);let o=await n(()=>p(),5e3);if(!o)return!1;let s=[...o.querySelectorAll(`.el-select-dropdown__item`)].find(e=>c(e.textContent?.trim()??``,i));return s?(await t(s),await r(),!0):(console.warn(`[xyxp-xgj] fillAddress: 未匹配选项`,i),!1)}async function h(e){let n=[...e.querySelectorAll(`.el-button`)].find(e=>e.textContent?.replace(/\s/g,``).includes(`确认选择`));return n?(await t(n),await a(300),!l()):!1}async function g(t){if(!e(t))return!1;let n=[t.province,t.city,t.area],r=await d();if(!r)return!1;let i=f(r);if(i.length<3)return console.warn(`[xyxp-xgj] fillAddress: 弹窗内省市区选择器不足`,i.length),!1;for(let e=0;e<3;e++){if(!await m(i[e],n[e]))return!1;await a(200)}return h(r)}export{g as fillXianguanjiaAddress};