1import{m as ae,b5 as ne,aA as ie,a7 as le,aF as R,aE as re,aD as ce,r as d,i as z,s as F,b as r,$ as U,w as _,b9 as J,a as i,aU as ue,ah as o,c as m,e as s,j as v,l as x,F as de,k as me,t as L,av as pe,_ as fe,aM as _e,b6 as ve,aV as he,aL as ye,aZ as xe}from"./CVB3sd8v.js";import{_ as ge}from"./CIEsYy7i.js";import{_ as be}from"./DxviTe1l.js";import{_ as we}from"./BOHKVDT7.js";import{g as Ce}from"./CnByW1Hk.js";import{normalizeDomain as g}from"./B22Qej_J.js";import{t as ke,W as Se}from"./BTHDixBy.js";import"./BYy6r0pa.js";import"./Cs_qtKOX.js";import"./UA6336Ao.js";const Ue={key:0,class:"mb-6 flex justify-start opacity-80"},De={class:"w-full max-w-xl p-2 bg-indigo-50 border border-indigo-100 rounded-md"},Ne={class:"flex items-start gap-2"},Te={key:1,class:"flex space-x-2"},Ee={key:1,class:"divide-y divide-gray-200/80 dark:divide-gray-800"},$e={class:"flex items-center space-x-4 rounded-md"},Ve={class:"flex-shrink-0 flex justify-center p-0.5 items-center rounded-md border border-gray-100 shadow-sm"},Ae={class:"flex-1 min-w-0"},Pe={class:"text-sm font-semibold font-serif text-gray-900 dark:text-white truncate"},je={key:0,class:"text-xs text-gray-500 dark:text-gray-400 truncate"},Oe={key:2,class:"text-gray-500 dark:text-gray-400"},Ie={key:3,class:"text-gray-500 max-w-xl text-xs dark:text-gray-400"},Me={key:4,class:"mt-4 p-3 bg-gradient-to-r from-purple-50 to-indigo-50 rounded-md border border-indigo-100"},Ye={class:"text-sm text-indigo-700 font-medium font-serif mb-2.5"},Re={key:5,class:"mt-6 w-full lg:w-[540px]"},ze={class:"flex items-start space-x-2"},Fe={class:"flex justify-between items-center"},Je={class:"text-xl font-semibold text-green-600 font-serif flex items-center"},Le={class:"flex justify-end space-x-2"},st=ae({__name:"competitors",setup(Be){const{hasActiveSubscription:V}=ne(),A=ie(),D=le(),{currentProject:N}=R(D),B=re(),{currentPlan:q}=R(B),h=ce(),b=d([]),a=d([]),p=d(!1),u=d(""),w=d(!1),P=d(""),C=d(!1),k=d(!1),T=d(!1),y=d(null),E=z(()=>u.value?ke(u.value):null);F(E,e=>{e&&!e.isAmbiguous||e?y.value=e:y.value=null});function j(e){if(!e)return"";const t=e.sourceType;return t==="website_subpath"&&e.canonicalUrl?e.canonicalUrl.replace(/^https?:\/\//i,"").replace(/^www\./i,"").replace(/\/$/,""):t==="app_store_ios"?"App Store":t==="app_store_android"?"Google Play":e.domain}const S=z(()=>{var t,f;const e=q.value;return e&&((f=(t=J[e])==null?void 0:t.quota)!=null&&f.competitors)?J[e].quota.competitors:3});F(()=>N.value,e=>{e!=null&&e.website_competitors&&(a.value=[...e.website_competitors],b.value=[...e.website_competitors])},{immediate:!0});const O=()=>{p.value?(a.value=JSON.parse(JSON.stringify(b.value)),u.value="",P.value=""):b.value=JSON.parse(JSON.stringify(a.value)),p.value=!p.value},W=()=>{u.value="",y.value=null,C.value=!1},G=()=>{if(u.value&&C.value&&a.value.length<S.value){const e=y.value;a.value.push({domain:(e==null?void 0:e.domain)??g(u.value),canonicalUrl:(e==null?void 0:e.canonicalUrl)??`https://${g(u.value)}`,sourceType:(e==null?void 0:e.sourceType)??"website",appStoreId:(e==null?void 0:e.appStoreId)??null}),u.value="",y.value=null}},H=e=>{a.value.length>1?a.value.splice(e,1):h.add({title:"Cannot remove competitor",description:"You must have at least one competitor",color:"red",icon:"i-heroicons-exclamation-circle",timeout:5e3})},K=e=>{C.value=e},X=async()=>{if(a.value.length===0){h.add({title:"Validation Error",description:"You must have at least one competitor",color:"red",icon:"i-heroicons-exclamation-circle",timeout:5e3});return}w.value=!0,P.value="";try{const e=a.value.filter(n=>n.domain&&n.domain.trim()!==""),t=e.map(n=>g(n.domain)),f=e.map(n=>({domain:n.domain??g(n.domain),canonicalUrl:n.canonicalUrl??`https://${g(n.domain)}`,sourceType:n.sourceType??"website",appStoreId:n.appStoreId??null}));if(t.length===0){h.add({title:"Validation Error",description:"You must have at least one valid competitor",color:"red",icon:"i-heroicons-exclamation-circle",timeout:5e3}),w.value=!1;return}const c=await A(`/projects/edit-competitors/${N.value.id}`,{method:"POST",body:{competitorWebsites:t,competitorSourceData:f}});await D.fetchAndSetCurrentProject(),b.value=JSON.parse(JSON.stringify(a.value)),p.value=!1,k.value=!0}catch(e){try{await D.fetchAndSetCurrentProject()}catch{}if((e==null?void 0:e.code)==="COMPETITOR_UPDATE_LIMIT_EXCEEDED"){const t=(e==null?void 0:e.meta)||{used:0,allowed:2},f=t.cycleStart?new Date(t.cycleStart):new Date,c=new Date(f);c.setMonth(c.getMonth()+1);const n=c.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"});h.add({title:"Update Limit Exceeded",description:`You've already used ${t.used}/${t.allowed} updates this cycle. Next update available after ${n}.`,color:"red",icon:"i-heroicons-exclamation-circle",timeout:7e3})}else h.add({title:"Failed to save competitors",description:(e==null?void 0:e.message)||"Please reach out to supp
1ort if the issue persists.",color:"red",icon:"i-heroicons-exclamation-circle",timeout:5e3})}finally{w.value=!1}},Z=async()=>{T.value=!0;try{const e=await A(`/projects/rerun-serp-opportunities/${N.value.id}`,{method:"POST"});h.add({title:"Success",description:"Searchbox results rerun has been scheduled successfully. You will be notified via email when the results are ready.",color:"green",icon:"i-heroicons-check-circle",timeout:5e3}),k.value=!1}catch{h.add({title:"Error scheduling rerun",description:"Failed to schedule searchbox rerun. Please try again later or contact support.",color:"red",icon:"i-heroicons-exclamation-circle",timeout:5e3})}finally{T.value=!1}},$=()=>{k.value=!1};return(e,t)=>{const f=fe,c=_e,n=ve,I=he,Q=ye,ee=ge,te=be,oe=xe,se=we;return r(),U(se,{class:"pb-24"},{default:_(()=>[i(te,{title:"Competitors",description:`Manage your project's competitors. Your plan allows you to add up to ${o(S)} competitors.`,ui:{links:"flex flex-wrap items-center gap-1.5 ml-auto"}},ue({default:_(()=>{var M;return[o(p)?(r(),m("div",Ue,[s("div",De,[s("div",Ne,[i(f,{name:"i-heroicons:information-circle",class:"text-indigo-500 flex-shrink-0 size-4 mt-0.5"}),t[2]||(t[2]=s("span",{class:"text-xs text-indigo-700 leading-relaxed text-left w-full"},[s("span",{class:"font-medium"},"You can change your competitors twice a month."),v(" Choose carefully. ")],-1))])])])):x("",!0),o(a).length?(r(),m("ul",Ee,[(r(!0),m(de,null,me(o(a),(l,Y)=>(r(),m("li",{key:l.domain+Y,class:"py-4 w-full lg:w-[400px]"},[i(I,{class:"",ui:{body:{padding:"sm:p-3"}}},{default:_(()=>[s("div",$e,[s("div",Ve,[i(n,{src:o(Ce)(l.domain),alt:l.domain,size:"2xs"},null,8,["src","alt"])]),s("div",Ae,[s("p",Pe,L(l.company_name||l.domain),1),l.sourceType&&l.sourceType!=="website"&&j(l)!==l.domain?(r(),m("p",je,L(j(l)),1)):x("",!0)]),o(p)?(r(),U(c,{key:0,color:"red",variant:"ghost",icon:"i-heroicons-trash",disabled:o(a).length<=1,onClick:qe=>H(Y)},null,8,["disabled","onClick"])):x("",!0)])]),_:2},1024)]))),128))])):(r(),m("p",Oe," No competitors added yet. ")),o(V)?x("",!0):(r(),m("p",Ie," You can only change competitors if you have an active subscription. ")),!o(p)&&o(a).length>=o(S)?(r(),m("div",Me,[s("p",Ye,[t[4]||(t[4]=v(" Need to track more competitors? ")),i(Q,{to:"/app/settings/project/billing",class:"underline font-semibold font-serif"},{default:_(()=>t[3]||(t[3]=[v("Upgrade your plan â")])),_:1})])])):x("",!0),o(p)&&o(a).length<o(S)?(r(),m("div",Re,[s("div",ze,[i(ee,{modelValue:o(u),"onUpdate:modelValue":t[0]||(t[0]=l=>pe(u)?u.value=l:null),placeholder:"https://competitor.com",class:"flex-1",size:"md",onValidationChange:K},null,8,["modelValue"]),i(c,{size:"md",label:"Add Competitor",color:"gray",disabled:!o(u)||!o(C),onClick:G},null,8,["disabled"])]),(M=o(E))!=null&&M.isAmbiguous?(r(),U(Se,{key:0,compact:"",parsed:o(E),"onUpdate:effective":t[1]||(t[1]=l=>y.value=l),onRequestNewUrl:W},null,8,["parsed"])):x("",!0)])):x("",!0)]}),_:2},[o(V)?{name:"links",fn:_(()=>[o(p)?(r(),m("div",Te,[i(c,{label:"Cancel",color:"gray",onClick:O}),i(c,{label:"Save Changes",color:"primary",loading:o(w),onClick:X},null,8,["loading"])])):(r(),U(c,{key:0,label:"Edit Competitors",color:"gray",onClick:O}))]),key:"0"}:void 0]),1032,["description"]),i(oe,{"model-value":o(k),"prevent-close":"",onClose:$},{default:_(()=>[i(I,null,{header:_(()=>[s("div",Fe,[s("div",null,[s("h3",Je,[i(f,{name:"i-heroicons-check-circle",class:"text-green-600 mr-2 size-5"}),t[5]||(t[5]=v(" Competitors Updated Successfully "))]),t[6]||(t[6]=s("p",{class:"text-sm opacity-60 mt-2"}," Here's what will happen next: ",-1))]),i(c,{color:"gray",variant:"ghost",icon:"i-heroicons-x-mark-20-solid",onClick:$})])]),footer:_(()=>[s("div",Le,[i(c,{color:"gray",label:"Close",onClick:$}),i(c,{color:"primary",loading:o(T),label:"Rerun Searchbox Results",onClick:Z},null,8,["loading"])])]),default:_(()=>[t[7]||(t[7]=s("div",{class:"space-y-4 py-2"},[s("p",{class:"text-sm text-gray-600"},[s("span",{class:"gradient-text-primary font-semibold"},"New opportunities"),v(" and "),s("span",{class:"gradient-text-primary font-semibold"},"mentions"),v(" will reflect the updated competitors with the "),s("span",{class:"font-semibold"},"next scheduled run.")]),s("p",{class:"text-sm text-gray-600"},[v(" You can also rerun the "),s("span",{class:"gradient-text-primary font-semibold"},"Searchbox"),v(" search results "),s("span",{class:"font-semibold"},"immediately"),v(" to see them adjusted to your new competitors by clicking the button below. ")])],-1))]),_:1})]),_:1},8,["model-value"])]),_:1})}}});
1export{st as default};
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.