var SirsoftDaumPostcode=function(h){"use strict";const L="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js",P="daum_postcode_script",D="daum-postcode-sdk";function O(e,n){const o=window?.G7Core?.t;if(typeof o!="function")return n;const t=`sirsoft-daum_postcode.${e}`,s=o(t);return typeof s=="string"&&s!==t?s:n}function p(){return!!window.daum?.Postcode}function A(e=12e3){return p()?Promise.resolve(!0):new Promise(n=>{const o=Date.now(),t=()=>{if(p()){n(!0);return}if(Date.now()-o>=e){n(!1);return}setTimeout(t,100)};setTimeout(t,100)})}async function _(){if(p())return!0;document.getElementById(P)?.remove();const e=window?.G7Core?.asset?.loadScript;try{typeof e=="function"?await e(L,{id:P},{label:"daum postcode SDK"}):await new Promise((n,o)=>{const t=document.createElement("script");t.id=P,t.src=L,t.onload=()=>n(),t.onerror=()=>o(new Error("daum postcode SDK load failed")),document.head.appendChild(t)})}catch{return!1}return p()}function E(e){const n=window?.G7Core?.assets?.notifyFailure,o=O("postcode.error.sdk_unavailable","주소 검색을 불러오지 못했습니다. 주소를 직접 입력해 주세요.");if(typeof n!="function"){console.warn(`[sirsoft-daum_postcode] ${o}`);return}n({id:D,label:O("postcode.search","주소 검색"),message:o,retry:async()=>{if(!await _())throw new Error("[sirsoft-daum_postcode] 주소 검색을 여전히 불러올 수 없습니다.");await e()}})}function S(){window?.G7Core?.assets?.clearFailure?.(D)}const f=window.G7Core?.createLogger?.("DaumPostcode:SetFieldReadOnly")??{log:(...e)=>console.log("[DaumPostcode:SetFieldReadOnly]",...e),warn:(...e)=>console.warn("[DaumPostcode:SetFieldReadOnly]",...e),error:(...e)=>console.error("[DaumPostcode:SetFieldReadOnly]",...e)};async function k(e,n){const o=e.params||{},t=o.fields||[],s=o.readOnly!==!1;if(!t.length){f.warn("[setFieldReadOnly] No fields specified");return}if(s){if(!await A(o.sdkWaitMs)){f.warn("[setFieldReadOnly] Daum Postcode SDK unavailable — leaving fields editable"),b(t,!1),E(()=>{b(t,!0),S()});return}S()}f.log(`[setFieldReadOnly] Setting readOnly=${s} for fields:`,t),b(t,s)}function b(e,n){e.forEach(o=>{const t=document.querySelectorAll(`input[name="${o}"], textarea[name="${o}"]`);if(t.length===0){f.warn(`[setFieldReadOnly] No input found with name="${o}"`);return}t.forEach(s=>{s.readOnly=n,n?s.classList.add("readonly"):s.classList.remove("readonly"),f.log(`[setFieldReadOnly] Set readOnly=${n} on input[name="${o}"]`)})})}const i=window.G7Core?.createLogger?.("DaumPostcode:OpenPostcode")??{log:(...e)=>console.log("[DaumPostcode:OpenPostcode]",...e),warn:(...e)=>console.warn("[DaumPostcode:OpenPostcode]",...e),error:(...e)=>console.error("[DaumPostcode:OpenPostcode]",...e)};function R(e){return{zipcode:e.zonecode||"",address:e.roadAddress||e.jibunAddress||"",addressDetail:"",region:e.sido||"",city:e.sigungu||"",countryCode:"KR",_raw:e}}async function $(e,n){const o=e.params||{},{callbackAction:t,displayMode:s="layer",width:c=500,height:r=600,theme:a,targetFields:l}=o,x=(window.G7Core?.plugin?.getSettings?.("sirsoft-daum_postcode")||{}).target_fields||{zipcode:"shipping.zipcode",address:"shipping.address",region:"shipping.region",city:"shipping.city"};if(i.log("[openPostcode] Starting with params:",{displayMode:s,width:c,height:r,hasCallbackAction:!!t,targetFields:l||x}),!p()){if(i.warn("[openPostcode] Daum Postcode API not loaded — retrying"),!await _()){i.error("[openPostcode] Daum Postcode API unavailable"),E(()=>$(e,n));return}S()}const y={oncomplete:w=>{i.log("[openPostcode] Address selected (raw):",w);const m=R(w);i.log("[openPostcode] Converted to G7 format:",m),t?(i.log("[openPostcode] Executing callbackAction"),G(t,m,n)):(i.log("[openPostcode] Executing default setState"),F(l||x,m))},width:c,height:r};a&&(y.theme=a);const I=new window.daum.Postcode(y);if(s==="popup")I.open();else{const{layer:w,closeLayer:m}=T(c,r),j=y.oncomplete;y.oncomplete=M=>{m(),j(M)},new window.daum.Postcode(y).embed(w)}}function T(e,n){const o=document.createElement("div");o.id="daum-postcode-overlay",o.style.cssText=` position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 9999; `;const t=document.createElement("div");t.id="daum-postcode-layer",t.style.cssText=` width: ${e}px; height: ${n}px; background-color: white; border-radius: 8px; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); `;const s=document.createElement("button");s.type="button",s.innerHTML="×",s.style.cssText=` position: absolute; top: -12px; right: -12px; width: 32px; height: 32px; border-radius: 50%; background-color: #374151; color: white; border: none; cursor: pointer; font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; z-index: 10; `;const c=document.createElement("div");c.style.cssText="position: relative;",c.appendChild(s),c.appendChild(t),o.appendChild(c),document.body.appendChild(o);const r=()=>{o.parentNode&&o.parentNode.removeChild(o)};s.addEventListener("click",r),o.addEventListener("click",l=>{l.target===o&&r()});const a=l=>{l.key==="Escape"&&(r(),document.removeEventListener("keydown",a))};return document.addEventListener("keydown",a),i.log("[openPostcode] Layer created with size:",{width:e,height:n}),{overlay:o,layer:t,closeLayer:r}}function G(e,n,o){const t=window.G7Core;if(!t?.dispatch){i.error("[openPostcode] G7Core.dispatch not available");return}const s=o?.state||t?.state?.getLocal?.()||{},c={state:s,setState:o?.setState,data:{...o?.data||{},_local:s,$event:n},isolatedContext:o?.isolatedContext};i.log("[openPostcode] Dispatching with componentContext:",{hasLocalState:!!s,sourceType:o?.state?"handlerContext":"getLocal",localCheckout:s?.checkout,event:n});try{const r=Array.isArray(e)?e:[e];for(const a of r)a&&typeof a=="object"&&(i.log("[openPostcode] Dispatching action:",a),t.dispatch(a,{componentContext:c}))}catch(r){i.error("[openPostcode] callbackAction failed:",r)}}function F(e,n){const o=window.G7Core;if(!o?.state?.setLocal){i.error("[openPostcode] G7Core.state.setLocal not available");return}const t={};e.zipcode&&(t[e.zipcode]=n.zipcode),e.address&&(t[e.address]=n.address),e.region&&(t[e.region]=n.region),e.city&&(t[e.city]=n.city),i.log("[openPostcode] Setting local state:",t),o.state.setLocal(t)}const u={setFieldReadOnly:k,openPostcode:$},d="sirsoft-daum_postcode",g=window.G7Core?.createLogger?.(`Plugin:${d}`)??{log:(...e)=>console.log(`[Plugin:${d}]`,...e),warn:(...e)=>console.warn(`[Plugin:${d}]`,...e),error:(...e)=>console.error(`[Plugin:${d}]`,...e)};function v(e=!1){const n=window.G7Core?.getActionDispatcher?.();if(n)Object.entries(u).forEach(([o,t])=>{const s=`${d}.${o}`;n.registerHandler(s,t,{category:"plugin",source:d})}),g.log(`${Object.keys(u).length} handler(s) registered:`,Object.keys(u).map(o=>`${d}.${o}`));else if(e){let o=0;const t=50,s=()=>{const c=window.G7Core?.getActionDispatcher?.();c?(Object.entries(u).forEach(([r,a])=>{const l=`${d}.${r}`;c.registerHandler(l,a,{category:"plugin",source:d})}),g.log(`${Object.keys(u).length} handler(s) registered:`,Object.keys(u).map(r=>`${d}.${r}`))):(o++,o<=t?(g.warn(`ActionDispatcher not found, retrying... (${o}/${t})`),setTimeout(s,100)):g.error("Failed to register handlers: ActionDispatcher not available after maximum retries"))};s()}else g.warn("ActionDispatcher not found, handlers not registered")}function C(){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>v(!0));else{const e=!!window.G7Core?.getActionDispatcher?.();v(!e)}}return C(),typeof window<"u"&&(window.__SirsoftDaumPostcode={identifier:d,handlers:Object.keys(u),initPlugin:C}),h.initPlugin=C,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),h}({});