(()=>{var{defineProperty:Q,getOwnPropertyNames:y,getOwnPropertyDescriptor:F}=Object,k=Object.prototype.hasOwnProperty;var X=new WeakMap,E=(w)=>{var z=X.get(w),C;if(z)return z;if(z=Q({},"__esModule",{value:!0}),w&&typeof w==="object"||typeof w==="function")y(w).map((G)=>!k.call(z,G)&&Q(z,G,{get:()=>w[G],enumerable:!(C=F(w,G))||C.enumerable}));return X.set(w,z),z};var I=(w,z)=>{for(var C in z)Q(w,C,{get:z[C],enumerable:!0,configurable:!0,set:(G)=>z[C]=()=>G})};var M={};I(M,{setFilToUrl:()=>O,sendRequestToEndpoint:()=>R,sendRequest:()=>S,main:()=>A,getEndpointUrl:()=>N,convertDirectIdsToAP:()=>W});var Y={local:"https://localhost:27443/direct_visit.php",dev:"https://t.affi-b.net/direct_visit.php",prod:"https://t.afi-b.com/direct_visit.php"};function Z(){return Y.prod}function V(){if(typeof window==="undefined")return!1;try{return new URLSearchParams(window.location.search).get("afblpcvtest")==="true"}catch(w){return window.location?.search?.includes("afblpcvtest=true")??!1}}function $(){try{if(typeof window==="undefined")return!1;return window.location?.search?.includes("afblpcvtest=true")??!1}catch{return!1}}function J(w,z,...C){if(V())console[w](`[TEST] ${z}`,...C)}function A(){try{R()}catch(w){J("error","❌ ダイレクトトラッキング処理でエラーが発生しました:",w)}}function R(){let w=null;try{w=new URLSearchParams(window.location.search).get("afb_direct")}catch(z){let G=(window.location?.search||"").match(/[?&]afb_direct=([^&]*)/);w=G?decodeURIComponent(G[1]):null}if(w==="true"||w==="1"){let z=W();if(z){let C=new URL(window.location.href);C.searchParams.delete("fil");let G=C.toString(),B={a:z.a,p:z.p,t:Date.now(),s:"direct",url:G},K=N();J("info","\uD83D\uDCE4 direct_visit.php への送信データ:",{endpoint:K,requestData:B,queryString:`a=${B.a}&p=${B.p}&t=${B.t}&s=${B.s}`}),S(K,B).then((H)=>{try{let L="";if(H&&typeof H==="object"&&H.fil&&typeof H.fil==="string"&&H.fil.length>0)L=H.fil,J("info","✅ ダイレクトトラッキング成功: サーバーからfilを受信",{fil:L.substring(0,100)+"..."});else J("warn","⚠️ ダイレクトトラッキング: サーバーからfilパラメータが返されませんでした",{result:H});if(L)O(L);else J("info","ℹ️ filをURLに設定できませんでした")}catch(L){J("warn","filをURLに設定する処理でエラーが発生しました",L)}}).catch((H)=>{J("error","リクエスト送信エラー:",H)})}else J("warn","⚠️ パラメータの変換に失敗しました")}}function W(){let w=null,z=null;try{let G=new URLSearchParams(window.location.search);w=G.get("afb_pid"),z=G.get("afb_psid")}catch(G){let B=window.location?.search||"",K=B.match(/[?&]afb_pid=([^&]*)/),H=B.match(/[?&]afb_psid=([^&]*)/);w=K?decodeURIComponent(K[1]):null,z=H?decodeURIComponent(H[1]):null}if(J("info","\uD83D\uDD0D URL パラメータ解析結果:",{afb_pid:w,afb_psid:z,fullQueryString:window.location.search}),!w||!z)return J("warn","⚠️ afb_pid または afb_psid が見つかりません"),null;let C={a:w,p:z};return J("info","\uD83D\uDD04 パラメータ変換完了:",C),C}function N(){if(V())try{let z=new URLSearchParams(window.location.search).get("mock_port");if(z)return`http://localhost:${z}/direct_visit.php`}catch(w){let C=(window.location?.search||"").match(/[?&]mock_port=([^&]*)/),G=C?decodeURIComponent(C[1]):null;if(G)return`http://localhost:${G}/direct_visit.php`}return Z()}function O(w){if(V())window.__setFilToUrlCalled=!0,window.__urlUpdateCalled=!0;J("info","\uD83D\uDD17 filをURLに設定中:",{fil:w.substring(0,200)+(w.length>200?"...":""),filLength:w.length,beforeUrl:window.location.href});let z=new URL(window.location.href);z.searchParams.set("fil",w);let C=z.toString();window.history.replaceState({},"",C),J("info","✅ URL更新完了:",{afterUrl:C.substring(0,300)+(C.length>300?"...":"")});try{window.dispatchEvent(new CustomEvent("afblpcv:fil-updated"))}catch(G){}}function S(w,z){let C=new URLSearchParams;for(let B in z)if(z.hasOwnProperty(B))C.append(B,String(z[B]));let G=`${w}?${C.toString()}`;if($()&&typeof window!=="undefined")window.__lastFetch={url:G,method:"GET",headers:{},body:null,timestamp:Date.now()};return fetch(G,{method:"GET",credentials:"include"}).then((B)=>{if(B.ok)return B.text().then((K)=>{if(J("info","\uD83D\uDD0D サーバーレスポンス詳細",{responseTextLength:K?K.length:0,responseText:K?K.substring(0,500):"null",status:B.status,headers:B.headers}),K&&K.trim().length>0)try{let H=JSON.parse(K.trim());if(H&&H.fil&&typeof H.fil==="string"&&H.fil.length>0)return{success:!0,status:B.status,fil:H.fil};else return J("info","ℹ️ JSONレスポンスにfilパラメータが含まれていません",{jsonData:H}),{success:!0,status:B.status}}catch(H){return J("warn","⚠️ サーバーレスポンスのJSONパースに失敗",{responseText:K.substring(0,200),parseError:H}),{success:!0,status:B.status}}else return{success:!0,status:B.status}});else throw new Error(`HTTP error! status: ${B.status} ${B.statusText}`)}).then((B)=>{if($()&&typeof window!=="undefined")window.__lastResponse=B;return B}).catch((B)=>{return J("error","リクエスト送信エラー:",B.message),{success:!1,error:B.message}})}if(typeof window!=="undefined")window.DirectMain={main:A};})();