1import{c as T,j as e,r as c}from"./client-auj285-g.js";let y=null;async function O(s){const n=`/api/liff/affiliate/me?lineAccessToken=${encodeURIComponent(s)}`,t=await fetch(n);if(t.status===404)return{registered:!1};if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error??`API ${t.status}`)}const r=await t.json();return{registered:!0,affiliate:r.affiliate,links:r.links}}async function C(s){const n=`/api/liff/affiliate/offers?lineAccessToken=${encodeURIComponent(s)}`,t=await fetch(n);return t.ok?(await t.json()).offers:[]}async function R(s,n){const t=await fetch(`/api/liff/affiliate/offers/${encodeURIComponent(n)}/enroll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lineAccessToken:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error??`API ${t.status}`)}return(await t.json()).link}async function I(s){const n=await fetch("/api/liff/affiliate/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lineAccessToken:s})});if(!n.ok){const t=await n.json().catch(()=>({}));throw new Error(t.error??`API ${n.status}`)}return await n.json()}async function L(s,n,t){const r=await fetch("/api/liff/affiliate/links",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lineAccessToken:s,label:n||null,offerId:t||null})});if(!r.ok){const d=await r.json().catch(()=>({}));throw new Error(d.error??`API ${r.status}`)}return(await r.json()).link}async function P(s){var n;try{if((n=navigator.clipboard)!=null&&n.writeText)return await navigator.clipboard.writeText(s),!0}catch{}try{const t=document.createElement("textarea");t.value=s,t.style.position="fixed",t.style.top="-9999px",t.style.left="-9999px",t.setAttribute("readonly",""),document.body.appendChild(t),t.select(),t.setSelectionRange(0,t.value.length);const r=document.execCommand("copy");if(document.body.removeChild(t),r)return!0}catch{}return!1}function $({url:s,urlRef:n}){const[t,r]=c.useState(!1),[o,d]=c.useState(!1);async function f(){if(await P(s)){d(!1),r(!0),setTimeout(()=>r(!1),2e3);return}d(!0),setTimeout(()=>{const l=n.current;l&&(l.focus(),l.select(),l.setSelectionRange(0,l.value.length))},0)}return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:f,className:"af-copy-btn",children:t?"ã³ãã¼æ¸ã¿":"ã³ãã¼"}),o&&e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"èªåã³ãã¼ã§ãã¾ããã§ãããä¸ã®URLã鏿ãã¦ã³ãã¼ãã¦ãã ããã"}),e.jsx("input",{ref:n,type:"text",readOnly:!0,value:s,onFocus:x=>x.currentTarget.select(),className:"af-input text-xs"})]})]})}const B=s=>s>0?`1ä»¶ Â¥${s.toLocaleString()}`:"å ±é
¬æªè¨å®";function A({link:s}){const n=c.useRef(null);return e.jsxs("div",{className:"af-link-row space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[s.label?e.jsx("div",{className:"text-sm font-semibold text-gray-800",children:s.label}):e.jsx("div",{className:"text-sm font-semibold text-gray-500",children:"ãªã³ã¯"}),e.jsx("div",{className:"text-xs text-gray-400 break-all mt-0.5",children:s.url})]}),e.jsx($,{url:s.url,urlRef:n})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs text-gray-600",children:[e.jsxs("span",{children:["ã¯ãªã㯠",e.jsx("strong",{className:"af-line-green-text",children:s.clickCount})]}),e.jsxs("span",{children:["åã ã¡è¿½å ",e.jsx("strong",{className:"af-line-green-text",children:s.friendAdds})]}),e.jsxs("span",{children:["CVæ¿èªæ¸ã¿ ",e.jsx("strong",{className:"af-line-green-text",children:s.conversionsApproved})]}),e.jsxs("span",{className:"text-gray-400",children:["審æ»ä¸ ",s.conversionsPending]})]})]})}function M({token:s,offerId:n,atLimit:t,onAdded:r}){const[o,d]=c.useState(!1),[f,x]=c.useState(""),[l,p]=c.useState(!1),[h,g]=c.useState(null);async function u(){if(!l){p(!0),g(null);try{const m=await L(s,f.trim()||null,n);r(m),x(""),d(!1)}catch(m){g(m instanceof Error?m.message:String(m))}finally{p(!1)}}}return t?e.jsx("div",{className:"text-xs text-red-600",children:"ãªã³ã¯ã®ä¸éï¼20æ¬ï¼ã«éãã¦ãã¾ã"}):o?e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"text",value:f,onChange:m=>
1x(m.target.value),placeholder:"ä¾: Xç¨ãInstagramç¨",className:"af-input",disabled:l}),h&&e.jsx("div",{className:"text-xs text-red-600",children:h}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:u,disabled:l,className:"af-primary-btn",children:l?"çºè¡ä¸â¦":"ãªã³ã¯ãçºè¡"}),e.jsx("button",{onClick:()=>{d(!1),g(null)},disabled:l,className:"shrink-0 px-4 rounded-xl text-sm text-gray-500",children:"ããã"})]})]}):e.jsx("button",{onClick:()=>d(!0),className:"af-secondary-btn",children:"ï¼ ãã®æ¡ä»¶ç¨ã®ãªã³ã¯ã追å "})}function S({offer:s,offerLinks:n,token:t,atLimit:r,onEnrolled:o,onLinkAdded:d}){const[f,x]=c.useState(!1),[l,p]=c.useState(null),h=c.useRef(!1);async function g(){if(!(f||h.current)){h.current=!0,x(!0),p(null);try{const u=await R(t,s.id);o(u)}catch(u){p(u instanceof Error?u.message:String(u))}finally{x(!1),h.current=!1}}}return e.jsxs("div",{className:"af-card space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-base font-bold text-gray-900",children:s.name}),s.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:s.description})]}),e.jsx("span",{className:"af-badge shrink-0",style:{background:"#ecfdf5",color:"#06C755"},children:B(s.rewardAmount)})]}),s.enrolled?e.jsxs("div",{className:"space-y-2",children:[n.length>0?n.map(u=>e.jsx(A,{link:u},u.refCode)):e.jsx("div",{className:"text-xs text-gray-400 py-1",children:"ãªã³ã¯ã追å ããã¨ç´¹ä»ãå§ãããã¾ã"}),e.jsx(M,{token:t,offerId:s.id,atLimit:r,onAdded:d})]}):e.jsxs(e.Fragment,{children:[l&&e.jsx("div",{className:"text-xs text-red-600",children:l}),e.jsx("button",{onClick:g,disabled:f,className:"af-primary-btn",children:f?"åå ä¸â¦":"ãã®æ¡ä»¶ã«åå ãã"})]})]})}function F({ctx:s}){const n=s.lineAccessToken,[t,r]=c.useState({phase:"loading"}),[o,d]=c.useState(!1),f=c.useRef(!1),x=c.useCallback(async()=>{r({phase:"loading"});try{const a=await O(n);if(a.registered){const i=await C(n).catch(()=>[]);r({phase:"registered",affiliate:a.affiliate,links:a.links,offers:i})}else r({phase:"not_registered"})}catch(a){r({phase:"error",message:a instanceof Error?a.message:String(a)})}},[n]);c.useEffect(()=>{x()},[x]);async function l(){if(!(o||f.current)){f.current=!0,d(!0);try{const a=await I(n),i=await C(n).catch(()=>[]);r({phase:"registered",affiliate:a.affiliate,links:a.links,offers:i})}catch(a){r({phase:"error",message:a instanceof Error?a.message:String(a)})}finally{d(!1),f.current=!1}}}if(t.phase==="loading")return e.jsxs("div",{className:"af-fade-in flex flex-col items-center justify-center py-20 text-gray-500",children:[e.jsx("div",{className:"af-spinner mb-3"}),e.jsx("span",{className:"text-sm",children:"èªã¿è¾¼ã¿ä¸..."})]});if(t.phase==="error")return e.jsxs("div",{className:"af-fade-in max-w-md mx-auto p-4",children:[e.jsx("div",{className:"bg-red-50 text-red-700 p-3 rounded-xl text-sm",children:t.message}),e.jsx("button",{onClick:x,className:"mt-3 text-sm af-line-green-text font-semibold underline",children:"åèªã¿è¾¼ã¿"})]});if(t.phase==="not_registered")return e.jsxs("div",{className:"af-fade-in max-w-md mx-auto p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-gray-900",children:"ã¢ãã£ãªã¨ã¤ã"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 leading-relaxed",children:"æ¡ä»¶ã«åå ãã¦ãSNSãã¨ã«ç´¹ä»ãªã³ã¯ã使ã§ãã¾ãã"})]}),e.jsx("button",{onClick:l,disabled:o,className:"af-primary-btn",children:o?"ç»é²ä¸â¦":"ã¯ããã"})]});const{links:p,offers:h}=t,g=p.length>=20,u=[...p].reverse(),m=new Map,j=[];for(const a of u)if(a.offerId){const i=m.get(a.offerId)??[];i.push(a),m.set(a.offerId,i)}else j.push(a);const N=h.filter(a=>a.enrolled),k=h.filter(a=>!a.enrolled);function w(a){r(i=>{if(i.phase!=="registered")return i;const E=i.offers.map(b=>b.id===a.offerId?{...b,enrolled:!0,refCode:a.refCode,url:a.url}:b);return{...i,links:[...i.links,a],offers:E}})}function v(a){r(i=>i.phase!=="registered"?i:{...i,links:[...i.links,a]})}return e.jsxs("div",{className:"af-fade-in max-w-md mx-auto p-4 pb-12 space-y-5",style:{background:"#f7f8fa",minHeight:"100vh"},children:[e.jsx("h1",{className:"text-lg font-bold text-gray-900",children:"ã¢ãã£ãªã¨ã¤ã"}),N.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide px-1",children:"åå ä¸ã®æ¡ä»¶"}),N.map(a=>e.jsx(S,{offer:a,offerLinks:m.get(a.id)??[],token:n,atLimit:g,onEnrolled:w,onLinkAdded:v},a.id))]}),k.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide px-1",children:"åå ã§ããæ¡ä»¶"}),k.map(a=>e.jsx(S,{offer:a,offerLinks:[],token:n,atLimit:g,onEnrolled:w,onLinkAdded:v},a.id))]}),j.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide px-1",children:"ãã®ä»ã®ãªã³ã¯"}),e.jsx("div",{className:"af-card space-y-2",children:j.map(a=>e.jsx(A,{link:a},a.refCode))})]}),h.length===0&&j.length===0&&e.jsx("div",{className:"af-card text-center text-sm text-gray-500",children:"ç¾å¨åå ã§ããæ¡ä»¶ã¯ããã¾ãã"})]})}function J(s,n){document.body.classList.add("af-active"),y&&(y.unmount(),y=null),s.innerHTML="",y=T.createRoot(s),y.render(e.jsx(c.StrictMode,{children:e.jsx(F,{ctx:n})}))}export{J as mountAffiliate};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.