PageSourceSearch

https://app.adcero.io/_next/static/chunks/1624.b85e80c000f337a1.js

js adcero.io collected 2026-09-24 15:05:15 UTC 173,214 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1624],{4538:(e,t,a)=>{a.d(t,{k:()=>s});var i=a(12115);let n=(e,t)=>{let a=e instanceof Map?e:new Map(e.entries()),i=t instanceof Map?t:new Map(t.entries());if(a.size!==i.size)return!1;for(let[e,t]of a)if(!i.has(e)||!Object.is(t,i.get(e)))return!1;return!0};function s(e){let t=i.useRef(void 0);return a=>{let i=e(a);return!function(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;if(Symbol.iterator in e&&Symbol.iterator in t){if("entries"in e&&"entries"in t)return n(e,t);let a=e[Symbol.iterator](),i=t[Symbol.iterator](),s=a.next(),r=i.next();for(;!s.done&&!r.done;){if(!Object.is(s.value,r.value))return!1;s=a.next(),r=i.next()}return!!s.done&&!!r.done}return n({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}(t.current,i)?t.current=i:t.current}}},6132:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]])},6872:(e,t,a)=>{a.r(t),a.d(t,{CreateCampaignModal:()=>ag});var i=a(95155),n=a(12115),s=a(82734),r=a(96159),l=a(30948),o=a(97377),d=a(55546);function c(e,t){return[e,...null!=t?t:[]].filter(e=>"string"==typeof e&&e.trim().length>0).slice(0,5).map(e=>({text:e}))}function u(e){return[e.primaryTextOptions,e.headlineOptions,e.descriptionOptions].some(e=>null==e?void 0:e.some(e=>e.trim().length>0))}function m(e){let{adDetailsData:t,callToActionType:a,websiteUrl:i}=e,n=c(t.primaryText,t.primaryTextOptions),s=c(t.headline,t.headlineOptions),r=c(t.description,t.descriptionOptions);return{...n.length>0?{bodies:n}:{},...s.length>0?{titles:s}:{},...r.length>0?{descriptions:r}:{},call_to_action_types:[a],link_urls:[{website_url:i}]}}var p=a(57408);let g={square:"100x100",horizontal:"191x100",vertical:"56x100"};function h(e,t,a){let i={},n=!1;for(let s of e){if("specific"!==s.aspectRatio||!s.cropData)continue;let e=g[s.placementType];if(!e){console.warn("Unknown placement type: ".concat(s.placementType));continue}let r=function(e,t,a){let i=Math.round(e.x/100*t),n=Math.round(e.y/100*a);return[[i,n],[Math.round((e.x+e.width)/100*t),Math.round((e.y+e.height)/100*a)]]}(s.cropData,t,a);i[e]=r,n=!0}return n?i:void 0}function f(e,t,a,i){console.log("[Image Crops] Input placements:",JSON.stringify(e,null,2)),console.log("[Image Crops] Image dimensions:",{width:a,height:i}),console.log("[Image Crops] Transformed to Meta format:",JSON.stringify(t,null,2))}var x=a(94469);function b(e){return!!(e&&e.videoId)}let v="ar_default",y={facebook:["story","facebook_reels","facebook_reels_overlay"],instagram:["story","reels","profile_reels"],messenger:["story"],audience_network:[]},S={facebook:["right_hand_column","search","instream_video","instant_article"],instagram:[],messenger:[],audience_network:["classic","native_banner","interstitial","rewarded_video","instream_video"]},j=["facebook","instagram","messenger","audience_network"];function A(e){return"ar_".concat(e.replace(/[:.]/g,"_"))}function C(e,t){return{video_id:e.videoId,...e.thumbnailHash?{thumbnail_hash:e.thumbnailHash}:{},...e.thumbnailUrl?{thumbnail_url:e.thumbnailUrl}:{},adlabels:[{name:t}]}}async function w(e,t,a,i){var n;let s=a.videoVersions;if(!s||0===Object.keys(s).length)return;let r=null==(n=e.media)?void 0:n.uploadVideoFromUrl;if("function"!=typeof r)return;let l={};for(let[e,t]of Object.entries(s)){let a=(null==t?void 0:t.url)?(0,d.JI)(t.url):"";if(a)try{let t=await r(a);l[e]={videoId:t.id,thumbnailHash:i.thumbnailHash,thumbnailUrl:i.thumbnailUrl}}catch(t){console.warn("[Video Versions] Failed to upload ".concat(e," version to Meta:"),t)}}if(0!==Object.keys(l).length)return function(e){var t,a,i,n,s;let{versionRefs:r,masterVideo:l,placements:o}=e;if(!b(l))return;let d=e=>{let t=r[e];return b(t)?t:void 0},c=(0,x.H4)(o),u={facebook:null!=(t=c.facebook_positions)?t:[],instagram:null!=(a=c.instagram_positions)?a:[],messenger:null!=(i=c.messenger_positions)?i:[],audience_network:null!=(n=c.audience_network_positions)?n:[]};if(0===j.reduce((e,t)=>
1e+u[t].length,0))return;let m=d("4:5")?"4:5":d("1:1")?"1:1":null,p=(e,t)=>y[e].includes(t)?d("9:16")?"9:16":null:S[e].includes(t)?d("16:9")?"16:9":null:m,g=new Map;for(let e of j)for(let t of u[e]){let a=p(e,t);if(!a||!d(a))continue;let i="".concat(a,"__").concat(e),n=null!=(s=g.get(i))?s:{ratio:a,platform:e,positions:[]};n.positions.push(t),g.set(i,n)}let h=[],f=new Set;for(let{ratio:e,platform:t,positions:a}of g.values())f.add(e),h.push({customization_spec:{publisher_platforms:[t],["".concat(t,"_positions")]:a},video_label:{name:A(e)}});if(0===f.size)return;h.push({is_default:!0,customization_spec:{},video_label:{name:v}});let w=[C(l,v)];for(let e of f)w.push(C(d(e),A(e)));return{videos:w,asset_customization_rules:h,optimization_type:"PLACEMENT"}}({versionRefs:l,masterVideo:i,placements:{placementType:t.placementType,selectedPlacements:t.selectedPlacements,selectedDevices:t.selectedDevices}})}async function N(e){return new Promise(t=>{let a=new Image;a.crossOrigin="anonymous",a.onload=()=>{t({width:a.naturalWidth,height:a.naturalHeight})},a.onerror=()=>{console.warn("[Image Crops] Could not load thumbnail for dimensions:",e),t(null)},a.src=e})}async function _(e,t){var a;let i=null==(a=e.media)?void 0:a.placementCrops;if(!i||0===i.length||!t||!i.some(e=>"specific"===e.aspectRatio&&e.cropData))return;let n=await N(t);if(!n)return void console.warn("[Image Crops] Could not determine thumbnail dimensions, skipping crops");let s=h(i,n.width,n.height);return f(i,s,n.width,n.height),s}async function k(e,t,a){var i;if(t.media.file&&"video"===t.media.type)return{videoId:(await e.uploadVideo(t.media.file)).id,mainAssetFile:t.media.file};let n=(0,d.JI)(a.videoUrl||a.url||"");if(!n)throw Error("Video file could not be prepared for upload");if("function"==typeof(null==(i=e.media)?void 0:i.uploadVideoFromUrl))return{videoId:(await e.media.uploadVideoFromUrl(n)).id,mainAssetFile:null,mainAssetSourceUrl:n};throw Error("Video file could not be prepared for upload")}async function E(e,t,a){let i,n,s=(0,d.JI)(a.url);if(!s)throw Error("A video thumbnail image is required. Select a library video with a thumbnail or attach an image.");let r=null,l=await (0,d.co)(s,"".concat(t.adName||"thumbnail",".jpg"));if(l)try{i=(await e.uploadImage(l)).hash,r=l}catch(e){}return!r&&s&&(n=s),{thumbHash:i,videoThumbnailFile:r,videoThumbnailUrl:n}}async function I(e){let{apiService:t,adDetailsData:a,adSetDetailsData:i,selectedCreative:n}=e,{videoId:s,mainAssetFile:r,mainAssetSourceUrl:l}=await k(t,a,n),{thumbHash:o,videoThumbnailFile:c,videoThumbnailUrl:g}=await E(t,a,n),h=await w(t,i,n,{videoId:s,thumbnailHash:o,thumbnailUrl:g}),f=h?void 0:await _(a,n.url),x="phone_call"===a.destinationType?(0,d.AY)(a):(0,p.W)((0,d.JI)((0,d.AY)(a))||(0,d.AY)(a)),b=(0,d.Qc)(a.callToAction),v={page_id:a.selectedPageId||i.facebookPageId,...a.selectedInstagramId?{instagram_actor_id:a.selectedInstagramId}:{}},y=function(e){let{adDetailsData:t,callToActionType:a,format:i,thumbnailHash:n,thumbnailUrl:s,videoId:r,websiteUrl:l,placementFeed:o}=e;if(!u(t)&&!o)return;let d={...m({adDetailsData:t,callToActionType:a,websiteUrl:l}),ad_formats:[i]};return o?{...d,videos:o.videos,asset_customization_rules:o.asset_customization_rules,optimization_type:o.optimization_type}:{...d,videos:[{video_id:r,...n?{thumbnail_hash:n}:{},...s?{thumbnail_url:s}:{}}]}}({adDetailsData:a,callToActionType:b,format:"SINGLE_VIDEO",thumbnailHash:o,thumbnailUrl:g,videoId:s,websiteUrl:x,placementFeed:h}),S={name:"".concat(a.adName," - Creative"),url_tags:(0,d.qk)(a.urlParameters),...f?{image_crops:f}:{},...y?{asset_feed_spec:y}:{},object_story_spec:{...v,...!y?{video_data:{video_id:s,message:a.primaryText,...a.headline?{title:a.headline}:{},...a.description?{link_description:a.description}:{},call_to_action:{type:b,value:{link:x}},...o?{image_hash:o}:{}}}:{}}};return console.log("Creating video ad creative with data:",S),f&&console.log("[Image Crops] Sending thumbnail crops to Meta API:",JSON.stringify(f,null,2)),{creativeId:(await t.createAdCreative(S)).id,videoId:s,mainAssetFile:r,mainAssetSourceUrl:l,videoThumbnailFile:c,videoThumbnailUrl:g}}function T(e){return!!(e&&(e.hash||e.url))}let D="ar_default",P={facebook:["story","facebook_reels","facebook_reels_overlay"],instagram:["story","reels","profile_reels"],messenger:["story"],audience_network:[]},O={facebook:["right_hand_column","search","instream_video","instant_article"],instagram:[],messenger:[],audience_network:["classic","native_banner","interstitial","rewarded_video","instream_video"]},L=["facebook","instagram","messenger","audience_network"];function M(e){return"ar_".concat(e.replace(/[:.]/g,"_"))}async function F(e,t){return e?new Promise(t=>{let a=new Image,i=URL.createObjectURL(e);a.onload=()=>
1{URL.revokeObjectURL(i),t({width:a.naturalWidth,height:a.naturalHeight})},a.onerror=()=>{URL.revokeObjectURL(i),t(null)},a.src=i}):t?new Promise(e=>{let a=new Image;a.crossOrigin="anonymous",a.onload=()=>{e({width:a.naturalWidth,height:a.naturalHeight})},a.onerror=()=>{console.warn("[Image Crops] Could not load image for dimensions:",t),e(null)},a.src=t}):null}async function U(e,t){var a,i;let n=null==(a=e.media)?void 0:a.placementCrops;if(!n||0===n.length||!n.some(e=>"specific"===e.aspectRatio&&e.cropData))return;let s=await F(null==(i=e.media)?void 0:i.file,t.url);if(!s)return void console.warn("[Image Crops] Could not determine image dimensions, skipping crops");let r=h(n,s.width,s.height);return f(n,r,s.width,s.height),r}async function R(e,t,a){if(t.media.file&&"image"===t.media.type)return{imageHash:(await e.uploadImage(t.media.file)).hash,mainAssetFile:t.media.file};if(a.url){let i=(0,d.JI)(a.url),n=await (0,d.co)(i,"".concat(t.adName||"image",".jpg"));return n?{imageHash:(await e.uploadImage(n)).hash,mainAssetFile:n}:{mainAssetFile:null,mainAssetSourceUrl:i}}return{mainAssetFile:null}}async function B(e){let{apiService:t,adDetailsData:a,adSetDetailsData:i,selectedCreative:n}=e,[s,r]=await Promise.all([R(t,a,n),U(a,n)]),{imageHash:l,mainAssetFile:o,mainAssetSourceUrl:c}=s,g=l?{hash:l}:c?{url:c}:n.url?{url:(0,d.JI)(n.url)}:{},h=function(e,t,a){let i=e.versions;if(!e.isVideo&&i&&0!==Object.keys(i).length)return function(e){var t,a,i,n,s;let{versions:r,masterImage:l,versionImageByRatio:o,placements:d}=e;if(!T(l))return;let c=e=>{var t;let a=null==o?void 0:o[e];if(T(a))return a;let i=null==(t=r[e])?void 0:t.url;return i?{url:i}:void 0},u=(0,x.H4)(d),m={facebook:null!=(t=u.facebook_positions)?t:[],instagram:null!=(a=u.instagram_positions)?a:[],messenger:null!=(i=u.messenger_positions)?i:[],audience_network:null!=(n=u.audience_network_positions)?n:[]};if(0===L.reduce((e,t)=>e+m[t].length,0))return;let p=T(c("4:5"))?"4:5":T(c("1:1"))?"1:1":null,g=(e,t)=>P[e].includes(t)?T(c("9:16"))?"9:16":null:O[e].includes(t)?T(c("1.91:1"))?"1.91:1":null:p,h=new Map;for(let e of L)for(let t of m[e]){let a=g(e,t);if(!a||!T(c(a)))continue;let i="".concat(a,"__").concat(e),n=null!=(s=h.get(i))?s:{ratio:a,platform:e,positions:[]};n.positions.push(t),h.set(i,n)}let f=[],b=new Set;for(let{ratio:e,platform:t,positions:a}of h.values())b.add(e),f.push({customization_spec:{publisher_platforms:[t],["".concat(t,"_positions")]:a},image_label:{name:M(e)}});if(0===b.size)return;f.push({is_default:!0,customization_spec:{},image_label:{name:D}});let v=[{...l,adlabels:[{name:D}]}];for(let e of b)v.push({...c(e),adlabels:[{name:M(e)}]});return{images:v,asset_customization_rules:f,optimization_type:"PLACEMENT"}}({versions:i,masterImage:a,placements:{placementType:t.placementType,selectedPlacements:t.selectedPlacements,selectedDevices:t.selectedDevices}})}(n,i,g),f=h?void 0:r,b=(0,p.W)((0,d.JI)((0,d.qj)(a))||""),v=(0,d.AY)(a),y="phone_call"===a.destinationType?v:(0,p.W)((0,d.JI)(v)||v),S=(0,d.Qc)(a.callToAction),j={page_id:a.selectedPageId||i.facebookPageId,...a.selectedInstagramId?{instagram_actor_id:a.selectedInstagramId}:{}},A=function(e){let{adDetailsData:t,callToActionType:a,format:i,imageHash:n,imageUrl:s,websiteUrl:r,placementFeed:l}=e;if(!u(t)&&!l)return;let o={...m({adDetailsData:t,callToActionType:a,websiteUrl:r}),ad_formats:[i]};if(l)return{...o,images:l.images,asset_customization_rules:l.asset_customization_rules,optimization_type:l.optimization_type};let d=n?[{hash:n}]:s?[{url:s}]:[];return{...o,...d.length>0?{images:d}:{}}}({adDetailsData:a,callToActionType:S,format:"SINGLE_IMAGE",imageHash:l,imageUrl:!l&&n.url?(0,d.JI)(n.url):void 0,websiteUrl:b,placementFeed:h}),C={name:"".concat(a.adName," - Creative"),url_tags:(0,d.qk)(a.urlParameters),...f?{image_crops:f}:{},...A?{asset_feed_spec:A}:{},object_story_spec:{...j,...!A?{link_data:{link:b,message:a.primaryText,name:a.headline,description:a.description,call_to_action:{type:S,value:{link:y}},...l?{image_hash:l}:{},...!l&&n.url?{picture:(0,d.JI)(n.url)}:{},...f?{image_crops:f}:{}}}:{}}};return console.log("Creating image ad creative with data:",C),f&&console.log("[Image Crops] Sending to Meta API:",JSON.stringify(f,null,2)),{creativeId:(await t.createAdCreative(C)).id,imageHash:l,mainAssetFile:o,mainAssetSourceUrl:c,videoThumbnailFile:null}}async function V(e,t){if(t.isVideo){if(t.videoId)return{imageHash:t.imageHash,videoId:t.videoId};if(t.file){let a=await e.uploadVideo(t.file);return{imageHash:t.imageHash,videoId:a.id}}if(t.videoUrl){let a=(0,d.JI)(t.videoUrl),i="carousel-card-".concat(t.id,".mp4"),n=await (0,d.co)(a,i);if(n){let a=await e.uploadVideo(n);return{imageHash:t.imageHash,videoId:a.id}}}return{imageHash:t.imageHash}}if(t.imageHash)return{imageHash:t.imageHash};if(t.file)return{imageHash:(await e.uploadImage(t.file)).hash};if(t.previewUrl){let a=(0,d.JI)(t.previewUrl),i="carousel-card-".concat(t.id,".jpg"),n=await (0,d.co)(a,i);if(n)return{imageHash:(await e.uploadImage(n)).hash}}return{}}async function G(e){var t,a;let{apiService:i,adDetailsData:n,adSetDetailsData:s,carouselItems:r}=e;if(!r||r.length<2)throw Error("Carousel ads require at least 2 cards");if(r.find(e=>e.isVideo&&!e.imageHash))throw Error("Carousel video cards require a thumbnail image hash before publishing.");let l=r.map(e=>V(i,e)),o=await Promise.all(l);o.forEach((e,t)=>{let a=r[t];if((null==a?void 0:a.isVideo)&&(!e.videoId||!e.imageHash))throw Error("Carousel video cards require a video source and thumbnail image hash before publishing.")});let c=r.map((e,t)=>{let a=o[t],i=(0,p.W)((0,d.JI)(e.url||n.websiteUrl||n.destinationUrl||"")||""),s=(0,d.AY)(n),r="phone_call"===n.destinationType?s:(0,p.W)((0,d.JI)(s)||s),l={link:i,name:e.headline||n.headline,description:e.description||n.description,call_to_action:{type:(0,d.Qc)(n.callToAction),value:{link:r}}};return a.imageHash&&(l.image_hash=a.imageHash),a.videoId&&(l.video_id=a.videoId),l}),u={name:"".concat(n.adName," - Carousel Creative"),url_tags:(0,d.qk)(n.urlParameters),object_story_spec:{page_id:n.selectedPageId||s.facebookPageId,...n.selectedInstagramId?{instagram_actor_id:n.selectedInstagramId}:{},link_data:{link:(0,p.W)((0,d.JI)(n.websiteUrl||n.destinationUrl||"")||""),message:n.primaryText,child_attachments:c,multi_share_optimized:!0,multi_share_end_card:!1}}};console.log("Creating carousel ad creative with data:",u);let m=await i.createAdCreative(u),g=o[0];return{creativeId:m.id,imageHash:null==g?void 0:g.imageHash,mainAssetFile:(null==(t=r[0])?void 0:t.file)||null,mainAssetSourceUrl:null==(a=r[0])?void 0:a.previewUrl,videoThumbnailFile:null}}var z=a(8525);async function q(e){let{verifiedAd:t,adDetailsData:a,adSetId:i,campaignId:n,creativeId:s,apiConfig:r,connectedPages:l,resolvedPageId:o}=e,d=function(e,t,a){var i,n,s,r,l,o;let d=a?t.find(e=>e.page.id===a):void 0,c=e.selectedCreative;return{primaryText:e.primaryText||null,headline:e.headline||null,description:e.description||null,websiteUrl:e.websiteUrl||e.destinationUrl||null,displayLink:e.displayLink||null,callToAction:e.callToAction||null,pageId:a,pageName:(null==d||null==(i=d.page)?void 0:i.name)||null,pageLogoUrl:(null==d||null==(r=d.page)||null==(s=r.picture)||null==(n=s.data)?void 0:n.url)||(null==d||null==(l=d.page)?void 0:l.logo_url)||null,facebookUsername:null,instagramUsername:(null==d||null==(o=d.instagram)?void 0:o.username)||null,adFormat:e.adFormat||null,imageUrl:(null==c?void 0:c.url)||(null==c?void 0:c.previewUrl)||null,thumbnailUrl:(null==c?void 0:c.previewUrl)||(null==c?void 0:c.url)||null,videoId:null,videoUrl:(null==c?void 0:c.videoUrl)||null}}(a,l,o),c={...t,adset_id:i,campaign_id:n,name:a.adName,status:t.status||"ACTIVE",creative_id:s,ad_format:a.adFormat||null,primary_text_1:d.primaryText,headline_1:d.headline,description_1:d.description,website_url:d.websiteUrl,display_link:d.displayLink,call_to_action_type:d.c
1allToAction,page_id:o,page_logo_url:d.pageLogoUrl,facebook_username:d.facebookUsername,instagram_username:d.instagramUsername,image_url:d.imageUrl,thumbnail_url:d.thumbnailUrl,video_id:d.videoId,video_url:d.videoUrl};console.log("Saving ad to database with details:",{adId:t.id,adset_id:i,campaign_id:n});let{data:{session:u}}=await z.supabase.auth.getSession(),m={"Content-Type":"application/json"};(null==u?void 0:u.access_token)&&(m.Authorization="Bearer ".concat(u.access_token));let p=await fetch("/api/ads/save",{method:"POST",headers:m,body:JSON.stringify({adId:t.id,adDetails:c,adAccountId:r.adAccountId,adMetadata:d}),credentials:"include"});if(!p.ok){let e=await p.json();throw console.error("Failed to save ad to database:",e),Error(e.error||"Failed to save ad to database")}console.log("Ad successfully saved to database")}async function H(e){let{creativeId:t,adId:a,apiConfig:i,isVideo:n,mainAssetFile:s,mainAssetSourceUrl:r,videoThumbnailFile:l,videoThumbnailUrl:o}=e,d=new FormData;d.append("creativeId",t),d.append("adAccountId",i.adAccountId),d.append("adId",a),d.append("fileType",n?"video":"image"),s?d.append("file",s):r&&d.append("sourceUrl",r),n&&(l?d.append("thumbnailFile",l):o&&d.append("thumbnailUrl",o));let{data:{session:c}}=await z.supabase.auth.getSession(),u={};(null==c?void 0:c.access_token)&&(u.Authorization="Bearer ".concat(c.access_token)),await fetch("/api/assets/save-creative",{method:"POST",headers:u,body:d,credentials:"include"})}var W=a(65820),Y=a(25647),$=a(46276),J=a(305),K=a(94161),Z=a(94509);function X(e){return(0,J.Dv)(null!=e?e:"")}async function Q(e){var t;let{apiService:a,adDetailsData:i}=e,n=null==(t=i.existingPostId)?void 0:t.trim();if(!n)throw Error("An existing post ID is required to publish an existing post ad.");return{creativeId:(await a.createAdCreative({name:"".concat(i.adName," - Existing Post Creative"),url_tags:(0,d.qk)(i.urlParameters),object_story_id:n})).id,mainAssetFile:null,videoThumbnailFile:null}}var ee=a(39849),et=a(64895);async function ea(){let{data:{session:e}}=await z.supabase.auth.getSession();return{"Content-Type":"application/json",...(null==e?void 0:e.access_token)?{Authorization:"Bearer ".concat(e.access_token)}:{}}}async function ei(e){let{campaignId:t,campaignSettings:a,createCampaign:i,setSelectedCampaign:n}=e;if(t)return t;if(!i||!a)throw Error("Campaign creation functions are required when campaign does not exist");if(!a.name.trim())throw Error("Campaign name is required");let s=(0,ee.M)(a),r=await i(s);return null==n||n({id:r,name:a.name,objective:a.objective,status:"ACTIVE",buying_type:a.buyingType||"AUCTION",created_time:new Date().toISOString(),updated_time:new Date().toISOString()}),r}async function en(e){let{adSetId:t,campaignId:a,apiService:i,adSetDetailsData:n,campaignSettings:s,mapAdSetDataToApiFormat:r,apiConfig:l,organizationId:o,userId:d,syncNewEntity:c,setPublishedAdSet:u}=e;if(t)return t;if(!r||!s)throw Error("Ad set creation functions are required when ad set does not exist");let m=r(n,s,a),p=await i.createAdSet({...m,campaign_id:a,status:m.status||"ACTIVE"});return await (0,et.P)({adSetId:p.id,adSetData:m,campaignId:a,adAccountId:l.adAccountId,organizationId:o,userId:d,syncNewEntity:c}),null==u||u({id:p.id,name:m.name,campaign_id:a,status:"active",budget_amount:0}),p.id}async function es(e){var t,a;let{apiService:i,adDetailsData:n,adSetDetailsData:s}=e,r="use_existing_post"===n.adCreationType,l="carousel"===n.adFormat,o=(null==(t=n.media)?void 0:t.carouselItems)||[],d=n.selectedCreative||{},c=!!d.isVideo||"video"===n.media.type;if(!r&&!l&&!(null==(a=n.media)?void 0:a.file)&&!d.url&&!d.id)throw Error("An image or video is required. Please upload media or select a creative from the asset library.");let u=d.id,m=!!u&&/^\d+$/.test(u)&&!n.media.file&&!l;return{creativeResult:r?await Q({apiService:i,adDetailsData:n}):l?await G({apiService:i,adDetailsData:n,adSetDetailsData:s,carouselItems:o}):m?{creativeId:u,mainAssetFile:null,mainAssetSourceUrl:d.url,videoThumbnailFile:null,videoThumbnailUrl:d.previewUrl||d.url}:c?await I({apiService:i,adDetailsData:n,adSetDetailsData:s,selectedCreative:d}):await B({apiService:i,adDetailsData:n,adSetDetailsData:s,selectedCreative:d}),isCarousel:l,isVideo:c}}async function er(e){let{adResult:t,adDetailsData:a,adSetDetailsData:i,adSetId:n,campaignId:s,creativeResult:r,isCarousel:l,isVideo:o,apiConfig:d,connectedPages:c,syncNewEntity:u}=e;try{await q({verifiedAd:t,adDetailsData:a,adSetId:n,campaignId:s,creativeId:r.creativeId,apiConfig:d,connectedPages:c,resolvedPageId:a.selectedPageId||i.facebookPageId})}catch(e){if(console.warn("[useAdPublisher] Local ad save failed:",e),!u)throw Error("Ad 
1was created in Meta, but Adcero could not save it locally for the table. Please run a sync and try again.");if(!(await u("ad",t.id)).success)throw Error("Ad was created in Meta, but Adcero could not sync it into the Ads Manager table. Please run a sync and try again.")}if(!l)try{await H({creativeId:r.creativeId,adId:t.id,apiConfig:d,isVideo:o,mainAssetFile:r.mainAssetFile,mainAssetSourceUrl:r.mainAssetSourceUrl,videoThumbnailFile:r.videoThumbnailFile,videoThumbnailUrl:r.videoThumbnailUrl})}catch(e){}}function el(e,t,a,i){ea().then(n=>fetch("/api/ads-manager/behavior",{method:"POST",headers:n,body:JSON.stringify({event:e,entityId:t,context:a,organizationId:null!=i?i:null})})).catch(()=>{})}var eo=a(85642),ed=a(50095);let ec={CAMPAIGN:1,AD_SET:2,AD:3},eu={EXPANDED:"max-w-none sm:max-w-[1200px]"},em="ads-data-refresh";var ep=a(42431);function eg(e){let t=null==e?void 0:e.trim().toUpperCase();if(t)return(0,Y.tV)(t)}var eh=a(52099),ef=a(59558),ex=a(54679),eb=a(97003),ev=a(7235),ey=a(17787),eS=a(49027),ej=a(27587),eA=a(49476),eC=a(23327),ew=a(82180);function eN(e){let{section:t,onVisibilityChange:a}=e,{attributes:n,listeners:s,setNodeRef:r,transform:l,transition:o}=(0,eS.gl)({id:t.id}),d={transform:ej.Ks.Transform.toString(l),transition:o};return(0,i.jsxs)("div",{ref:r,style:d,className:"flex items-center justify-between p-4 bg-white dark:bg-card border rounded-lg hover:border-primary/50 transition-colors",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)("div",{...n,...s,children:(0,i.jsx)(eA.A,{className:"h-4 w-4 text-muted-foreground cursor-grab"})}),(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)("span",{children:t.title}),t.isRequired&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:"(required)"}),t.description&&(0,i.jsx)(ew.Bc,{children:(0,i.jsxs)(ew.m_,{children:[(0,i.jsx)(ew.k$,{children:(0,i.jsx)(eC.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,i.jsx)(ew.ZI,{children:(0,i.jsx)("p",{children:t.description})})]})})]}),t.description&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:t.description})]})]}),(0,i.jsx)(ev.d,{checked:t.isVisible,onCheckedChange:e=>a(t.id,e),disabled:t.isRequired})]})}function e_(e){let{isOpen:t,onOpenChange:a,sections:s,onSectionsChange:r,pageTitle:l,onSave:o}=e,[d,c]=n.useState(s),[u,m]=n.useState(!1);n.useEffect(()=>{c(s),m(!1)},[s]);let p=(0,ey.FR)((0,ey.MS)(ey.AN,{activationConstraint:{distance:8}}),(0,ey.MS)(ey.uN,{coordinateGetter:eS.JR})),g=e=>{c(d.map(t=>t.id===e?{...t,isVisible:!t.isVisible}:t)),m(!0)},h=()=>{c(s),m(!1),a(!1)},f=d.filter(e=>!1!==e.isAvailable);return(0,i.jsx)(ex.lG,{open:t,onOpenChange:h,children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-[425px]",children:[(0,i.jsxs)(ex.c7,{children:[(0,i.jsxs)(ex.L3,{children:["Page Settings - ",l]}),(0,i.jsx)(ex.rr,{children:"Toggle sections to show or hide them on the page. Drag to reorder."})]}),(0,i.jsx)("div",{className:"max-h-[60vh] overflow-y-auto pr-6 -mr-6",children:(0,i.jsx)(ey.Mp,{sensors:p,collisionDetection:ey.fp,onDragEnd:e=>{let{active:t,over:a}=e;if(a&&t.id!==a.id){let e=d.findIndex(e=>e.id===t.id),i=d.findIndex(e=>e.id===a.id);c((0,eS.be)(d,e,i)),m(!0)}},children:(0,i.jsx)(eS.gB,{items:f.map(e=>e.id),strategy:eS._G,children:(0,i.jsx)("div",{className:"space-y-4",children:f.map(e=>(0,i.jsx)(eN,{section:e,onVisibilityChange:g},e.id))})})})}),(0,i.jsxs)(ex.Es,{className:"flex justify-between gap-2",children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:h,className:"cursor-pointer",children:"Cancel"}),(0,i.jsx)(eb.$,{onClick:()=>{if(d.some(e=>e.isRequired&&!e.isVisible))return void console.error("Required sections cannot be hidden");r(d),m(!1),a(!1),null==o||o()},className:"cursor-pointer",disabled:!u,children:"Save"})]})]})})}var ek=a(99506),eE=a(52056),eI=a(89559),eT=a(90368),eD=a(35299),eP=a(27937),eO=a(26989);function eL(e){let{onClick:t,className:a}=e;return(0,i.jsx)(ew.Bc,{children:(0,i.jsxs)(ew.m_,{children:[(0,i.jsx)(ew.k$,{asChild:!0,children:(0,i.jsx)(eb.$,{variant:"ghost",size:"icon",className:"hover:bg-accent cursor-pointer ".concat(a),onClick:t,children:(0,i.jsx)(eO.A,{className:"h-4 w-4"})})}),(0,i.jsx)(ew.ZI,{children:(0,i.jsx)("p",{children:"Customize page sections"})})]})})}let eM=e=>{let{currentStep:t,canGoToPreviousStep:a,canGoToNextStep:n,canPublishCampaign:s,canPublishAdSet:r,isLoading:l,isPublishingAdSet:o,isEditingExisting:d,isEditingExistingAdSet:c,onPrevious:u,onNext:m,onPublishCampaign:p,onPublishAdSet:g,onPageSettingsClick:h}=e,f=3===t;return(0,i.jsxs)("div",{className:"flex flex-shrink-0 flex-col border-t bg-background sm:flex-row sm:items-center",children:[(0,i.jsx)("div",{className:"px-4 pt-3 sm:px-0 sm:pt-0",children:(0,i.jsx)(eL,{onClick:h})}),(0,i.jsxs)(ex.Es,{className:"flex w-full flex-1 flex-col gap-2 p-4 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsx)("div",{children:a&&(0,i.jsxs)(eb.$,{variant:"outline",onClick:u,className:"cursor-pointer",children:[(0,i.jsx)(eT.A,{className:"h-4 w-4"}),"Previous"]})}),(0,i.jsxs)("div",{className:"flex w-full flex-wrap items-center justify-end gap-2 sm:w-auto 
1sm:flex-nowrap",children:[(0,i.jsx)(ex.HM,{asChild:!0,children:(0,i.jsx)(eb.$,{variant:"ghost",className:"cursor-pointer",children:"Cancel"})}),t===ec.CAMPAIGN&&(0,i.jsx)(eb.$,{onClick:p,disabled:!s,variant:"outline",className:"cursor-pointer border-green-500 hover:bg-green-600/10 border text-green-500 hover:text-green-600",children:l?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eD.A,{className:"h-4 w-4 animate-spin mr-2"}),d?"Updating...":"Publishing..."]}):d?"Update Campaign":"Publish Campaign"}),t===ec.AD_SET&&g&&(0,i.jsx)(eb.$,{onClick:g,disabled:!r,variant:"outline",className:"cursor-pointer border-green-500 hover:bg-green-600/10 border text-green-500 hover:text-green-600",children:o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eD.A,{className:"h-4 w-4 animate-spin mr-2"}),c?"Updating...":"Publishing..."]}):c?"Update Ad Set":"Publish Ad Set"}),(0,i.jsxs)(eb.$,{onClick:m,variant:f?"gradient1":"default",className:f?"":"bg-gradient-to-r from-brand-primary/80 to-brand-secondary/80 text-white backdrop-blur-md border border-white/20 shadow-[0_8px_32px_0_rgba(31,38,135,0.2)] hover:from-brand-primary hover:to-brand-secondary transition-all",disabled:!n,children:[f?"Publish Ad":"Continue",!f&&(0,i.jsx)(eP.A,{className:"h-4 w-4"})]})]})]})]})};var eF=a(7220),eU=a(15870),eR=a(24033),eB=a(46046),eV=a(23818),eG=a(8599);let ez=["objective","buyingType"],eq=["facebookPageId","performanceGoal","trafficConversionLocation"],eH=["name"],eW=["adSetName"],eY=["adName","selectedCreative","media","primaryText","primaryTextOptions","headline","headlineOptions","description","callToAction"],e$=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i={};return Object.entries(e||{}).forEach(e=>{let[n,s]=e;if(!a.includes(n)&&(t.includes(n)||null!=s&&""!==s&&!(Array.isArray(s)&&0===s.length)&&("object"!=typeof s||0!==Object.keys(s).length||s.constructor!==Object)))if("object"==typeof s&&!Array.isArray(s)&&s&&s.constructor===Object){let e=e$(s,[],a);Object.keys(e).length>0&&(i[n]=e)}else i[n]=s}),i};class eJ{static async loadSettings(e,t,i,n){console.log("=== LOADING FIELD SETTINGS ==="),console.log("Full config data:",e);let{getInitialAdSetDetailsData:s,initialAdDetailsData:r}=await Promise.resolve().then(a.bind(a,6740)),{OBJECTIVES_DATA:l}=await Promise.resolve().then(a.bind(a,58050)),o={name:"",buyingType:"AUCTION",objective:l[0].id||"AWARENESS",specialAdCategories:[],hasSpendingLimit:!1,spendingLimitAmount:0,isAdvantageBudgetEnabled:!1,isAbTestEnabled:!1,bidStrategy:"LOWEST_COST",abTestData:null},d=s(),c=eG.d4.getState();await this.loadCampaignData(e.campaign,c,o,t),await this.loadAdSetData(e.adSet,c,d,i),await this.loadAdData(e.ad||e.adDetails,c,r,n),this.clearExcludedFields(c),this.logFinalState()}static loadCampaignData(e,t,a,i){if(console.log("Resetting campaign to defaults, then applying saved values"),t.updateCampaignBatch(a),t.updateCampaign("name",""),console.log("Campaign name cleared to empty string"),e&&Object.keys(e).length>0){if(console.log("Loading campaign data:",e),console.log("Campaign fields to load:",Object.keys(e)),Ob
1ject.entries(e).forEach(e=>{let[a,i]=e;"name"!==a&&null!=i&&t.updateCampaign(a,i)}),i){let{name:t,...n}=e;i({...a,...n})}}else i&&i(a)}static loadAdSetData(e,t,a,i){if(console.log("Resetting ad set to defaults, then applying saved values"),t.updateAdSetBatch(a),t.updateAdSet("adSetName",""),e&&Object.keys(e).length>0){if(console.log("Loading adSet data:",e),console.log("AdSet fields to load:",Object.keys(e)),Object.entries(e).forEach(e=>{let[a,i]=e;"adSetName"!==a&&null!=i&&("facebookPageId"===a?setTimeout(()=>t.updateAdSet(a,i),0):t.updateAdSet(a,i))}),i){let{adSetName:t,...n}=e;i({...a,...n})}}else i&&i(a)}static loadAdData(e,t,a,i){if(console.log("Resetting ad to defaults, then applying saved values"),t.updateAdBatch(a),t.updateAd("adName",""),e&&Object.keys(e).length>0){if(console.log("Loading ad data:",e),console.log("Ad fields to load:",Object.keys(e)),Object.entries(e).forEach(e=>{let[a,i]=e;eY.includes(a)||null==i||t.updateAd(a,i)}),i){let t=Object.entries(e).reduce((e,t)=>{let[a,i]=t;return eY.includes(a)||(e[a]=i),e},{});i({...a,...t})}}else i&&i(a)}static clearExcludedFields(e){e.updateCampaign("name",""),e.updateAdSet("adSetName",""),e.updateAd("adName",""),e.updateAd("selectedCreative",void 0),e.updateAd("media",{}),e.updateAd("primaryText",""),e.updateAd("headline",""),e.updateAd("description",""),e.updateAd("callToAction",""),console.log("Final clearing: names and creative/text fields reset to defaults")}static logFinalState(){let e=eG.d4.getState();console.log("State AFTER loading:",{campaignObjective:e.campaign.objective,campaignName:e.campaign.name,adSetName:e.adSet.adSetName,adName:e.ad.adName,facebookPageId:e.adSet.facebookPageId,selectedCreative:e.ad.selectedCreative,media:e.ad.media,primaryText:e.ad.primaryText,headline:e.ad.headline,description:e.ad.description,callToAction:e.ad.callToAction}),setTimeout(()=>{let e=eG.d4.getState();console.log("State after 100ms delay:",{campaignObjective:e.campaign.objective,campaignName:e.campaign.name})},100)}}var eK=a(71360);function eZ(e){let{id:t,name:a,isSelected:n,canUpdate:s,onLoad:r,onUpdate:l,onDelete:o}=e;return(0,i.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 hover:bg-accent rounded-sm group",children:[(0,i.jsxs)("button",{className:"flex-1 text-left text-sm py-1",onClick:e=>{e.preventDefault(),e.stopPropagation(),r(a)},children:[a,n&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground ml-1",children:"(active)"})]}),(0,i.jsxs)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,i.jsx)(eb.$,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:e=>{e.stopPropagation(),l(a)},disabled:!s,title:s?"Update this field setting with current values":"Load this setting first to update it",children:(0,i.jsx)(eB.A,{className:"h-3 w-3"})}),(0,i.jsx)(eb.$,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:e=>{e.stopPropagation(),o(t,a)},title:"Delete this field setting",children:(0,i.jsx)(eK.A,{className:"h-3 w-3"})})]})]})}var eX=a(33789),eQ=a(90235);function e0(e){let{open:t,onOpenChange:a,settingName:n,onSettingNameChange:s,onSave:r,isLoading:l}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(ex.Cf,{children:[(0,i.jsxs)(ex.c7,{children:[(0,i.jsx)(ex.L3,{children:"Save Field Settings"}),(0,i.jsx)(ex.rr,{children:"Save the current form configuration to quickly load it later."})]}),(0,i.jsx)("div",{className:"grid gap-4 py-4",children:(0,i.jsxs)("div",{className:"grid gap-2",children:[(0,i.jsx)(eQ.J,{htmlFor:"name",children:"Name"}),(0,i.jsx)(eX.p,{id:"name",placeholder:"Enter a name for these settings",value:n,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&n.trim()&&r()},autoFocus:!0})]})}),(0,i.jsxs)(ex.Es,{children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>{a(!1),s("")},children:"Cancel"}),(0,i.jsx)(eb.$,{onClick:r,disabled:l||!n.trim(),children:"Save Settings"})]})]})})}function e1(e){let t,{currentCampaignData:a,currentAdSetDetailsData:i,currentAdDetailsData:n,storeState:s=eG.d4.getState()}=e;return{campaign:e$((t={campaign:null!=a?a:s.campaign,adSet:null!=i?i:s.adSet,ad:null!=n?n:s.ad}).campaign,ez,eH),adSet:e$(t.adSet,eq,eW),ad:e$(t.ad,[],eY)}}function e2(e){let{user:t,setCampaignData:a,setAdSetDetailsData:s,setAdDetail
1sData:r,currentCampaignData:l,currentAdSetDetailsData:o,currentAdDetailsData:d}=e,{toast:c}=(0,$.dj)(),[u,m]=(0,n.useState)(!1),[p,g]=(0,n.useState)(""),[h,f]=(0,n.useState)(null),{fieldSettings:x,isLoading:b,loadFieldSettings:v,saveFieldSettings:y,deleteFieldSettings:S}=function(e){let{settings:t,isLoading:a,error:i,loadSettings:n,saveSettings:s,deleteSettings:r}=(0,eV.H)({userId:e,settingType:"campaign_field_settings",label:"field settings"});return{fieldSettings:t,isLoading:a,error:i,loadFieldSettings:n,saveFieldSettings:s,deleteFieldSettings:r}}(null==t?void 0:t.id);(0,n.useEffect)(()=>{(null==t?void 0:t.id)&&v().catch(e=>{console.error("Failed to load field settings:",e)})},[null==t?void 0:t.id,v]);let j=async()=>{if(!p.trim())return void c({title:"Name required",description:"Please enter a name for your field settings",variant:"destructive"});let e=e1({currentCampaignData:l,currentAdSetDetailsData:o,currentAdDetailsData:d});if(!(Object.keys(e.campaign||{}).length||Object.keys(e.adSet||{}).length||Object.keys(e.ad||{}).length))return void c({title:"No settings to save",description:"Please configure some fields before saving",variant:"destructive"});try{await y(p.trim(),e),m(!1),g(""),f(p.trim()),c({title:"Settings saved",description:'Field settings "'.concat(p,'" saved successfully')})}catch(e){console.error("Failed to save field settings:",e),c({title:"Save failed",description:"Failed to save field settings. Please try again.",variant:"destructive"})}},A=async e=>{let t=null==x?void 0:x.find(t=>t.setting_key===e);if(t)try{await eJ.loadSettings(t.setting_value,a,s,r),f(e),c({title:"Settings loaded",description:'Field settings "'.concat(e,'" applied successfully')})}catch(e){console.error("Failed to load field settings:",e),c({title:"Load failed",description:"Failed to load field settings. Please try again.",variant:"destructive"})}},C=async e=>{let t=e1({currentCampaignData:l,currentAdSetDetailsData:o,currentAdDetailsData:d});try{await y(e,t),c({title:"Settings updated",description:'Field settings "'.concat(e,'" updated successfully')})}catch(e){console.error("Failed to update field settings:",e),c({title:"Update failed",description:"Failed to update field settings. Please try again.",variant:"destructive"})}},w=async(e,t)=>{try{await S(e),h===t&&f(null),c({title:"Settings deleted",description:'Field settings "'.concat(t,'" deleted successfully')})}catch(e){console.error("Failed to delete field settings:",e),c({title:"Delete failed",description:"Failed to delete field settings. Please try again.",variant:"destructive"})}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(eF.rI,{children:[(0,i.jsx)(eF.ty,{asChild:!0,children:(0,i.jsxs)(eb.$,{variant:"outline",size:"sm",className:"gap-2",children:[(0,i.jsx)(eU.A,{className:"h-4 w-4"}),"Field Settings",(0,i.jsx)(eR.A,{className:"h-4 w-4"})]})}),(0,i.jsxs)(eF.SQ,{className:"w-64",align:"end",children:[(0,i.jsx)(eF.lp,{children:"Field Settings"}),(0,i.jsx)(eF.mB,{}),(0,i.jsx)(eF.I,{children:(0,i.jsxs)(eF._2,{onClick:()=>m(!0),children:[(0,i.jsx)(eB.A,{className:"mr-2 h-4 w-4"}),"Save Current Settings"]})}),x&&x.length>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eF.mB,{}),(0,i.jsx)(eF.lp,{className:"text-xs text-muted-foreground",children:"Saved Settings"}),(0,i.jsx)("div",{className:"max-h-64 overflow-y-auto",children:x.map(e=>(0,i.jsx)(eZ,{id:e.id,name:e.setting_key,isSelected:h===e.setting_key,canUpdate:h===e.setting_key,onLoad:A,onUpdate:C,onDelete:w},e.id))})]})]})]}),(0,i.jsx)(e0,{open:u,onOpenChange:m,settingName:p,onSettingNameChange:g,onSave:j,isLoading:b})]})}let e4=e=>{let{currentStep:t,campaignName:a,selectedObjectiveDetails:n,adSetName:s,user:r,setCampaignData:l,setAdSetDetailsData:o,setAdDetailsData:d,currentCampaignData:c,currentAdSetDetailsData:u,currentAdDetailsData:m}=e;return(0,i.jsx)(ex.c7,{children:(0,i.jsxs)("div",{className:"flex items-center justify-between",children:[(0,i.jsx)(ex.L3,{className:"text-xl font-semibold",children:(()=>{let e=(null==n?void 0:n.label)||(null==n?void 0:n.name)||"Objective",r=(0,i.jsx)("span",{className:"objective-bubble",children:e});switch(t){case ec.CAMPAIGN:return"Create";case ec.AD_SET:return(0,i.jsxs)(i.Fragment,{children:["Create: ",a||"Campaign Name"," ",r]});case ec.AD:return(0,i.jsxs)(i.Fragment,{children:["Create: ",a||"Campaign Name"," ",r," >"," ",s||"Ad Set Name"]});default:return"Create"}})()}),r&&(0,i.jsx)(e2,{user:r,setCampaignData:l,setAdSetDetailsData:o,setAdDetail
1sData:d,currentCampaignData:c,currentAdSetDetailsData:u,currentAdDetailsData:m})]})})};var e5=a(44109),e3=a(795),e7=a(74054),e6=a(5917),e8=a(38392),e9=a(97450),te=a(36742),tt=a(25016),ta=a(6132);let ti=(0,a(71847).A)("monitor-smartphone",[["path",{d:"M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8",key:"10dyio"}],["path",{d:"M10 19v-3.96 3.15",key:"1irgej"}],["path",{d:"M7 19h5",key:"qswx4l"}],["rect",{width:"6",height:"10",x:"16",y:"12",rx:"2",key:"1egngj"}]]);var tn=a(69065),ts=a(40583),tr=a(78519),tl=a(15239);let to=(0,i.jsxs)("div",{className:"text-foreground",children:[(0,i.jsxs)("p",{className:"info-modal-body",children:['As part of our ongoing efforts to promote fairness on our advertising platform, we have introduced a new Special Ad Category "Financial products and services" for advertisers promoting financial products and services. Starting January 21, 2025, using this category is required for financial products and services campaigns for advertisers based in the United States or showing ads to audiences in the United States. Ads may be rejected if an appropriate category is not chosen.'," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/510724041294968",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"Learn more about the update here"}),".",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsxs)("p",{className:"info-modal-body",children:["To help prevent discrimination, our"," ",(0,i.jsx)("a",{href:"https://transparency.meta.com/en-gb/policies/ad-standards/unacceptable-content/discriminatory-practices/",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"Discriminatory Practices"})," ","advertising policy has special requirements for ads related to financial products and services.",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsxs)("p",{className:"info-modal-body",children:[(0,i.jsx)("strong",{className:"info-modal-section-title",children:"Note:"})," The Credit Special Ad Category has been replaced by the Financial Products and Services category. This video covers the credit components that are in scope for our requirements. Additionally, this category has expanded to include financial products and services, which you can"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/510724041294968",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"learn more about here"}),".",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsx)("p",{className:"info-modal-body",children:"When you run financial products and services ads, you may need to choose a Special Ad Category during the creation of your campaign. You'll need to do this if:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside info-modal-body",children:[(0,i.jsx)("li",{children:"You're an advertiser in the United States"}),(0,i.jsx)("li",{children:"Your audience is in the United States"}),(0,i.jsx)("li",{children:"You're running ads for credit opportunities in the US, Canada or certain parts of Europe or reaching audiences in these regions"})]}),(0,i.jsxs)("details",{className:"my-3 group",children:[(0,i.jsxs)("summary",{className:"list-none flex items-center cursor-pointer text-sm font-medium text-muted-foreground hover:text-foreground",children:[(0,i.jsx)(eP.A,{className:"h-4 w-4 mr-1 transition-transform duration-200 group-open:rotate-90"}),"Certain parts of Europe include:"]}),(0,i.jsxs)("ul",{className:"text-xs pl-5 mt-2 list-disc columns-2 sm:columns-3 gap-x-4 bg-muted/50 p-3 rounded-md border",children:[(0,i.jsx)("li",{children:"Andorra"}),(0,i.jsx)("li",{children:"Austria"}),(0,i.jsx)("li",{children:"Azores"}),(0,i.jsx)("li",{children:"Belgium"}),(0,i.jsx)("li",{children:"Bulgaria"}),(0,i.jsx)("li",{children:"Canary Islands"}),(0,i.jsx)("li",{children:"All Channel Islands (Guernsey)"}),(0,i.jsx)("li",{children:"All Channel Islands (Jersey)"}),(0,i.jsx)("li",{children:"Croatia"}),(0,i.jsx)("li",{children:"Cyprus"}),(0,i.jsx)("li",{children:"Czechia"}),(0,i.jsx)("li",{children:"Denmark"}),(0,i.jsx)("li",{children:"Estonia"}),(0,i.jsx)("li",{children:"Finland"}),(0,i.jsx)("li",{children:"France"}),(0,i.jsx)("li",{children:"French Guiana"}),(0,i.jsx)("li",{children:"Germany"}),(0,i.jsx)("li",{children:"Greece"}),(0,i.jsx)("li",{children:"Guadeloupe"}),(0,i.jsx)("li",{children:"Hungary"}),(0,i.jsx)("li",{children:"Iceland"}),(0,i.jsx)("li",{children:"Ireland"}),(0,i.jsx)("li",{children:"Isle of Man"}),(0,i.jsx)("li",{children:"Italy"}),(0,i.jsx)("li",{children:"Latvia"}),(0,i.jsx)("li",{children:"Liechtenstein"}),(0,i.jsx)("li",{children:"Lithuania"}),(0,i.jsx)("li",{children:"Luxembourg"}),(0,i.jsx)("li",{children:"Madeira"}),(0,i.jsx)("li",{children:"Malta"}),(0,i.jsx)("li",{children:"Martinique"}),(0,i.jsx)("li",{children:"Mayotte"}),(0,i.jsx)("li",{children:"Monaco"}),(0,i.jsx)("li",{children:"Netherlands"}),(0,i.jsx)("li",{children:"Norway"}),(0,i.jsx)("li",{children:"Poland"}),(0,i.jsx)("li",{children:"Portugal"}),(0,i.jsx)("li",{children:"R\xe9union"}),(0,i.jsx)("li",{children:"Saint-Martin"}),(0,i.jsx)("li",{children:"San Marino"}),(0,i.jsx)("li",{children:"Slovakia"}),(0,i.jsx)("li",{children:"Slovenia"}),(0,i.jsx)("li",{children:"Spain"}),(0,i.jsx)("li",{children:"Sweden"}),(0,i.jsx)("li",{children:"Switzerland"}),(0,i.jsx)("li",{children:"United Kingdom"}),(0,i.jsx)("li",{children:"UK sovereign bases in Cyprus (Akrotiri and Dhekeli)"}),(0,i.jsx)("li",{children:"Vatican City"})]})]}),(0,i.jsx)("p",{className:"info-modal-body",children:"If you meet the qualifications above and don't choose a Special Ad Category, your ad may be rejected."}),(0,i.jsx)("h5",{className:"info-modal-section-title mt-4 mb-2",children:"Ads for financial products and services"}),(0,i.jsxs)("p",{className:"info-modal-body",children:["Starting January 21, 2025, use of the financial products and services Special Ad Category is required for advertisers based in the United States or showing financial products and services campaigns to audie
1nces in the United States. Ads may be rejected if the advertiser does not choose an appropriate Special Ad Category. Our policy for credit ads (a subset of financial products and services) does not change, and will continue to apply to advertisers based in the US or showing ads to audiences in the US, Canada or certain parts of Europe.",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsx)("p",{className:"info-modal-body",children:"If you're unsure whether your ad is covered under Meta's Discriminatory Practices policy for housing, employment or financial products and services ads, you can review examples of covered ads below."}),(0,i.jsx)("strong",{className:"block info-modal-section-title mt-3 mb-1",children:"Ads that promote or directly link to a financial product or service offer, including credit"}),(0,i.jsx)("p",{className:"info-modal-body",children:"Here are some examples of ads for credit, a subset of financial products and services, under our policies:"}),(0,i.jsx)(tl.default,{src:"/images/mod-electrica.jpeg",alt:"Example ad for Mod Electrica cars",width:320,height:200,className:"max-w-xs mx-auto my-3 border rounded-md info-modal-body"}),(0,i.jsx)(tl.default,{src:"/images/bankcard-loan.png",alt:"Example ad for BankCard loan",width:320,height:200,className:"max-w-xs mx-auto my-3 border rounded-md info-modal-body"}),(0,i.jsx)("span",{className:"block info-modal-section-title mt-3 mb-1",children:"They can include offers for the following and more in the US, Canada or certain parts of Europe:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside info-modal-body",children:[(0,i.jsx)("li",{children:"Credit cards"}),(0,i.jsx)("li",{children:"Brand ads for credit cards, regardless of offer"}),(0,i.jsx)("li",{children:"Loans, including auto, mortgage, personal or business loans"}),(0,i.jsx)("li",{children:"Long-term financing"}),(0,i.jsx)("li",{children:"Debt recovery"}),(0,i.jsx)("li",{children:"Debt consolidation and relief"})]}),(0,i.jsx)("span",{className:"block info-modal-section-title mt-3 mb-1",children:"Additionally, in the US, they can also include other financial products and services like the following and more:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside info-modal-body",children:[(0,i.jsx)("li",{children:"Banking services including checking and savings accounts"}),(0,i.jsx)("li",{children:"Brand ads for financial products and services, regardless of offer"}),(0,i.jsx)("li",{children:"Prepaid cards"}),(0,i.jsx)("li",{children:"Investment services"}),(0,i.jsx)("li",{children:"Pension or retirement funds"}),(0,i.jsx)("li",{children:"Insurance products"}),(0,i.jsx)("li",{children:"Consumer payment services"}),(0,i.jsx)("li",{children:"0% APR installment payments, including buy now, pay later (BNPL) and in-house installment payments"})]}),(0,i.jsx)("span",{className:"block info-modal-section-title mt-3 mb-1",children:"They don't include offers for the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside info-modal-body",children:[(0,i.jsx)("li",{children:"Gift cards"}),(0,i.jsx)("li",{children:"Store rewards"}),(0,i.jsx)("li",{children:"Business-to-Business (B2B) only financial products and services"}),(0,i.jsx)("li",{children:"Tax and accounting services"})]}),(0,i.jsx)("h5",{className:"info-modal-section-title mt-4 mb-2",children:"Audience restrictions"}),(0,i.jsxs)("p",{className:"info-modal-body",children:["When you choose a Special Ad Category, we apply additional audience restrictions to your campaign. These restrictions are a preventative measure to protect people from discriminatory practices. Your audience options don't become limited to only people interested in financial products and services opportunities. Learn more about"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/2220749868045706",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"targeting restrictions for financial products and services ads"}),".",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsxs)("p",{className:"info-modal-body",children:["If you determine that your ad is for financial products and services, learn how to"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/298000447747885",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"choose a Special Ad Category in Ads Manager"}),". Remember that choosing a Special Ad Category doesn't impact how long it takes for us to review your ads.",(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsxs)("p",{className:"info-modal-body",children:["Learn more about how to"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/1210227555661027",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"troubleshoot a rejected ad"}),". If you believe your ad was rejected incorrectly, you can request a review in"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business-support-home/",target:"_blank",rel:"noopener noreferrer",className:"link-primary info-modal-body",children:"Business Support Home"}),"."]})]}),td=e=>{let{goToNext:t,categoryTitle:a,currentSelection:s,onSelectionChange:r}
1=e,[l,o]=(0,n.useState)(!1),d=e=>{r(a,e)},c=[{id:"landingPage",label:"Ad landing page",icon:ti},{id:"images",label:"Ad images and videos",icon:tn.A},{id:"headlines",label:"Ad headlines and text",icon:ts.A}];return(0,i.jsxs)("div",{className:"flex flex-col space-y-6",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-lg font-semibold section-title mb-2 text-center",children:"Is any part of your ads about financial products and services?"}),(0,i.jsx)("p",{className:"text-xs text-amber-600 text-center font-medium",children:"Please select an option to continue"}),(0,i.jsx)("div",{className:"flex justify-center space-x-4 sm:space-x-6 my-4 border-b pb-3",children:c.map(e=>(0,i.jsxs)("div",{className:"flex items-center px-1 py-1.5 text-sm font-medium text-muted-foreground",children:[(0,i.jsx)(e.icon,{className:"mr-1.5 h-5 w-5 flex-shrink-0"}),e.label]},e.id))}),(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-6 mt-6",children:[(0,i.jsxs)("label",{htmlFor:"financial-yes",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!0===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"financial-yes",type:"radio",name:"financial-promote",checked:!0===s,onChange:()=>d(!0),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"Yes, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Credit cards"}),(0,i.jsx)("li",{children:"Long-term financing"}),(0,i.jsx)("li",{children:"Checking and savings accounts"}),(0,i.jsx)("li",{children:"Investment services"}),(0,i.jsx)("li",{children:"Payment services"}),(0,i.jsx)("li",{children:"Insurance services"}),(0,i.jsx)("li",{children:"Other related financial opportunities"})]})]})]}),(0,i.jsxs)("label",{htmlFor:"financial-no",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!1===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"financial-no",type:"radio",name:"financial-promote",checked:!1===s,onChange:()=>d(!1),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"No, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Unrelated activities"}),(0,i.jsx)("li",{children:"Gift cards"}),(0,i.jsx)("li",{children:"Financial management education"}),(0,i.jsx)("li",{children:"Tax and accounting services"}),(0,i.jsx)("li",{children:"Store rewards"})]})]})]})]}),(0,i.jsxs)("p",{className:"text-xs text-muted-foreground mt-6 flex items-center",children:[(0,i.jsx)(tr.A,{className:"mr-1.5 h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,i.jsx)("span",{className:"font-semibold",children:"Credit"})," is now part of financial products and services."]}),(0,i.jsxs)("p",{className:"text-xs text-muted-foreground mt-2",children:["For additional information, read"," ",(0,i.jsx)(eb.$,{variant:"link",className:"p-0 h-auto text-sm text-[oklch(0.58_0.19_258.5)] hover:underline cursor-pointer",onClick:()=>o(!0),children:"About ads for financial products and services"}),"."]})]}),(0,i.jsx)(e3.W,{isOpen:l,onOpenChange:o,title:"About ads for financial products and services",children:to})]})},tc=e=>{let{goToNext:t,goToPrev:a,categoryTitle:n,currentSelection:s,onSelectionChange:r}=e,l=e=>{r(n,e)},o=[{id:"landingPage",label:"Ad landing page",icon:ti},{id:"images",label:"Ad images and videos",icon:tn.A},{id:"headlines",label:"Ad headlines and text",icon:ts.A}];return(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-lg font-semibold section-title mb-2 text-center",children:"Are your ads about employment?"}),(0,i.jsx)("p",{className:"text-xs text-amber-600 text-center font-medium",children:"Please select an option to continue"}),(0,i.jsx)("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"See if any part of your ads promote a product or service related to employment."}),(0,i.jsx)("div",{className:"flex justify-center space-x-4 sm:sp
1ace-x-6 my-4 border-b pb-3",children:o.map(e=>(0,i.jsxs)("div",{className:"flex items-center px-1 py-1.5 text-sm font-medium text-muted-foreground",children:[(0,i.jsx)(e.icon,{className:"mr-1.5 h-5 w-5 flex-shrink-0"}),e.label]},e.id))}),(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-6 mt-6",children:[(0,i.jsxs)("label",{htmlFor:"employment-yes",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!0===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"employment-yes",type:"radio",name:"employment-promote",checked:!0===s,onChange:()=>l(!0),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"Yes, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Full-time or part-time jobs"}),(0,i.jsx)("li",{children:"Freelance"}),(0,i.jsx)("li",{children:"Internships"}),(0,i.jsx)("li",{children:"Franchising opportunities"}),(0,i.jsx)("li",{children:"Apprenticeships"}),(0,i.jsx)("li",{children:"Professional certification programs"}),(0,i.jsx)("li",{children:"Job fairs"}),(0,i.jsx)("li",{children:"Job board or aggregation services"}),(0,i.jsx)("li",{children:"Guaranteed interviews or career placement"}),(0,i.jsx)("li",{children:"Promotion of company perks alongside employment opportunities"})]})]})]}),(0,i.jsxs)("label",{htmlFor:"employment-no",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!1===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"employment-no",type:"radio",name:"employment-promote",checked:!1===s,onChange:()=>l(!1),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"No, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Unrelated activities"}),(0,i.jsx)("li",{children:"General advice on how to succeed at work unrelated to specific listings"}),(0,i.jsx)("li",{children:"General advice for career development unrelated to specific listings"}),(0,i.jsx)("li",{children:"Discussing a company without sharing employment opportunities or perks"})]})]})]})]})]})},tu=e=>{let{goToNext:t,goToPrev:a,categoryTitle:n,currentSelection:s,onSelectionChange:r}=e,l=e=>{r(n,e)},o=[{id:"landingPage",label:"Ad landing page",icon:ti},{id:"images",label:"Ad images and videos",icon:tn.A},{id:"headlines",label:"Ad headlines and text",icon:ts.A}];return(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-lg font-semibold section-title mb-2 text-center",children:"Are your ads about housing?"}),(0,i.jsx)("p",{className:"text-xs text-amber-600 text-center font-medium",children:"Please select an option to continue"}),(0,i.jsx)("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"See if any part of your ads promote a product or service related to housing."}),(0,i.jsx)("div",{className:"flex justify-center space-x-4 sm:space-x-6 my-4 border-b pb-3",children:o.map(e=>(0,i.jsxs)("div",{className:"flex items-center px-1 py-1.5 text-sm font-medium text-muted-foreground",children:[(0,i.jsx)(e.icon,{className:"mr-1.5 h-5 w-5 flex-shrink-0"}),e.label]},e.id))}),(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-6 mt-6",children:[(0,i.jsxs)("label",{htmlFor:"housing-yes",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!0===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"housing-yes",type:"radio",name:"housing-promote",checked:!0===s,onChange:()=>l(!0),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"Yes, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Sale, rental, or temporary housing listings"}),(0,i.jsx)("li",{children:"Homeowners insurance offers (including insurance bundles)"}),(0,i.jsx)("li",{children:"Renters insurance offers (including insurance bundles)"}),(0,i.jsx)("li",{children:"Mortgage insurance offers (including insurance bundles)"}),(0,i.jsx)("li",{children:"Financing options offers (including mortgage loans)"}),(0,i.jsx)("li",{children:"Home equity or appraisal services"}),(0,i.jsx)("li",{children:"Real estate and house hunting services"}),(0,i.jsx)("li",{children:"Aggregator services"})]})]})]}),(0,i.jsxs)("label",{htmlFor:"housing-no",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!1===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground
1/50"),children:[(0,i.jsx)("input",{id:"housing-no",type:"radio",name:"housing-promote",checked:!1===s,onChange:()=>l(!1),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"No, my ads promote one of the following:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Unrelated activities"}),(0,i.jsx)("li",{children:"Hotels"}),(0,i.jsx)("li",{children:"Resorts"}),(0,i.jsx)("li",{children:"Retreats"}),(0,i.jsx)("li",{children:"Tips related to homeownership or home buying"}),(0,i.jsx)("li",{children:"Education for consumers or housing providers about their rights and responsibilities under fair housing laws"})]})]})]})]})]})},tm=e=>{let{goToNext:t,goToPrev:a,categoryTitle:n,currentSelection:s,onSelectionChange:r}=e,l=e=>{r(n,e)},o=[{id:"landingPage",label:"Ad landing page",icon:ti},{id:"images",label:"Ad images and videos",icon:tn.A},{id:"headlines",label:"Ad headlines and text",icon:ts.A}];return(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-lg font-semibold section-title mb-2 text-center",children:"Are your ads about social issues, elections or politics?"}),(0,i.jsx)("p",{className:"text-xs text-amber-600 text-center font-medium",children:"Please select an option to continue"}),(0,i.jsxs)("p",{className:"text-sm text-muted-foreground text-center mb-4",children:["See if any part of your ads offer details about social issues, elections, or political opportunities.",(0,i.jsx)("br",{}),"Check to see if your ads fall under social issues based on the"," ",(0,i.jsx)("a",{href:"https://www.facebook.com/business/help/214754279118974",target:"_blank",rel:"noopener noreferrer",className:"text-[oklch(0.58_0.19_258.5)] hover:underline cursor-pointer",children:"country where you are running your ads"}),"."]}),(0,i.jsx)("div",{className:"flex justify-center space-x-4 sm:space-x-6 my-4 border-b pb-3",children:o.map(e=>(0,i.jsxs)("div",{className:"flex items-center px-1 py-1.5 text-sm font-medium text-muted-foreground",children:[(0,i.jsx)(e.icon,{className:"mr-1.5 h-5 w-5 flex-shrink-0"}),e.label]},e.id))}),(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-6 mt-6",children:[(0,i.jsxs)("label",{htmlFor:"social-yes",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!0===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"social-yes",type:"radio",name:"social-promote",checked:!0===s,onChange:()=>l(!0),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"Yes, my ads are:"}),(0,i.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:[(0,i.jsx)("li",{children:"Made by, on behalf of, or about a candidate for public office, a political figure, a political party, a political action committee or advocates for the outcome of an election to public office"}),(0,i.jsx)("li",{children:'About any election, referendum, or ballot initiative, including "go out and vote" or election campaigns'}),(0,i.jsx)("li",{children:"Regulated as political advertising"}),(0,i.jsx)("li",{children:"Social issues"})]})]})]}),(0,i.jsxs)("label",{htmlFor:"social-no",className:(0,tt.cn)("border p-4 rounded-md cursor-pointer transition-colors duration-150 flex items-start space-x-3",!1===s?"border-primary ring-2 ring-primary ring-offset-2 ring-offset-background":"border-muted hover:border-muted-foreground/50"),children:[(0,i.jsx)("input",{id:"social-no",type:"radio",name:"social-promote",checked:!1===s,onChange:()=>l(!1),className:"mt-1 flex-shrink-0 accent-primary focus:ring-primary"}),(0,i.jsxs)("span",{className:"text-sm",children:[(0,i.jsx)("strong",{children:"No, my ads offer:"}),(0,i.jsx)("ul",{className:"list-disc list-inside text-xs text-muted-foreground mt-1 space-y-0.5",children:(0,i.jsx)("li",{children:"Unrelated activities"})})]})]})]})]})},tp=e=>{let{goToPrev:t,onDeclare:a,categorySelections:n}=e,s=Object.entries(n).filter(e=>
1{let[t,a]=e;return!0===a}).map(e=>{let[t]=e;return t});return["Financial products and services","Employment","Housing","Social issues, elections or politics"].filter(e=>!s.includes(e)),(0,i.jsxs)("div",{className:"text-center",children:[s.length>0?(0,i.jsxs)("div",{className:"my-8",children:[(0,i.jsx)("h3",{className:"text-lg font-semibold section-title mb-3",children:"Selected Categories:"}),(0,i.jsx)("div",{className:"flex flex-col items-center space-y-2 px-4",children:s.map(e=>(0,i.jsx)("span",{className:"px-4 py-2 text-sm font-normal bg-muted text-muted-foreground rounded-full shadow-sm whitespace-nowrap",children:e},e))})]}):(0,i.jsxs)("div",{className:"my-8 p-4 border border-amber-200 dark:border-amber-500/30 bg-amber-50 dark:bg-amber-950/30 rounded-lg",children:[(0,i.jsxs)("div",{className:"flex items-center text-amber-600 mb-2",children:[(0,i.jsx)(ta.A,{className:"h-5 w-5 mr-2"}),(0,i.jsx)("h3",{className:"font-semibold",children:"No Categories Selected"})]}),(0,i.jsx)("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:'You haven\'t selected "Yes" for any categories. Please go back and select at least one category that applies to your ads, or select "No" for all categories if none apply.'})]}),(0,i.jsx)("h2",{className:"text-lg font-semibold section-title mb-4",children:"Based on your responses:"}),(0,i.jsx)("div",{className:"text-sm text-muted-foreground mb-6 space-y-2",children:s.length>0?"You have indicated that your ads fall into the following Special Ad Categories: ".concat(s.join(", "),".").split("\n").map((e,t)=>(0,i.jsx)("p",{className:"mb-2",children:e},t)):(0,i.jsx)("p",{children:"You have not indicated that your ads fall into any Special Ad Categories."})}),(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:"After declaring your category, you can opt out or change your category at any time."})]})},tg=[{id:1,title:"Financial products and services"},{id:2,title:"Employment"},{id:3,title:"Housing"},{id:4,title:"Social issues, elections or politics"},{id:5,title:"Review"}],th=e=>{let{message:t}=e,a=n.useMemo(()=>"shake_".concat(Date.now(),"_").concat(Math.random().toString(36).slice(2)),[]);return n.useEffect(()=>{let e=document.createElement("style");return e.innerHTML="@keyframes ".concat(a," {0%{transform:translateX(0);}20%{transform:translateX(-10px);}40%{transform:translateX(10px);}60%{transform:translateX(-10px);}80%{transform:translateX(10px);}100%{transform:translateX(0);}}"),document.head.appendChild(e),()=>{document.head.removeChild(e)}},[a]),(0,i.jsxs)("div",{style:{animation:"".concat(a," 0.5s linear")},className:"mb-4 p-3 border-2 border-destructive bg-destructive/5 text-destructive rounded-lg flex items-start",children:[(0,i.jsx)(ta.A,{className:"h-5 w-5 mr-2 mt-0.5 flex-shrink-0"}),(0,i.jsx)("div",{className:"text-sm font-medium",children:t})]})};function tf(e){let{isOpen:t,onOpenChange:a,onDeclareCategories:s,initialCategorySelections:r={}}=e,[l,o]=(0,n.useState)(1),[d,c]=(0,n.useState)(r),[u,m]=(0,n.useState)(""),[p,g]=(0,n.useState)(0);(0,n.useEffect)(()=>{Object.keys(r).length>0&&c(e=>({...e,...r}))},[r]),(0,n.useEffect)(()=>{t&&o(1)},[t]);let h=e=>{m(e),g(e=>e+1)},f=()=>{var e;let t=null==(e=tg[l-1])?void 0:e.title;if(l<5&&void 0===d[t])return void h("Please select Yes or No for ".concat(t," before continuing."));m(""),o(e=>Math.min(e+1,tg.length))},x=()=>{m(""),o(e=>Math.max(e-1,1))},b=(e,t)=>{c(a=>({...a,[e]:t})),m("")},v=()=>{let e=Object.entries(d).filter(e=>
1{let[t,a]=e;return!0===a}).map(e=>{let[t]=e;return t});if(0===e.length)return void h("Please select at least one category to declare.");s(e),a(!1),m("")};return(0,i.jsx)(ex.lG,{open:t,onOpenChange:e=>{e||m(""),a(e)},children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-3xl md:max-w-4xl lg:max-w-5xl p-0 flex flex-col h-[calc(100vh-80px)] max-h-[700px] [&>button.absolute.right-4.top-4]:cursor-pointer",children:[(0,i.jsx)(ex.c7,{className:"p-6 border-b",children:(0,i.jsx)(ex.L3,{className:"text-lg font-semibold text-center",children:"Categorize your ads"})}),(0,i.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,i.jsx)("aside",{className:"w-1/4 border-r p-6 bg-muted/40 overflow-y-auto",children:(0,i.jsx)("nav",{className:"space-y-1",children:tg.map(e=>{let t=e.id<l,a=e.id===l,n=e.id>l;return(0,i.jsxs)("button",{onClick:()=>o(e.id),disabled:n,className:"w-full text-left px-3 py-2 rounded-md text-sm font-medium transition-colors flex items-center ".concat(a?"bg-primary text-primary-foreground":t?"text-foreground hover:bg-accent hover:text-accent-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"," ").concat(n?"opacity-50 cursor-not-allowed":"cursor-pointer"),children:[t?(0,i.jsx)(e6.A,{className:"h-4 w-4 mr-2 text-green-500 flex-shrink-0"}):(0,i.jsx)("span",{className:"inline-block h-4 w-4 mr-2 rounded-full border ".concat(a?"border-primary-foreground/50 bg-primary-foreground/20":"border-muted-foreground/50"," flex-shrink-0")}),e.title]},e.id)})})}),(0,i.jsxs)("main",{className:"flex-1 p-6 overflow-y-auto",children:[u&&(0,i.jsx)(th,{message:u},p),(()=>{let e={goToNext:f,goToPrev:x,onSelectionChange:b};switch(l){case 1:return(0,i.jsx)(td,{...e,categoryTitle:tg[0].title,currentSelection:d[tg[0].title]});case 2:return(0,i.jsx)(tc,{...e,categoryTitle:tg[1].title,currentSelection:d[tg[1].title]});case 3:return(0,i.jsx)(tu,{...e,categoryTitle:tg[2].title,currentSelection:d[tg[2].title]});case 4:return(0,i.jsx)(tm,{...e,categoryTitle:tg[3].title,currentSelection:d[tg[3].title]});case 5:return(0,i.jsx)(tp,{goToPrev:x,onDeclare:v,categorySelections:d});default:return null}})()]})]}),(0,i.jsxs)(ex.Es,{className:"p-6 border-t flex justify-between w-full",children:[l>1?(0,i.jsx)(eb.$,{variant:"outline",onClick:x,className:"mr-auto",children:5===l?"Back":"Previous"}):(0,i.jsx)("div",{}),l<tg.length?(0,i.jsx)(eb.$,{onClick:f,children:"Next"}):(0,i.jsx)(eb.$,{onClick:v,disabled:0===Object.entries(d).filter(e=>
1{let[t,a]=e;return!0===a}).length,children:"Declare category"})]})]})})}var tx=a(68625);function tb(e){var t;let{specialAdCategories:a,setSpecialAdCategories:s,onCompletionChange:r,isSectionCompleted:l=!1,sectionType:d="OPTIONAL",disabled:c}=e,[u,m]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!1),[h,f]=(0,n.useState)(!1),x=a.length>0,b="About Special Ad Categories\nSome types of ads — like those about jobs, housing, credit, politics, or social issues — have extra rules to make sure everyone gets treated fairly. Meta calls these \"Special Ad Categories.\"\nIf your ad is about one of these topics, you'll need to let us know so we can help you follow Meta's rules. These rules limit how you can target people — for example, you won't be able to target by age, gender, or ZIP code in some cases.\nDeclaring your category up front:\nHelps keep your ads compliant\nReduces the chances of your ad being rejected\nEnsures a fair experience for all users\nIf your ad doesn't fall into one of these categories, just skip this section.",v='Meta calls these "Special Ad Categories."',y="Declaring your category up front:",S=b.indexOf(v)+v.length,j=b.substring(0,S).trim(),A=b.substring(S).trim(),C=A.indexOf(y),w="",N=[],_="";if(-1!==C){w=A.substring(0,C).trim();let e=A.substring(C+y.length).trim().split("\n").map(e=>e.trim());N=e.filter(e=>["Helps keep your ads compliant","Reduces the chances of your ad being rejected","Ensures a fair experience for all users"].includes(e));let t=e.findIndex(e=>"If your ad doesn't fall into one of these categories, just skip this section."===e);-1!==t&&(_=e.slice(t).join("\n"))}else w=A;let k=c?(0,i.jsx)("span",{className:"text-xs text-muted-foreground bg-muted px-2 py-1 rounded",children:"Cannot be changed"}):null;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(tx.z,{title:"Special Ad Categories",isCompleted:x,sectionType:d,onCompletionChange:r,disabled:c,headerSlot:k,children:[(0,i.jsxs)("div",{className:"text-sm text-muted-foreground mb-4 space-y-1",children:[j.split("\n").map((e,t)=>e.trim()&&(0,i.jsx)("p",{children:e.trim()},"init-".concat(t))),p?(0,i.jsxs)("div",{className:"space-y-1 pt-1",children:[w.split("\n").map((e,t)=>e.trim()&&(0,i.jsx)("p",{children:e.trim()},"rem-".concat(t))),N.length>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{className:"pt-1",children:y}),(0,i.jsx)("ul",{className:"list-disc list-inside pl-4",children:N.map((e,t)=>(0,i.jsx)("li",{children:e},"item-".concat(t)))})]}),_.split("\n").map((e,t)=>e.trim()&&(0,i.jsx)("p",{className:"pt-1",children:e.trim()},"post-".concat(t))),(0,i.jsx)("button",{onClick:()=>g(!1),className:"link-primary text-sm font-medium pt-1",children:"Read less"})]}):(0,i.jsx)("button",{onClick:()=>g(!0),className:"link-primary text-sm font-medium pt-1",children:"Read more"})]}),(0,i.jsxs)("div",{className:"mb-4",children:[(0,i.jsx)("h4",{className:"font-medium text-sm mb-1",children:"Benefits of declaring Special Ad Categories"}),(0,i.jsx)("p",{className:"text-sm text-muted-foreground",children:"Accurately declaring your ad categories helps you run ads compliant with Meta's advertising standards and helps prevent potential ad rejections."})]}),(0,i.jsxs)("div",{className:"flex items-end space-x-4",children:[(0,i.jsxs)("div",{className:"flex-grow space-y-1.5",children:[(0,i.jsx)(eQ.J,{htmlFor:"special-category-select",className:"text-sm font-medium mb-1 block",children:"Categories"}),(0,i.jsx)("p",{className:"text-xs text-muted-foreground mb-2",children:"Select the categories that best describe what this campaign will advertise."}),(0,i.jsxs)(e9.AM,{open:u,onOpenChange:m,modal:!1,children:[(0,i.jsx)(e9.Wv,{asChild:!0,children:(0,i.jsxs)(eb.$,{variant:"outline",role:"combobox","aria-expanded":u,className:"w-full justify-between font-normal custom-dropdown-trigger",id:"special-category-select",children:[0===a.length?"Select categories...":1===a.length?null==(t=o.gE.find(e=>e.value===a[0]))?void 0:t.label:"".concat(a.length," categories selected"),(0,i.jsx)(e7.A,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),(0,i.jsx)(e9.hl,{className:"w-[--radix-popover-trigger-width] p-0 z-[9999]",align:"start",onClick:()=>{console.log("PopoverContent onClick triggered")},onInteractOutside:e=>{console.log("PopoverContent onInteractOutside triggered, default behavior should close Popover")},children:(0,i.jsx)(te.uB,{style:{pointerEvents:"auto"},children:(0,i.jsxs)(te.oI,{style:{pointerEvents:"auto"},children:[(0,i.jsx)(te.xL,{children:"No category found."}),(0,i.jsx)(te.L$,{children:o.gE.filter(e=>"NONE"!==e.value).map(e=>{let t=e.icon,n=a.includes(e.value);return(0,i.jsx)(te.h_,{value:e.label,disabled:!1,style:{pointerEvents:"auto"},onClick:()=>{console.log("CommandItem direct onClick triggered for:",e.label)},onSelect:()=>{console.log("CommandItem onSelect triggered for:",e.label,"Actual value:",e.value),s(t=>{let a=t.includes(e.value);console.log("Current selection state:",t);let i=a?t.filter(t=>t!==e.value):[...t,e.value];return console.log("New selection state:",i),i})},className:"custom-dropdown-item checkbox-hover-effect",children:(0,i.jsxs)("div",{className:"flex items-start space-x-3 w-full",children:[(0,i.jsx)(e6.A,{className:(0,tt.cn)("mt-1 h-4 w-4",n?"opacity-100":"opacity-0")}),t&&(0,i.jsx)("div",{className:"mt-1",children:(0,i.jsx)(t,{className:"h-5 w-5 text-muted-foreground"})}),(0,i.jsxs)("div",{className:t?"":"ml-5",children:[(0,i.jsx)("p",{className:"font-medium text-sm",children:e.label}),e.description&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:e.description})]})]})},e.value)})})]})})})]})]}),(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>f(!0),className:"cursor-pointer",children:"Help me categorize"})]}),a.includes("ISSUES_ELECTIONS_POLITICS")&&(0,i.jsxs)("div",{className:"mt-4 p-3 pr-4 border border-gray-300 dark:border-border rounded-md bg-background shadow-sm relative",children:[(0,i.jsx)("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-red-600 rounded-l-md"}),(0,i.jsxs)("div",{className:"ml-2 flex items-start",children:[(0,i.jsx)("div",{className:"flex-shrink-0 pt-0.5",children:(0,i.jsx)(e8.A,{className:"h-5 w-5 text-red-600","aria-hidden":"true"})}),(0,i.jsxs)("div",{className:"ml-3 flex-grow",children:[(0,i.jsx)("h3",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:"Authorization required"}),(0,i.jsxs)("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-300",children:["To run ads about social issues, elections or politics, you need to confirm your identity and create a disclaimer. Unfortunately, you can only do this in"," ",(0,i.jsx)("a",{href:"https://adsmanager.facebook.com/",target:"_blank",rel:"noopener noreferrer",className:"font-medium text-blue-600 dar
1k:text-blue-400 hover:underline",children:"Meta's ad manager"}),"."]})]})]})]})]}),(0,i.jsx)(tf,{isOpen:h,onOpenChange:f,onDeclareCategories:e=>{let t={"Financial products and services":"FINANCIAL_PRODUCTS_SERVICES",Employment:"EMPLOYMENT",Housing:"HOUSING","Social issues, elections or politics":"ISSUES_ELECTIONS_POLITICS"};s(e.map(e=>t[e]).filter(e=>void 0!==e)),f(!1)},initialCategorySelections:(()=>{let e={FINANCIAL_PRODUCTS_SERVICES:"Financial products and services",EMPLOYMENT:"Employment",HOUSING:"Housing",ISSUES_ELECTIONS_POLITICS:"Social issues, elections or politics"},t={};return a.forEach(a=>{let i=e[a];i&&(t[i]=!0)}),t})()})]})}var tv=a(34345),ty=a(42020),tS=a(88490);function tj(e){let{hasSpendingLimit:t,setHasSpendingLimit:a,onCompletionChange:s,onValidationChange:r,onSpendingLimitAmountChange:l,initialAmount:o=100,isSectionCompleted:d=!1,sectionType:c="OPTIONAL",currency:u="USD"}=e,m=(0,ty.Hz)(u),p=(0,tS.cf)(u),g=(null==p?void 0:p.symbol)||"$",h=Math.max(100*m.daily,100),[f,x]=(0,n.useState)(o>0?o.toFixed(2):h.toFixed(2)),b=!t||parseFloat(String(f))>=h,v=t&&parseFloat(String(f))>=h;(0,n.useEffect)(()=>{o>0?x(o.toFixed(2)):x(h.toFixed(2))},[o,h]),(0,n.useEffect)(()=>{t&&l&&l(parseFloat(String(f))||0)},[t,f,l]);let y=(0,i.jsx)(ev.d,{id:"spending-limit",checked:t,onCheckedChange:e=>{a(e),e||x(o>0?o.toFixed(2):h.toFixed(2))},className:"cursor-pointer"});return(0,i.jsx)(tx.z,{title:"Campaign Spending Limit",description:"Set a maximum budget for your campaign",isCompleted:v,sectionType:c,isValid:b,onCompletionChange:s,onValidationChange:r,headerSlot:y,className:b?"":"bg-red-50 border-red-200 dark:bg-red-950/20 dark:border-red-800",children:t&&(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsxs)(eQ.J,{htmlFor:"limit-amount",children:["Spending limit amount (minimum ",g,(0,ty.ej)(h,u),")"]}),(0,i.jsx)(tv.U,{id:"limit-amount",value:f,onChange:e=>{x(String(e))},currency:u,placeholder:(0,ty.ej)(h,u)}),parseFloat(String(f))<h&&(0,i.jsxs)("p",{className:"text-sm text-destructive",children:["Minimum spending limit is ",g,(0,ty.ej)(h,u)]})]})})}var tA=a(47507);function tC(e){let{isAdvantageBudgetEnabled:t,setIsAdvantageBudgetEnabled:a,campaignBidStrategy:s,setCampaignBidStrategy:r,onCompletionChange:l,isSectionCompleted:o=!1,sectionType:d="OPTIONAL",disabled:c=!1}=e,u="20.00",m=t&&""!==u.trim()&&parseFloat(u)>0;(0,n.useEffect)(()=>{t&&!["LOWEST_COST","COST_PER_RESULT_GOAL","BID_CAP"].includes(s)&&r("LOWEST_COST")},[t,s,r]);let p=(0,i.jsxs)(i.Fragment,{children:[c&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground bg-muted px-2 py-1 rounded",children:"Enable Campaign Spending Limit first"}),(0,i.jsx)(ev.d,{id:"advantage-budget",checked:t,onCheckedChange:e=>{a(e)},disabled:c,className:"cursor-pointer"})]});return(0,i.jsx)(tx.z,{title:"Advantage+ Campaign Budget (recommended)",isCompleted:m,sectionType:d,onCompletionChange:l,headerSlot:p,disabled:c,children:t&&(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsx)(eQ.J,{htmlFor:"bid-strategy",children:"Campaign bid strategy"}),(0,i.jsxs)(tA.l6,{value:s,onValueChange:e=>{r(e)},children:[(0,i.jsx)(tA.bq,{id:"bid-strategy",className:"custom-dropdown-trigger form-field-white-bg cursor-pointer",children:(0,i.jsx)(tA.yv,{placeholder:"Select a bid strategy"})}),(0,i.jsxs)(tA.gC,{className:"cursor-pointer",children:[(0,i.jsx)(tA.eb,{value:"LOWEST_COST",className:"custom-dropdown-item",children:"Lowest cost"}),(0,i.jsx)(tA.eb,{value:"COST_PER_RESULT_GOAL",className:"custom-dropdown-item",children:"Cost per result goal"}),(0,i.jsx)(tA.eb,{value:"BID_CAP",className:"custom-dropdown-item",children:"Bid cap"})]})]})]})})}var tw=a(86651);let tN=e=>{let{isOpen:t,onOpenChange:a,onCampaignSelect:r,accessToken:l,adAccountId:o}=e,{currentOrganization:d}
1=(0,s.Z5)(),[c,u]=(0,n.useState)([]),[m,p]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null),[f,x]=(0,n.useState)(""),[b,v]=(0,n.useState)(!1),y=(0,n.useDeferredValue)(f),S=(0,n.useCallback)(()=>{let e=new URLSearchParams({ad_account_id:o,access_token:l});return(null==d?void 0:d.id)&&e.set("organization_id",d.id),"/api/meta/campaigns?".concat(e.toString())},[o,l,null==d?void 0:d.id]),j=(0,n.useMemo)(()=>c.map(e=>({campaign:e,normalizedName:e.name.toLowerCase(),normalizedId:e.id.toLowerCase()})),[c]),A=(0,n.useMemo)(()=>(function(e,t){let a=t.trim().toLowerCase();return a?e.filter(e=>{let{normalizedName:t,normalizedId:i}=e;return t.includes(a)||i.includes(a)}).map(e=>{let{campaign:t}=e;return t}):e.map(e=>{let{campaign:t}=e;return t})})(j,y),[j,y]);(0,n.useEffect)(()=>{t&&l&&o&&(async()=>{p(!0),h(null);try{let e=await fetch(S());if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||"Failed to fetch campaigns (".concat(e.status,")"))}let t=await e.json();u(t.data||[])}catch(e){console.error("Failed to fetch campaigns:",e),h(e instanceof Error?e.message:"Failed to fetch campaigns")}finally{p(!1)}})()},[t,S]),(0,n.useEffect)(()=>{t||(x(""),h(null)),v(!1)},[t]);let C=e=>{if(b)return;v(!0);let t=c.find(t=>t.id===e.id),i=(null==t?void 0:t.spend_cap)||e.spend_cap,n={...e,spend_cap:i};a(!1),setTimeout(()=>{r(n),v(!1)},50)};return b?null:(0,i.jsx)(ex.lG,{open:t,onOpenChange:e=>{e||b||a(!1)},children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md",onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{children:"Choose Existing Campaign"})}),(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)(tw.A,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),(0,i.jsx)(eX.p,{placeholder:"Search campaigns by name or ID...",value:f,onChange:e=>x(e.target.value),className:"pl-9 form-field-white-bg",disabled:m})]}),(0,i.jsx)("div",{className:"min-h-[300px] max-h-[400px] overflow-y-auto",children:m?(0,i.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,i.jsx)(eD.A,{className:"h-6 w-6 animate-spin"}),(0,i.jsx)("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading campaigns..."})]}):g?(0,i.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[(0,i.jsx)("p",{className:"text-sm text-red-600 mb-2",children:g}),(0,i.jsx)(eb.$,{variant:"outline",size:"sm",onClick:async()=>{h(null),p(!0);try{let e=await fetch(S());if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||"Failed to fetch campaigns (".concat(e.status,")"))}let t=await e.json();u(t.data||[]),h(null)}catch(e){h(e instanceof Error?e.message:"Failed to fetch campaigns")}finally{p(!1)}},children:"Try Again"})]}):0===A.length?(0,i.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,i.jsx)("p",{className:"text-sm text-muted-foreground",children:f.trim()?'No campaigns found matching "'.concat(f,'"'):0===c.length?"No campaigns found in this ad account":"No campaigns match your search"})}):(0,i.jsx)("div",{className:"space-y-2",children:A.map(e=>(0,i.jsx)("div",{onClick:()=>C(e),className:(0,tt.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200","hover:bg-blue-50 hover:border-blue-200 hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"),tabIndex:0,role:"button",onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),C(e))},children:(0,i.jsxs)("div",{className:"flex flex-col",children:[(0,i.jsx)("h4",{className:"font-medium text-sm text-gray-900 dark:text-foreground line-clamp-2",children:e.name}),(0,i.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["ID: ",e.id]})]})},e.id))})})]})]})})},t_=e=>{let{campaignName:t,setCampaignName:a,buyingType:s,handleBuyingTypeChange:r,accessToken:l,adAccountId:o,selectedCampaign:d,onCampaignSelect:c,isEditingExisting:u,isSectionCompleted:m=!1,sectionType:p="REQUIRED",onCompletionChange:g,onValidationChange:h}=e,{toast:f}
1=(0,$.dj)(),[x,b]=(0,n.useState)(t),[v,y]=(0,n.useState)(!1),S=(0,n.useRef)(null);(0,n.useEffect)(()=>{b(t)},[t]);let j=x.trim().length>0;(0,n.useEffect)(()=>{null==g||g(j)},[j,g]);let A=(0,i.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,i.jsx)("div",{className:"flex items-center",children:(0,i.jsx)(eQ.J,{htmlFor:"buying-type-select",className:"text-sm font-medium mr-4",children:"Buying type"})})});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(tx.z,{title:"Campaign Name",isCompleted:j,sectionType:p,onCompletionChange:g,onValidationChange:h,headerSlot:A,children:(0,i.jsxs)("div",{className:"flex items-center gap-x-4",children:[(0,i.jsx)(eX.p,{id:"campaignNameInput",placeholder:"Enter campaign name",value:x,onChange:e=>{let t=e.target.value;b(t),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{a(t)},300)},className:"form-field-white-bg"}),(0,i.jsx)(eb.$,{variant:"outline",className:"shrink-0 whitespace-nowrap cursor-pointer",onClick:()=>{u?(b(""),a(""),c&&c(null)):l&&o?y(!0):f({title:"No ad account connected",description:"Connect a Meta, TikTok, or Google Ads account in Settings to create campaigns.",variant:"destructive"})},children:u?"Create New Campaign":"Choose Existing Campaign"}),(0,i.jsxs)(tA.l6,{value:s,onValueChange:r,name:"buying-type-select",disabled:u,children:[(0,i.jsx)(tA.bq,{id:"buying-type-select",className:(0,tt.cn)("custom-dropdown-trigger form-field-white-bg w-full max-w-[200px]",u&&"opacity-50 cursor-not-allowed"),children:(0,i.jsx)(tA.yv,{placeholder:"Select a buying type"})}),(0,i.jsxs)(tA.gC,{className:"dropdown-content-max-width",children:[(0,i.jsx)(tA.eb,{value:"AUCTION",className:"custom-dropdown-item cursor-pointer",children:"Auction"}),(0,i.jsx)(tA.eb,{value:"RESERVED",className:"custom-dropdown-item cursor-not-allowed opacity-50 text-muted-foreground",disabled:!0,children:"Reservation (Coming Soon)"})]})]})]})}),v&&(0,i.jsx)(tN,{isOpen:v,onOpenChange:y,onCampaignSelect:e=>{b(e.name),a(e.name),c&&c(e)},accessToken:l||"",adAccountId:o||""})]})};var tk=a(17982);let tE=e=>{let{campaignObjective:t,setCampaignObjective:a,displayedObjectives:s,selectedObjectiveDetails:r,setShowTrafficInfoModal:l,setShowAppPromotionInfoModal:o,isSectionCompleted:d=!0,sectionType:c="REQUIRED",disabled:u}=e,m=u?(0,i.jsx)("span",{className:"ml-2 text-xs text-muted-foreground bg-muted px-2 py-1 rounded",children:"Cannot be changed"}):null;return(0,i.jsx)(tx.z,{title:"Campaign Objective",isCompleted:d,sectionType:c,disabled:u,headerSlot:m,children:(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-10 pt-2",children:[(0,i.jsx)("div",{children:(0,i.jsx)(tk.z,{value:t,onValueChange:u?void 0:a,className:"space-y-1 mt-1.5",disabled:u,children:s.map(e=>{let a=e.icon,n=t===e.id;return(0,i.jsxs)(eQ.J,{htmlFor:e.id,className:(0,tt.cn)("flex items-center space-x-3 p-3 rounded-lg cursor-pointer border transition-colors",n?"border-primary bg-primary/5":"border-border hover:bg-muted/50",u&&"cursor-not-allowed"),children:[(0,i.jsx)("div",{className:(0,tt.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded-full border",n?"border-primary bg-primary":"border-muted-foreground/30"),children:n&&(0,i.jsx)("div",{className:"h-2 w-2 rounded-full bg-white dark:bg-card"})}),(0,i.jsx)(tk.C,{value:e.id,id:e.id,className:"sr-only"}),(0,i.jsx)("div",{className:(0,tt.cn)("p-2 rounded-md",n?"bg-primary text-primary-foreground":"bg-muted"),children:a&&(0,i.jsx)(a,{className:(0,tt.cn)("h-4 w-4",!n&&"text-foreground")})}),(0,i.jsx)("span",{className:(0,tt.cn)("font-medium",n?"text-primary":"text-foreground"),children:e.label})]},e.id)})})}),(0,i.jsx)("div",{className:"flex flex-col items-center justify-center text-center",children:r?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"w-28 h-28 bg-gray-300 rounded-full mb-6 flex items-center justify-center",children:r.icon&&n.createElement(r.icon,{className:"w-14 h-14 text-gray-500 dark:text-muted-foreground"})}),(0,i.jsx)("h3",{className:"text-xl font-semibold mb-2",children:r.label}),"TRAFFIC"===r.id?(0,i.jsxs)("p",{className:"text-sm text-muted-foreground mb-4 px-4",children:[r.description.split("Learn more")[0],(0,i.jsx)("button",{onClick:()=>l(!0),className:"link-primary ml-1 cursor-pointer",children:"Learn more"}),r.description.split("Learn more")[1]||""]}):"APP_PROMOTION"===r.id?(0,i.jsxs)("p",{className:"text-sm text-muted-foreground mb-4 px-4",children:[r.description,(0,i.jsx)("button",{onClick:()=>o(!0),className:"link-primary ml-1 cursor-pointer",children:"Learn more"})]}):(0,i.jsx)("p",{className:"text-sm text-muted-foreground mb-4 px-4",children:r.description}),(0,i.jsxs)("div",{className:"space-y-2 w-full",children:[(0,i.jsx)("p",{className:"text-sm font-medium",children:"Good for:"}),(0,i.jsx)("div",{className:"flex flex-col items-center space-y-1.5",children:(r.goodFor||[]).map(e=>(0,i.jsx)("span",{className:"px-3 py-1 text-xs bg-gray-200 dark:bg-white/10 text-gray-700 dark:text-foreground rounded-full w-auto",children:e},e))})]})]}):(0,i.jsx)("p",{className:"text-muted-foreground",children:"Select an objective to see details."})})]})})};var tI=a(97001),tT=a(93735);function tD(e){var t,a,s;let{campaignName:r,setCampaignName:l,buyingType:o,handleBuyingTypeChange:d,campaignObjective:c,setCampaignObjective:u,displayedObjectives:m,selectedObjectiveDetails:p,specialAdCategories:g,setSpecialAdCategories:h,hasSpendingLimit:f,setHasSpendingLimit:x,onSpendingLimitAmountChange:b,spendingLimitAmount:v=0,isAdvantageBudgetEnabled:y,setIsAdvantageBudgetEnabled:S,isAbTestEnabled:j,setIsAbTestEnabled:A,campaignBidStrategy:C,setCampaignBidStrategy:w,pageSettings:N,accessToken:_,adAccountId:k,selectedCampaign:E,onCampaignSelect:I,isEditingExisting:T,onValidationChange:D,abTestData:P,onAbTestDataChange:O,currency:L}
1=e,[M,F]=(0,n.useState)(!1),[U,R]=(0,n.useState)(!1),[B,V]=(0,n.useState)(!1),[G,z]=(0,n.useState)(0),[q,H]=(0,n.useState)(!1),[W,Y]=(0,n.useState)(!1),[$,J]=(0,n.useState)(g.length>0),[K,Z]=(0,n.useState)(!0);(0,n.useEffect)(()=>{J(g.length>0)},[g]),(0,n.useEffect)(()=>{null==D||D(K)},[K,D]),(0,n.useEffect)(()=>{j&&A(!1),P&&(null==O||O(null))},[P,j,O,A]),(0,n.useEffect)(()=>{f?S(!0):S(!1)},[f,S]);let X=(0,n.useRef)(null);(0,n.useEffect)(()=>{var e,t,a;let i=(null==E?void 0:E.id)||null;if(!i||i===X.current)return;let n=Number(null!=(a=null!=(t=null!=(e=null==E?void 0:E.spend_cap)?e:null==E?void 0:E.spend_cap)?t:null==E?void 0:E.daily_budget)?a:null==E?void 0:E.daily_budget);if(!Number.isNaN(n)&&n>0){let e=n/100;f||x(!0),b&&v!==e&&b(e)}let s=null==E?void 0:E.bid_strategy;if(s){let e=e5.xn[s]||"LOWEST_COST";C!==e&&w(e)}else((null==E?void 0:E.daily_budget)||(null==E?void 0:E.lifetime_budget))&&"LOWEST_COST"!==C&&w("LOWEST_COST");X.current=i},[null==E?void 0:E.id]);let Q=null!=(s=null!=(a=null!=(t=null==E?void 0:E.spend_cap)?t:null==E?void 0:E.spend_cap)?a:null==E?void 0:E.daily_budget)?s:null==E?void 0:E.daily_budget,ee=f?v:(()=>{let e=Number(Q);return!Number.isNaN(e)&&e>0?e/100:v})(),et={"campaign-details":(0,i.jsx)(t_,{campaignName:r,setCampaignName:l,buyingType:o,handleBuyingTypeChange:d,isSectionCompleted:void 0,sectionType:void 0,accessToken:_,adAccountId:k,selectedCampaign:E,onCampaignSelect:I,isEditingExisting:T}),"campaign-objective":(0,i.jsx)(tE,{campaignObjective:c,setCampaignObjective:u,displayedObjectives:m,selectedObjectiveDetails:p,setShowTrafficInfoModal:F,setShowAppPromotionInfoModal:R,isSectionCompleted:void 0,sectionType:void 0}),"campaign-spending-limit":(0,i.jsx)(tj,{hasSpendingLimit:f,setHasSpendingLimit:x,onCompletionChange:e=>{H(e)},onValidationChange:Z,onSpendingLimitAmountChange:b,initialAmount:ee,currency:L,isSectionCompleted:void 0,sectionType:void 0}),"advantage-campaign-budget":(0,i.jsx)(tC,{isAdvantageBudgetEnabled:y,setIsAdvantageBudgetEnabled:S,campaignBidStrategy:C,setCampaignBidStrategy:w,onCompletionChange:e=>{Y(e)},isSectionCompleted:void 0,sectionType:void 0,disabled:!f}),"special-ad-category":(0,i.jsx)(tb,{specialAdCategories:g,setSpecialAdCategories:h,onCompletionChange:e=>J(e),isSectionCompleted:void 0,sectionType:void 0})};return(0,n.useEffect)(()=>{let e=e=>{"Step 1"===e.detail.pageTitle&&z(e=>e+1)};return window.addEventListener("pageSettingsChanged",e),()=>{window.removeEventListener("pageSettingsChanged",e)}},[]),(0,i.jsxs)("div",{className:"space-y-6",children:[N.filter(e=>!1!==e.isAvailable&&"ab-test"!==e.id&&("RESERVED"!==o||"campaign-spending-limit"!==e.id&&"advantage-campaign-budget"!==e.id&&"ab-test"!==e.id)&&e.isVisible).map((e,t)=>{let a,s=!1,l=T&&("campaign-objective"===e.id||"special-ad-category"===e.id);switch(e.id){case"campaign-details":s=""!==r.trim();break;case"campaign-objective":s=!0;break;case"special-ad-category":s=$;break;case"campaign-spending-limit":s=q;break;case"advantage-campaign-budget":s=W;break;default:s=!1}a="advantage-campaign-budget"===e.id?"RECOMMENDED":e.isRequired?"REQUIRED":"OPTIONAL";let o=et[e.id];if(!o)return null;let d={isSectionCompleted:s,sectionType:a,...l&&{disabled:!0}};return(0,i.jsx)(tT.$,{index:t,className:"section-wrapper",children:n.cloneElement(o,d)},e.id)}),(0,i.jsx)(e3.W,{isOpen:M,onOpenChange:F,title:"Traffic Objective",children:tI.E7}),(0,i.jsx)(e3.W,{isOpen:U,onOpenChange:R,title:"App Promotion",children:tI.vi})]},G)}var tP=a(82778),tO=a(28307),tL=a(69321),tM=a(88432);let tF=e=>{let{user:t,currentStep:a,currentStepPageSettings:n,campaignName:s,setCampaignName:r,buyingType:l,handleBuyingTypeChange:o,campaignObjective:d,setCampaignObjective:c,displayedObjectives:u,selectedObjectiveDetails:m,specialAdCategories:p,setSpecialAdCategories:g,hasSpendingLimit:h,setHasSpendingLimit:f,onSpendingLimitAmountChange:x,spendingLimitAmount:b,isAdvantageBudgetEnabled:v,setIsAdvantageBudgetEnabled:y,isAbTestEnabled:S,setIsAbTestEnabled:j,campaignBidStrategy:A,setCampaignBidStrategy:C,abTestData:w,onAbTestDataChange:N,adSetDetailsData:_,setAdSetDetailsData:k,adDetailsData:E,setAdDetail
1sData:I,accessToken:T,adAccountId:D,currency:P,selectedCampaign:O,onCampaignSelect:L,selectedAdSet:M,onAdSetSelect:F,isEditingExisting:U,onValidationChange:R,sectionValidation:B,connectedPages:V=[],publishedCampaignId:G,organizationId:z}=e;return(0,i.jsx)("div",{className:"mt-6",children:(()=>{switch(a){case ec.CAMPAIGN:return(0,i.jsx)(tD,{campaignName:s,setCampaignName:r,buyingType:l,handleBuyingTypeChange:o,campaignObjective:d,setCampaignObjective:c,displayedObjectives:u,selectedObjectiveDetails:m,specialAdCategories:p,setSpecialAdCategories:g,hasSpendingLimit:h,setHasSpendingLimit:f,isAdvantageBudgetEnabled:v,setIsAdvantageBudgetEnabled:y,isAbTestEnabled:S,setIsAbTestEnabled:j,campaignBidStrategy:A,setCampaignBidStrategy:C,pageSettings:n,accessToken:T,adAccountId:D,selectedCampaign:O,onCampaignSelect:L,isEditingExisting:U,onValidationChange:R,onSpendingLimitAmountChange:x,spendingLimitAmount:b,abTestData:w,onAbTestDataChange:N,currency:P});case ec.AD_SET:return(0,i.jsxs)("div",{className:"flex h-full flex-col gap-3 lg:flex-row",children:[(0,i.jsx)("div",{className:"min-w-0 flex-1",children:(0,i.jsx)(tP.I,{user:t,adSetDetailsData:_,setAdSetDetailsData:k,campaignObjective:d,campaignBidStrategy:A,buyingType:l,isAdvantageBudgetEnabled:v,pageSettings:n,sectionValidation:B,accessToken:T,campaignId:(null==O?void 0:O.id)||G,selectedAdSet:M,onAdSetSelect:F,isEditingExisting:U,connectedPages:V,currency:P,organizationId:z,adAccountId:D})}),(0,i.jsx)("div",{className:"w-full lg:sticky lg:top-6 lg:max-h-[calc(100vh-200px)] lg:w-[280px]",children:(0,i.jsx)(tL.i,{adSetDetailsData:_,campaignObjective:d,campaignBudget:b,isAdvantageBudgetEnabled:v,accessToken:T,organizationId:z,adAccountId:D})})]});case ec.AD:var e;return(0,i.jsxs)("div",{className:"flex h-full flex-col gap-3 lg:flex-row",children:[(0,i.jsx)("div",{className:"min-w-0 flex-1",children:(0,i.jsx)(tO.l,{user:t,adDetailsData:E,setAdDetailsData:I,campaignObjective:d,isPhoneCallDestinationRequired:"TRAFFIC"===d&&"LOWEST_COST"===A&&(null==(e=_.trafficConversionLocation)?void 0:e.toUpperCase())==="CALLS"})}),(0,i.jsx)("div",{className:"flex w-full flex-col rounded-lg border border-neutral-200 bg-white shadow-sm dark:border-border dark:bg-neutral-900 lg:sticky lg:top-6 lg:max-h-[calc(100vh-200px)] lg:w-[280px]",children:(0,i.jsx)(tM.W,{user:t,adDetailsData:E})})]});default:return null}})()})};var tU=a(42529),tR=a(99051);let tB=e=>{let{steps:t,currentStep:a,isStepCompleted:n,onStepClick:s}=e;return(0,i.jsx)("div",{className:"w-full shrink-0 overflow-x-auto p-3 sidebar-glass sidebar-glass-meta md:w-[200px] md:overflow-visible md:p-6",children:(0,i.jsx)("div",{className:"flex gap-1 md:block md:space-y-1",children:t.map(e=>{let t=e.id<=a||n(e.id)||e.id===a+1&&n(a),r=a===e.id,l=a>e.id&&n(e.id);return(0,i.jsxs)("div",{className:"sidebar-step shrink-0 whitespace-nowrap ".concat(r?"sidebar-step-current":""," ").concat(t?"cursor-pointer":"cursor-not-allowed opacity-50"),onClick:()=>t&&s(e.id),children:[l?(0,i.jsx)(tU.A,{className:"sidebar-step-icon sidebar-step-icon-completed"}):(0,i.jsx)(tR.A,{className:"sidebar-step-icon ".concat(r?"sidebar-step-icon-current":"text-muted-foreground")}),(0,i.jsx)("span",{className:"sidebar-step-label ".concat(r?"sidebar-step-label-current":"text-foreground"),children:e.title})]},e.id)})})})},tV=e=>{var t;let{isOpen:a,onOpenChange:n,currentStep:s,loadError:r,onRetryLoad:l,user:d,onStepClick:c,isStepCompleted:u,isPageSettingsOpen:m,setIsPageSettingsOpen:p,currentStepPageSettings:g,onPageSettingsSectionsChange:h,campaignSettings:f,setCampaignNameCallback:x,handleBuyingTypeChangeCallback:b,setCampaignObjectiveCallback:v,displayedObjectives:y,selectedObjectiveDetails:S,setSpecialAdCategoriesCallback:j,setHasSpendingLimitCallback:A,onSpendingLimitAmountChange:C,setIsAdvantageBudgetEnabledCallback:w,setIsAbTestEnabledCallback:N,setCampaignBidStrategyCallback:_,setAbTestDataCallback:k,adSetDetailsData:E,setAdSetDetailsData:I,adDetailsData:T,setAdDetailsData:D,accessToken:P,adAccountId:O,currency:L,selectedCampaign:M,onCampaignSelect:F,selectedAdSet:U,onAdSetSelect:R,isEditingExisting:B,onValidationChange:V,sectionValidation:G,canGoToPreviousStep:z,canGoToNextStep:q,canPublishCampaign:H,canPublishAdSet:W,isLoading:Y,isPublishingAdSet:$,onPrevious:J,onNext:K,onPublishCampaign:Z,onPublishAdSet:X,connectedPages:Q=[],publishedCampaignId:ee,organizationId:et}=e,ea=eu.EXPANDED;return(0,i.jsx)(i.Fragment,{children:(0,i.jsx)(ex.lG,{open:a,onOpenChange:n,modal:!0,children:(0,i.jsx)(ex.Cf,{className:"".concat(ea," h-[100dvh] flex flex-col overflow-hidden rounded-none p-0 sm:h-[90vh] sm:rou
1nded-lg md:flex-row [&>button.absolute.right-4.top-4]:cursor-pointer [&>button.absolute.right-4.top-4]:hover:opacity-100 [&>button.absolute.right-4.top-4]:transition-opacity has-custom-styled-x"),onPointerDownOutside:e=>{let t=e.target;(t.closest("[data-radix-toast-viewport]")||t.closest('[role="status"]')||t.closest('[aria-live="polite"]'))&&e.preventDefault()},onInteractOutside:e=>{let t=e.target;(t.closest("[data-radix-toast-viewport]")||t.closest('[role="status"]')||t.closest('[aria-live="polite"]'))&&e.preventDefault()},children:(0,i.jsxs)(ek.q,{children:[(0,i.jsx)(e_,{isOpen:m,onOpenChange:p,sections:g,onSectionsChange:h,pageTitle:"Step ".concat(s)}),(0,i.jsx)(tB,{steps:o.UT,currentStep:s,isStepCompleted:u,onStepClick:c}),(0,i.jsxs)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[(0,i.jsxs)("div",{className:"flex-grow overflow-y-auto p-6",children:[r&&(0,i.jsxs)("div",{role:"alert",className:"mb-4 flex items-start justify-between gap-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[(0,i.jsxs)("div",{className:"flex items-start gap-2",children:[(0,i.jsx)(eE.A,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"font-medium",children:"Failed to load the existing campaign data"}),(0,i.jsx)("p",{className:"mt-1 break-words",children:r.message})]})]}),l&&(0,i.jsxs)(eb.$,{variant:"outline",size:"sm",onClick:l,className:"flex-shrink-0",children:[(0,i.jsx)(eI.A,{className:"mr-2 h-3 w-3"}),"Retry"]})]}),(0,i.jsx)(e4,{currentStep:s,campaignName:f.name,selectedObjectiveDetails:S,adSetName:E.adSetName,user:d,setCampaignData:e=>{"string"==typeof e.name&&x(e.name),"string"==typeof e.objective&&v(e.objective),"string"==typeof e.buyingType&&b(e.buyingType),Array.isArray(e.specialAdCategories)&&j(e.specialAdCategories),"boolean"==typeof e.hasSpendingLimit&&A(e.hasSpendingLimit),"number"==typeof e.spendingLimitAmount&&C&&C(e.spendingLimitAmount),"boolean"==typeof e.isAdvantageBudgetEnabled&&w(e.isAdvantageBudgetEnabled),"boolean"==typeof e.isAbTestEnabled&&N(e.isAbTestEnabled),"string"==typeof e.bidStrategy&&_(e.bidStrategy),e.abTestData&&"object"==typeof e.abTestData&&k(e.abTestData)},setAdSetDetailsData:I,setAdDetailsData:D,currentCampaignData:f,currentAdSetDetailsData:E,currentAdDetailsData:T}),(0,i.jsx)(tF,{user:d,currentStep:s,currentStepPageSettings:g,campaignName:f.name,setCampaignName:x,buyingType:f.buyingType,handleBuyingTypeChange:b,campaignObjective:f.objective,setCampaignObjective:v,displayedObjectives:y,selectedObjectiveDetails:S,specialAdCategories:f.specialAdCategories,setSpecialAdCategories:j,hasSpendingLimit:f.hasSpendingLimit,setHasSpendingLimit:A,onSpendingLimitAmountChange:C,spendingLimitAmount:f.spendingLimitAmount,isAdvantageBudgetEnabled:f.isAdvantageBudgetEnabled,setIsAdvantageBudgetEnabled:w,isAbTestEnabled:f.isAbTestEnabled,setIsAbTestEnabled:N,campaignBidStrategy:f.bidStrategy,setCampaignBidStrategy:_,abTestData:null!=(t=f.abTestData)?t:null,onAbTestDataChange:k,adSetDetailsData:E,setAdSetDetailsData:I,adDetailsData:T,setAdDetailsData:D,accessToken:P,adAccountId:O,currency:L,selectedCampaign:M,onCampaignSelect:F,selectedAdSet:U,onAdSetSelect:R,isEditingExisting:B,onValidationChange:V,sectionValidation:G,connectedPages:Q,publishedCampaignId:ee,organizationId:et})]}),(0,i.jsx)(eM,{currentStep:s,canGoToPreviousStep:z,canGoToNextStep:q,canPublishCampaign:H,canPublishAdSet:W,isLoading:Y,isPublishingAdSet:$,isEditingExisting:B,isEditingExistingAdSet:null!==U,onPrevious:J,onNext:K,onPublishCampaign:Z,onPublishAdSet:X,onPageSettingsClick:()=>p(!0)})]})]})})})})};var tG=a(92853);let tz=e=>{let{isOpen:t,onClose:a,campaign:n,selectedObjectiveDetails:s}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:e=>!e&&a(),children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md animate-in fade-in-0 duration-300 [&>button.absolute.right-4.top-4]:cursor-pointer [&>button.absolute.right-4.top-4]:hover:opacity-100 [&>button.absolute.right-4.top-4]:transition-opacity",children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{className:"text-lg font-semibold text-green-600",children:"\uD83C\uDF89 Campaign Created Successfully!"})}),(0,i.jsxs)("div",{className:"space-y-3",children:[(0,i.jsx)("p",{className:"text-gray-600 dark:text-muted-foreground",children:"Your campaign has been successfully created and is now active on Meta."}),n&&(0,i.jsxs)("div",{className:"bg-gray-50 dark:bg-white/5 rounded-lg p-4 space-y-2",children:[(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Campaign Name:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground",children:n.name})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Campaign ID:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground font-mono text-sm",children:n.id})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Objective:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground",children:(null==s?void 0:s.label)||n.objective})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Status:"}),(0,i.jsx)("span",{className:"text-green-600 font-medium",children:n.status})]})]}),(0,i.jsx)("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-500/30 rounded-lg p-3",children:(0,i.jsxs)("p",{className:"text-blue-800 dark:text-blue-300 text-sm",children:[(0,i.jsx)(tG.Le,{state:"happy",size:28,skin:"meta",className:"mr-1 align-middle",fallback:(0,i.jsx)(i.Fragment,{children:"\uD83D\uDCA1"})})," ",(0,i.jsx)("strong",{children:"Next Steps:"})," You can now create ad sets and ads for this campaign, or monitor its performance in your Meta Ads Manager."]})})]}),(0,i.jsx)(ex.Es,{className:"flex justify-center",children:(0,i.jsx)(eb.$,{onClick:a,className:"bg-green-600 hover:bg-green-700 text-white cursor-pointer",children:"Great! Close"})})]})})};function tq(e){var t;let{className:a="mt-4",reviewPayload:n}=e,s=null!=(t=null==n?void 0:n.items)?t:[],r=null==n?void 0:n.mappingError;return 0!==s.length||r?(0,i.jsxs)("div",{className:a,children:[r&&(0,i.jsxs)("div",{role:"alert",className:"mb-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[(0,i.jsx)("p",{className:"font-medium",children:"Review unavailable"}),(0,i.jsxs)("p",{className:"mt-1 break-words",children:["The settings could not be mapped to a publish payload, so this review may be incomplete. Publishing is blocked — adjust the highlighted settings and try again. (",r,")"]})]}),s.length>0&&(0,i.jsx)("dl",{className:"max-h-56 overflow-auto rounded-md border border-border bg-muted/40 p-3 text-sm",children:s.map(e=>(0,i.jsxs)("div",{className:"flex items-start justify-between gap-3 border-b border-border/60 py-2 last:border-b-0",children:[(0,i.jsx)("dt",{className:"font-medium text-foreground",children:e.label}),(0,i.jsx)("dd",{className:"text-right text-muted-foreground break-words",children:String(e.value)})]},"".concat(e.section,"-").concat(e.publishPath)))})]}):null}let tH=e=>{let{isOpen:t,onOpenChange:a,onConfirm:n,isLoading:s,reviewPayload:r}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md [&>button.absolute.right-4.top-4]:cursor-pointer [&>button.absolute.right-4.top-4]:hover:opacity-100 [&>button.absolute.right-4.top-4]:transition-opacity",children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{className:"text-lg font-semibold",children:"Publish Campaign"})}),(0,i.jsxs)("div",{className:"py-4",children:[(0,i.jsx)("p",{className:"text-gray-600 dark:text-muted-foreground",children:"Are you sure you want to publish a campaign with no ad sets or ads?"}),(0,i.jsx)(tq,{reviewPayload:r})]}),(0,i.jsxs)(ex.Es,{className:"flex justify-end space-x-2",children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Cancel"}),(0,i.jsx)(eb.$,{onClick:()=>{a(!1),n()},disabled:s,className:"cursor-pointer bg-gradient-to-r from-green-500 to-emerald-500 hover:from-green-600 hover:to-emerald-600 text-white",children:s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eD.A,{className:"h-4 w-4 animate-spin mr-2"}),"Publishing..."]}):"Publish"})]})]})})},tW=e=>{let{isOpen:t,onOpenChange:a,onConfirm:n,isLoading:s,isUpdating:r=!1,reviewPayload:l}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md [&>button.absolute.right-4.top-4]:cursor-pointer",children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{children:r?"Update Ad Set":"Publish Ad Set"})}),(0,i.jsxs)("div",{className:"py-4",children:[(0,i.jsx)("p",{className:"text-sm text-muted-foreground",children:r?"Are you sure you want to update this ad set? The changes will be applied immediately to your running ad set.":"Are you sure you want to publish this ad set? Once published, your ad set will go live and start spending your budget."}),(0,i.jsx)(tq,{reviewPayload:l})]}),(0,i.jsxs)(ex.Es,{children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>a(!1),disabled:s,className:"cursor-pointer",children:"Cancel"}),(0,i.jsx)(eb.$,{onClick:n,disabled:s||!!(null==l?void 0:l.mappingError),className:"cursor-pointer bg-gradient-to-r from-green-500 to-emerald-500 hover:from-green-600 hover:to-emerald-600 text-white",children:s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eD.A,{className:"h-4 w-4 animate-spin mr-2"}),r?"Updating...":"Publishing..."]}):r?"Update Ad Set":"Publish Ad Set"})]})]})})};var tY=a(74832),t$=a(93499);let tJ=e=>{let{isOpen:t,onClose:a,message:n,billingCenterUrl:s}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:e=>!e&&a(),children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md",children:[(0,i.jsxs)(ex.c7,{children:[(0,i.jsx)(ex.L3,{children:"Failed to publish ad"}),(0,i.jsx)(ex.rr,{children:n||"Update payment method: Visit the Billing and payment center to add a valid payment method."})]}),(0,i.jsxs)(ex.Es,{className:"gap-2 sm:gap-2",children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:a,children:"Close"}),(0,i.jsx)(eb.$,{asChild:!0,children:(0,i.jsxs)("a",{href:s,target:"_blank",rel:"noopener noreferrer",children:["Billing center",(0,i.jsx)(t$.A,{className:"ml-2 h-4 w-4","aria-hidden":"true"})]})})]})]})})},tK=e=>{let{isOpen:t,onOpenChange:a,onConfirm:n,isLoading:s,reviewPayload:r}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md animate-in fade-in-0 duration-300 [&>button.absolute.right-4.top-4]:cursor-pointer [&>button.absolute.right-4.top-4]:hover:opacity-100 [&>button.absolute.right-4.top-4]:transition-opacity",children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{children:"Publish Ad"})}),(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsx)("p",{className:"text-gray-600 dark:text-muted-foreground",children:"Are you ready to publish this ad? Once published, it will be submitted to Meta for review and will go live after approval."}),(0,i.jsx)("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-500/30 rounded-lg p-3",children:(0,i.jsxs)("p",{className:"text-amber-800 dark:text-amber-300 text-sm",children:[(0,i.jsx)("strong",{children:"Note:"})," Make sure you've reviewed all ad details including the creative, text, and targeting settings. You can edit the ad after publishing if needed."]})}),(0,i.jsx)(tq,{className:"",reviewPayload:r})]}),(0,i.jsxs)(ex.Es,{className:"flex gap-2 sm:gap-2",children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>a(!1),disabled:s,className:"cursor-pointer",children:"Go Back"}),(0,i.jsx)(eb.$,{onClick:n,disabled:s,className:"bg-gradient-to-r from-green-500 to-emerald-500 hover:from-green-600 hover:to-emerald-600 text-white cursor-pointer",children:s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eD.A,{className:"h-4 w-4 animate-spin mr-2"}),"Publishing..."]}):"Yes, Publish Ad"})]})]})})},tZ=e=>{let{isOpen:t,onClose:a,ad:n,campaignName:s,adSetName:r}=e;return(0,i.jsx)(ex.lG,{open:t,onOpenChange:e=>!e&&a(),children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md animate-in fade-in-0 duration-300 [&>button.absolute.right-4.top-4]:cursor-pointer [&>button.absolute.right-4.top-4]:hover:opacity-100 [&>button.absolute.right-4.top-4]:transition-opacity",children:[(0,i.jsx)(ex.c7,{children:(0,i.jsx)(ex.L3,{className:"text-lg font-semibold text-green-600",children:"\uD83C\uDF89 Ad Published Successfully!"})}),(0,i.jsxs)("div",{className:"space-y-3",children:[(0,i.jsx)("p",{className:"text-gray-600 dark:text-muted-foreground",children:"Your ad has been successfully published and is now active on Meta."}),n&&(0,i.jsxs)("div",{className:"bg-gray-50 dark:bg-white/5 rounded-lg p-4 space-y-2",children:[(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Ad Name:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground",children:n.name})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Ad ID:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground font-mono text-sm",children:n.id})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Campaign:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground",children:s})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Ad Set:"}),(0,i.jsx)("span",{className:"text-gray-900 dark:text-foreground",children:r})]}),(0,i.jsxs)("div",{className:"flex justify-between",children:[(0,i.jsx)("span",{className:"font-medium text-gray-700 dark:text-foreground",children:"Status:"}),(0,i.jsx)("span",{className:"text-green-600 font-medium",children:n.status})]})]}),(0,i.jsx)("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-500/30 rounded-lg p-3",children:(0,i.jsxs)("p",{className:"text-blue-800 dark:text-blue-300 text-sm",children:[(0,i.jsx)(tG.Le,{state:"happy",size:28,skin:"meta",className:"mr-1 align-middle",fallback:(0,i.jsx)(i.Fragment,{children:"\uD83D\uDCA1"})})," ",(0,i.jsx)("strong",{children:"What's Next:"})," Your ad is now live! Monitor its performance in the Ads Manager dashboard. You can edit, pause, or duplicate this ad at any time."]})})]}),(0,i.jsx)(ex.Es,{className:"flex justify-center",children:(0,i.jsx)(eb.$,{onClick:a,className:"bg-green-600 hover:bg-green-700 text-white cursor-pointer",children:"Awesome! Close"})})]})})},tX=e=>{let{showSuccessModal:t,onCloseSuccessModal:a,campaign:n,selectedObjectiveDetails:s,showConfirmationModal:r,setShowConfirmationModal:l,onConfirmPublishCampaign:o,isCampaignLoading:d,campaignReviewPayload:c,showAdSetConfirmationModal:u,setShowAdSetConfirmationModal:m,onConfirmPublishAdSet:p,isPublishingAdSet:g,selectedAdSet:h,adSetReviewPayload:f,showAdSetSuccessModal:x,onCloseAdSetSuccessModal:b,publishedAdSet:v,campaignName:y,showAdConfirmationModal:S,setShowAdConfirmationModal:j,onConfirmPublishAd:A,isPublishingAd:C,adReviewPayload:w,showAdSuccessModal:N,onCloseAdSuccessModal:_,publishedAd:k,adSetName:E,adBillingErrorMessage:I,onCloseAdBillingError:T,billingCenterUrl:D}=e;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(tz,{isOpen:t,onClose:a,campaign:n?{id:n.id,name:n.name||"",objective:n.objective||"",status:n.status||""}:null,selectedObjectiveDetails:s?{label:s.label||s.name||""}:null}),(0,i.jsx)(tH,{isOpen:r,onOpenChange:l,onConfirm:o,isLoading:d,reviewPayload:c}),(0,i.jsx)(tW,{isOpen:u,onOpenChange:m,onConfirm:p,isLoading:g,isU
1pdating:null!==h,reviewPayload:f}),(0,i.jsx)(tY.m,{isOpen:x,onClose:b,adSet:v,campaignName:y}),void 0!==S&&j&&A&&(0,i.jsx)(tK,{isOpen:S,onOpenChange:j,onConfirm:A,isLoading:C||!1,reviewPayload:w}),void 0!==N&&_&&(0,i.jsx)(tZ,{isOpen:N,onClose:_,ad:k||null,campaignName:y,adSetName:E||(null==v?void 0:v.name)||"Ad Set"}),T&&D&&(0,i.jsx)(tJ,{isOpen:!!I,onClose:T,message:I||null,billingCenterUrl:D})]})};function tQ(e){var t;let{open:a,onOpenChange:n,draft:s,onContinue:r,onStartFresh:l}=e,o=s.campaignSettings.name||(null==(t=s.selectedCampaign)?void 0:t.name)||"Untitled Campaign",d=s.currentStep,c=function(e){switch(e){case 1:return"Campaign";case 2:return"Ad Set";case 3:return"Ad";default:return"Step ".concat(e)}}(d),u=function(e){let t=new Date(e),a=new Date().getTime()-t.getTime(),i=Math.floor(a/6e4),n=Math.floor(a/36e5),s=Math.floor(a/864e5);return i<1?"just now":i<60?"".concat(i," minute").concat(1===i?"":"s"," ago"):n<24?"".concat(n," hour").concat(1===n?"":"s"," ago"):s<7?"".concat(s," day").concat(1===s?"":"s"," ago"):t.toLocaleDateString()}(s.savedAt);return(0,i.jsx)(ex.lG,{open:a,onOpenChange:n,children:(0,i.jsxs)(ex.Cf,{className:"sm:max-w-md",children:[(0,i.jsxs)(ex.c7,{children:[(0,i.jsx)(ex.L3,{children:"Continue where you left off?"}),(0,i.jsxs)(ex.rr,{children:["You have unsaved progress from ",u]})]}),(0,i.jsxs)("div",{className:"space-y-3 py-2",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,i.jsx)("span",{className:"text-muted-foreground",children:"Campaign"}),(0,i.jsx)("span",{className:"font-medium truncate max-w-[200px]",children:o})]}),(0,i.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,i.jsx)("span",{className:"text-muted-foreground",children:"Step"}),(0,i.jsxs)("span",{className:"font-medium",children:[d," of 3 (",c,")"]})]})]}),(0,i.jsxs)(ex.Es,{className:"sm:justify-between",children:[(0,i.jsx)(eb.$,{variant:"outline",onClick:()=>{l(),n(!1)},children:"Start Fresh"}),(0,i.jsx)(eb.$,{onClick:()=>{r(),n(!1)},children:"Continue"})]})]})})}var t0=a(59704),t1=a(35920),t2=a(79552);let t4={isLoading:!1,error:null,campaign:null,adSet:null,ad:null,adCreative:null,abTest:null,step:"campaign"};async function t5(e){let{campaignId:t,campaignDetails:a,adAccountId:i,organizationId:n}=e,{data:{session:s}}=await z.supabase.auth.getSession(),r=null==s?void 0:s.access_token,l=await fetch("/api/campaigns/save",{method:"POST",headers:{"Content-Type":"application/json",...r?{Authorization:"Bearer ".concat(r)}:{}},body:JSON.stringify({campaignId:t,campaignDetails:a,adAccountId:i,organizationId:n}),credentials:"include"});if(!l.ok){let e=await l.json().catch(()=>({}));throw Error((null==e?void 0:e.reason)||"Failed to save campaign to database (".concat(l.status,")"))}console.log("Successfully saved campaign to database")}function t3(e,t){return e instanceof Error?e.message:t}var t7=a(7438),t6=a(40399),t8=a(88066),t9=a(98211);function ae(e,t){if(e){if("date"===t)return e.split("T")[0];if("time"===t&&e.includes("T"))return e.split("T")[1].slice(0,5)}}function at(e){if(null!=e)return(("string"==typeof e?parseInt(e):e)/100).toString()}var aa=a(14689),ai=a(71708),an=a(7568),as=a(99914);function ar(e){var t;return{id:e.campaign_id,name:e.name||"",status:e.status||e.effective_status||"PAUSED",objective:e.objective||"",bid_strategy:e.bid_strategy,buying_type:"AUCTION",special_ad_categories:[],spend_cap:null!=(t=e.spend_cap)?t:void 0,daily_budget:e.daily_budget?String(e.daily_budget):void 0,lifetime_budget:e.lifetime_budget?String(e.lifetime_budget):void 0,created_time:e.created_at||new Date().toISOString(),updated_time:e.updated_at||new Date().toISOString()}}function al(e){return{id:e.ad_set_id,name:e.name||"",status:e.status}}function ao(e,t,a){var i,n;let s=t?(0,Y.tV)(t):void 0,r=e.optimization_goal?(0,t8.mapMetaAPIToPerformanceGoal)(e.optimization_goal,s,e.destination_type):"";return{...a,adSetName:e.name||"",performanceGoal:r,budgetType:null!==e.daily_budget&&void 0!==e.daily_budget?"daily":"lifetime",budgetValue:e.daily_budget||e.lifetime_budget||"",...e.targeting&&{targetL
1ocations:(0,an.TC)(null==(i=e.targeting)?void 0:i.geo_locations,null==(n=e.targeting)?void 0:n.excluded_geo_locations).map(e=>{var t;return{key:e.key,name:null!=(t=e.name)?t:e.key,type:String(e.type),radius:e.radius,distanceUnit:e.distanceUnit,includeExclude:e.includeExclude}})}}}async function ad(e,t,a){try{let i=await (0,as.getAuthHeaders)(),n=await fetch("/api/ads-manager/entity",{method:"POST",headers:i,body:JSON.stringify({entityType:e,entityId:t,organizationId:a})});if(!n.ok){let t=await n.json().catch(()=>({}));return{data:null,error:{message:t.reason||"Failed to fetch ".concat(e),code:t.code||"FETCH_FAILED"}}}return{data:(await n.json()).data,error:null}}catch(e){return{data:null,error:{message:e instanceof Error?e.message:"Network error",code:"NETWORK_ERROR"}}}}var ac=a(25959),au=a(89863);let am=(0,ac.v)()((0,au.Zr)((e,t)=>({drafts:{},saveDraft:t=>{if(t.organizationId){if(!(new Blob([JSON.stringify(t)]).size<=1e6))return void console.warn("[metaDraftStore] Draft exceeds the localStorage size budget; skipping save");e(e=>({drafts:{...e.drafts,[t.organizationId]:t}}))}},loadDraft:e=>{let{drafts:a}=t(),i=a[e];return!function(e){return!!e&&!!e.organizationId&&!!e.savedAt&&void 0!==e.currentStep&&!!e.campaignSettings&&!!e.adSetDetailsData&&!!e.adDetailsData&&!0}(i)?null:!function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6048e5,a=new Date(e.savedAt);return new Date().getTime()-a.getTime()>t}(i)?i:(t().clearDraft(e),null)},clearDraft:t=>{e(e=>{let a={...e.drafts};return delete a[t],{drafts:a}})},hasDraft:e=>null!==t().loadDraft(e),clearAllDrafts:()=>{e({drafts:{}})}}),{name:"meta-draft-storage",skipHydration:!0}));var ap=a(63583);function ag(e){var t,a,c,u,m,p,g;let{isOpen:h,onOpenChange:f,user:x,onSuccess:b,syncNewEntity:v,existingCampaignId:y,existingAdSetId:S,existingAdId:j}=e,{currentOrganization:A}=(0,s.Z5)(),{connectedPages:C}=(0,l.z)();(0,r.K)(h);let w=function(e,t){var a,i;let r=function(e){let{initialStep:t=1,totalSteps:a}=e,[i,s]=(0,n.useState)(t),[r,l]=(0,n.useState)(new Set),o=(0,n.useCallback)(e=>r.has(e),[r]),d=i<a,c=i>1,u=(0,n.useCallback)(()=>{d&&(l(e=>new Set(e).add(i)),s(e=>e+1))},[d,i]),m=(0,n.useCallback)(()=>{c&&s(e=>e-1)},[c]),p=(0,n.useCallback)(e=>{e>=1&&e<=a&&(e>i&&l(t=>{let a=new Set(t);for(let t=i;t<e;t++)a.add(t);return a}),s(e))},[i,a]);return{currentStep:i,completedSteps:r,goToNextStep:u,goToPreviousStep:m,goToStep:p,isStepCompleted:o,canGoToNextStep:d,canGoToPreviousStep:c}}({totalSteps:t}),l=(()=>{let[e,t]=(0,n.useState)({name:"",buyingType:ef.lg.AUCTION,objective:o.Sl[0].id,specialAdCategories:[],hasSpendingLimit:!1,spendingLimitAmount:0,isAdvantageBudgetEnabled:!1,isAbTestEnabled:!1,bidStrategy:ef.tQ.LOWEST_COST,abTestData:null}),a=(0,n.useMemo)(()=>"RESERVED"===e.buyingType?o.Sl.filter(e=>"AWARENESS"===e.id||"ENGAGEMENT"===e.id):o.Sl,[e.buyingType]),i=(0,n.useMemo)(()=>{let t=a.find(t=>t.id===e.objective);if(!t)return null;let i={...t};return"RESERVED"===e.buyingType&&("AWARENESS"===i.id&&i.goodForReservation?i.goodFor=i.goodForReservation:"ENGAGEMENT"===i.id&&(i.descriptionReservation&&(i.description=i.descriptionReservation),i.goodForReservation&&(i.goodFor=i.goodForReservation))),i},[e.objective,e.buyingType,a]),s=(0,n.useCallback)(e=>{t(t=>({...t,name:e}))},[]),r=(0,n.useCallback)(e=>{t(t=>{let a="RESERVED"===e?"RESERVED":"AUCTION",i=t.objective;return a===ef.lg.RESERVED&&t.objective!==ef.ah.AWARENESS&&t.objective!==ef.ah.ENGAGEMENT&&(i=ef.ah.AWARENESS),{...t,buyingType:a,objective:i}})},[]),l=(0,n.useCallback)(e=>{t(t=>{let a=["AWARENESS","TRAFFIC","ENGAGEMENT","LEADS","APP_PROMOTION","SALES"].includes(e)?e:t.objective;return{...t,objective:a}})},[]),d=(0,n.useCallback)(e=>{t(t=>({...t,specialAdCategories:"function"==typeof e?e(t.specialAdCategories):e}))},[]),c=(0,n.useCallback)(e=>{t(t=>({...t,hasSpendingLimit:e}))},[]),u=(0,n.useCallback)(e=>{t(t=>({...t,spendingLimitAmount:e}))},[]),m=(0,n.useCallback)(e=>{t(t=>({...t,isAdvantageBudgetEnabled:e}))},[]),p=(0,n.useCallback)(e=>{t(t=>({...t,isAbTestEnabled:e}))},[]),g=(0,n.useCallback)(e=>{t(t=>{let a=["LOWEST_COST_WITHOUT_CAP","LOWEST_COST","COST_PER_RESULT_GOAL","COST_CAP","BID_CAP"].includes(e)?e:t.bidStrategy;return{...t,bidStrategy:a}})},[]),h=(0,n.useCallback)(e=>{t(t=>({...t,abTestData:e}))},[]),f=(0,n.useCallback)(e=>{t(t=>({...t,...e}))},[]);return{campaignSettings:e,displayedObjectives:a,selectedObjectiveDetails:i,setCampaignNameCallback:s,handleBuyingTypeChangeCallback:r,setCampaignObjectiveCallback:l,setSpecialAdCategoriesCallback:d,setHasSpendingLimitCallback:c,setSpendingLimitAmountCallback:u,setIsAdvantageBudgetEnabledCallback:m,setIsAbTestEnabledCallback:p,setCampaignBidStrategyCallback:g,setAbTestDataCallback:h,resetCampaignSettings:(0,n.useCallback)(()=>{t({name:"",buyingType:ef.lg.AUCTION,objective:o.Sl[0].id,specialAdCategories:[],hasSpendingLimit:!1,spendingLimitAmount:0,isAdvantageBudgetEnabled:!1,isAbTestEnabled:!1,bidStrategy:ef.tQ.LOWEST_COST,abTestData:null})},[]),setBatchCampaignSettings:(0,n.useCallback)(e=>{t(t=>({...t,...e}))},[]),loadCampaignSettingsState:f}})(),d=(0,n.useMemo)(()=>({buyingType:l.campaignSettings.buyingType,objective:l.campaignSettings.objective,bidStrategy:l.campaignSettings.bidStrategy,isAdvantageBudgetEnabled:l.campaignSettings.isAdvantageBudgetEnabled}),[l.campaignSettings.buyingType,l.campaignSettings.objective,l.campaignSettings.bidStrategy,l.campaignSettings.isAdvantageBudgetEnabled]),c=(0,t1.H)(d),u=function(e){let{objective:t,isAdvantageBudgetEnabled:a=!1}
1=e,[i,s]=(0,n.useState)((0,o.gU)()),[r,l]=(0,n.useState)({facebookPage:!0,performanceGoal:!0,frequencyControl:!0,budgetAndSchedule:!0,advantagePlusAudience:!0}),d=(0,n.useCallback)(()=>{let e=!!a||!!i.budgetValue&&!isNaN(parseFloat(String(i.budgetValue)))&&parseFloat(String(i.budgetValue))>0,t=!!a||!!i.scheduleStartDate,n=!1;if(t)if(a)n=!0;else try{if(i.scheduleStartDate&&i.scheduleStartTime){let e=new Date(i.scheduleStartDate+"T"+i.scheduleStartTime);if(!isNaN(e.getTime())){let t=new Date;n=e.getTime()>=t.getTime()-9e5}}}catch(e){n=!1}return e&&t&&n},[i.budgetValue,i.scheduleStartDate,i.scheduleStartTime,a]),c=(0,n.useCallback)(()=>{let e=["TRAFFIC","ENGAGEMENT","LEADS","SALES"].includes(t),a=!!i.performanceGoal;e&&(a=!!i.trafficConversionLocation&&!!i.performanceGoal);let n=!!i.frequencyControlType;["TRAFFIC","SALES","LEADS","APP_PROMOTION"].includes(t)&&(n=!0);let s=!!i.facebookPageId;["LEADS","SALES"].includes(t)&&(s=!0),"TRAFFIC"===t&&("WEBSITE"===i.trafficConversionLocation||"Website"===i.trafficConversionLocation||"website"===i.trafficConversionLocation)&&(s=!0),l({facebookPage:s,performanceGoal:a,frequencyControl:n,budgetAndSchedule:d(),advantagePlusAudience:!!i.targetLocations&&i.targetLocations.length>0})},[i.facebookPageId,i.performanceGoal,i.trafficConversionLocation,i.frequencyControlType,i.targetLocations,d,t]),u=(0,n.useCallback)(()=>{var e;let t=Object.values(r).every(e=>e),n=!!(null==(e=i.adSetName)?void 0:e.trim()),s=a||!!i.budgetType;return t&&n&&s},[r,i.adSetName,i.budgetType,a]),m=(0,n.useCallback)(e=>u()&&e===ec.AD_SET,[u]),p=(0,n.useCallback)(()=>{s((0,o.gU)())},[]),g=(0,n.useCallback)(e=>{s(e)},[]);return(0,n.useEffect)(()=>{c()},[c]),{adSetDetailsData:i,setAdSetDetailsData:s,sectionValidation:r,validateAdSet:u,canPublishAdSet:m,resetAdSetData:p,loadAdSetState:g}}({objective:l.campaignSettings.objective,isAdvantageBudgetEnabled:l.campaignSettings.isAdvantageBudgetEnabled}),m=function(e){let[t,a]=(0,n.useState)(!1),[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(!1),[o,d]=(0,n.useState)(!1),[c,u]=(0,n.use
1State)(!1),[m,p]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null),[f,x]=(0,n.useState)(!1),[b,v]=(0,n.useState)(!1),[y,S]=(0,n.useState)(!1),[j,A]=(0,n.useState)(null),[C,w]=(0,n.useState)(null),[N,_]=(0,n.useState)(null),[k,E]=(0,n.useState)(!0);return{isPageSettingsOpen:t,setIsPageSettingsOpen:a,showSuccessModal:i,setShowSuccessModal:s,showConfirmationModal:r,setShowConfirmationModal:l,isPublishingAdSet:o,setIsPublishingAdSet:d,showAdSetConfirmationModal:c,setShowAdSetConfirmationModal:u,showAdSetSuccessModal:m,setShowAdSetSuccessModal:p,publishedAdSet:g,setPublishedAdSet:h,isPublishingAd:f,setIsPublishingAd:x,showAdConfirmationModal:b,setShowAdConfirmationModal:v,showAdSuccessModal:y,setShowAdSuccessModal:S,publishedAd:j,setPublishedAd:A,selectedCampaign:C,setSelectedCampaign:t=>{if(w(t),t&&(null==e?void 0:e.setBatchCampaignSettings)){let a=t.objective?(0,t7.tV)(t.objective):void 0,i=t.bid_strategy&&e5.xn[t.bid_strategy]||"LOWEST_COST",n=void 0!==t.spend_cap&&null!==t.spend_cap,s=n?Number(t.spend_cap)/100:0,r={name:t.name||"",bidStrategy:i,specialAdCategories:t.special_ad_categories||[],hasSpendingLimit:n,spendingLimitAmount:s};a&&(r.objective=a),t.buying_type&&(r.buyingType="RESERVED"===t.buying_type?"RESERVED":"AUCTION"),e.setBatchCampaignSettings(r)}else if(t&&t.objective&&(null==e?void 0:e.setCampaignObjectiveCallback)){let a=(0,t7.tV)(t.objective);e.setCampaignObjectiveCallback(a)}},isEditingExisting:null!==C,selectedAdSet:N,setSelectedAdSet:_,isStep1Valid:k,setIsStep1Valid:E,resetModalState:()=>{w(null),_(null),h(null),A(null),s(!1),l(!1),u(!1),p(!1),v(!1),S(!1),d(!1),x(!1),E(!0)},loadModalSelectionState:(e,t)=>{w(e),_(t)}}}({setCampaignObjectiveCallback:l.setCampaignObjectiveCallback,setBatchCampaignSettings:l.setBatchCampaignSettings}),[p,g]=(0,n.useState)(o.I3),h=(0,t6.IA)(),f=function(e){let[t,a]=(0,n.useState)(t4),[i,r]=(0,n.useState)(null),{currentOrganization:l}=(0,s.Z5)(),o=(0,n.useCallback)(e=>{let t=e.organizationId||(null==l?void 0:l.id);if(!t)throw Error("Organization ID is required to initialize Meta API service");let a={...e,organizationId:t},i=(0,Y.createMetaApiService)(a);return r(i),i},[null==l?void 0:l.id]),d=(0,n.useCallback)(e=>{a(t=>({...t,isLoading:e}))},[]),c=(0,n.useCallback)(e=>{a(t=>({...t,error:e,isLoading:!1}))}
1,[]),u={setState:a,setLoading:d,setError:c},{createCampaign:m,updateCampaign:p,createAdSet:g,createAdCreative:h,createAd:f,createABTest:x}=function(e){let{config:t,apiService:a,state:i,actions:s,initializeService:r,organizationId:l}=e,{setState:o,setLoading:d,setError:c}=s,u=(0,n.useCallback)(async e=>{if(!t)throw c("API configuration is required"),Error("API configuration is required");d(!0),c(null);try{let i=a||r(t),n=await i.createCampaign(e),s=await i.getCampaign(n.id);return l&&await t5({campaignId:n.id,campaignDetails:s,adAccountId:t.adAccountId,organizationId:l}),o(e=>({...e,campaign:s,step:"adset",isLoading:!1})),n.id}catch(e){throw c(t3(e,"Failed to create campaign")),e}},[t,a,r,l,o,d,c]),m=(0,n.useCallback)(async(e,i)=>{if(!t)return void c("API configuration is required");d(!0),c(null);try{let n=a||r(t);await n.updateCampaign(e,i);let s=await n.getCampaign(e);l&&await t5({campaignId:e,campaignDetails:s,adAccountId:t.adAccountId,organizationId:l}),o(e=>({...e,campaign:s,isLoading:!1}))}catch(e){c(t3(e,"Failed to update campaign"))}},[t,a,r,l,o,d,c]),p=(0,n.useCallback)(async e=>{if(!a||!i.campaign)return void c("Campaign must be created first");d(!0),c(null);try{let t={...e,campaign_id:i.campaign.id},n=await a.createAdSet(t),s=await a.getAdSet(n.id);o(e=>({...e,adSet:s,step:"creative",isLoading:!1}))}catch(e){c(t3(e,"Failed to create ad set"))}},[a,i.campaign,o,d,c]),g=(0,n.useCallback)(async e=>{if(!a)return void c("API service not initialized");d(!0),c(null);try{let t=await a.createAdCreative(e),i=await a.getAdCreative(t.id);o(e=>({...e,adCreative:i,step:"ad",isLoading:!1}))}catch(e){c(t3(e,"Failed to create ad creative"))}},[a,o,d,c]);return{createCampaign:u,updateCampaign:m,createAdSet:p,createAdCreative:g,createAd:(0,n.useCallback)(async e=>{if(!a||!i.adSet||!i.adCreative)return void c("Ad set and creative must be created first");d(!0),c(null);try{let t={...e,adset_id:i.adSet.id,creative:{creative_id:i.adCreative.id}},n=await a.createAd(t),s=await a.getAd(n.id);o(e=>({...e,ad:s,step:"complete",isLoading:!1}))}catch(e){c(t3(e,"Failed to create ad"))}},[a,i.adSet,i.adCreative,o,d,c]),createABTest:(0,n.useCallback)(async e=>{if(!t||!a)return void c("API configuration is required");d(!0),c(null);try{console.log("Fetching business ID for A/B test creation...");let i=l?await (0,Y.Mf)(t.adAccountId,l):null;if(!i){console.warn("No business ID found - A/B test creation is not available"),o(e=>({...e,abTest:null,isLoading:!1}));return}console.log("Business ID found:",i),console.log("Creating A/B test with data:",JSON.stringify(e,null,2));let n=await a.createABTest(i,e),s=await a.getABTest(n.id);o(e=>({...e,abTest:s,isLoading:!1}))}catch(e){console.error("Failed to create A/B test:",e),e instanceof Error&&e.message.includes("A/B testing is not available")?console.warn("A/B testing not available for this account"):console.error("Unexpected error creating A/B test:",e),o(e=>({...e,abTest:null,isLoading:!1}))}},[t,a,o,d,c])}}({config:e,apiService:i,state:t,actions:u,initializeService:o,organizationId:null==l?void 0:l.id}),{createFullCampaign:b}=function(e){let{config:t,apiService:a,actions:i,initializeService:s,organizationId:r}=e,{setState:l,setLoading:o,setError:d}=i;return{createFullCampaign:(0,n.useCallback)(async e=>{if(!t)return void d("API configuration is required");o(!0),d(null);try{let i=a||s(t);l(e=>({...e,step:"campaign"}));let n=await i.createCampaign(e.campaign),o=await i.getCampaign(n.id);if(r&&await t5({campaignId:n.id,campaignDetails:o,adAccountId:t.adAccountId,organizationId:r}),l(e=>({...e,campaign:o})),e.abTest){l(e=>({...e,step:"abtest"}));try{let a=r?await (0,Y.Mf)(t.adAccountId,r):null;if(a){let t={...e.abTest,campaigns:[o.id]},n=await i.createABTest(a,t),s=await i.getABTest(n.id);l(e=>({...e,abTest:s}))}}catch(e){console.warn("Failed to create A/B test, continuing with campaign creation:",e)}}l(e=>({...e,step:"creative"}));let d=await i.createAdCreative(e.creative),c=await i.getAdCreative(d.id);l(e=>({...e,adCreative:c}
1)),l(e=>({...e,step:"adset"}));let u={...e.adSet,campaign_id:o.id},m=await i.createAdSet(u),p=await i.getAdSet(m.id);l(e=>({...e,adSet:p})),l(e=>({...e,step:"ad"}));let g={...e.ad,adset_id:p.id,creative:{creative_id:c.id}},h=await i.createAd(g),f=await i.getAd(h.id);l(e=>({...e,ad:f,step:"complete",isLoading:!1}))}catch(e){d(t3(e,"Failed to create full campaign"))}},[t,a,s,r,l,o,d])}}({config:e,apiService:i,actions:u,initializeService:o,organizationId:null==l?void 0:l.id});return{state:t,createCampaign:m,updateCampaign:p,createAdSet:g,createAd:f,createAdCreative:h,createABTest:x,createFullCampaign:b,reset:(0,n.useCallback)(()=>{a(t4)},[]),apiService:i}}(h.accessToken&&h.adAccountId?{accessToken:h.accessToken,adAccountId:h.adAccountId,apiVersion:h.apiVersion}:void 0),x=function(e){let{campaignSettings:t,selectedCampaign:a,isEditingExisting:i,createCampaign:s,updateCampaign:r,apiConfig:l}=e;return{handlePublishCampaign:(0,n.useCallback)(async()=>{if(!l.accessToken||!l.adAccountId)return void(0,$.oR)({title:"No ad account connected",description:"Connect a Meta, TikTok, or Google Ads account in Settings to create campaigns.",variant:"destructive"});if(!t.name.trim())return void(0,$.oR)({title:"Validation Error",description:"Please enter a campaign name",variant:"destructive"});try{if(i&&a){let e=(0,ee.M)(t),i={name:t.name,status:"ACTIVE",...e.bid_strategy&&{bid_strategy:e.bid_strategy},...e.spend_cap&&{spend_cap:e.spend_cap},...e.daily_budget&&{daily_budget:e.daily_budget},...void 0!==e.is_adset_budget_sharing_enabled&&{is_adset_budget_sharing_enabled:e.is_adset_budget_sharing_enabled}};await r(a.id,i)}else{let e=(0,ee.M)(t);await s(e)}}catch(a){console.error("Failed to publish/update campaign:",a);let e=i?"update":"create",t=a instanceof Error?a.message:"Unknown error";(0,$.oR)({title:"Failed to ".concat(e," campaign"),description:t,variant:"destructive"})}},[l,t,i,a,s,r]),canPublishCampaign:(0,n.useCallback)(()=>""!==t.name.trim()&&!!(l.accessToken&&l.adAccountId),[t.name,l])}}({campaignSettings:l.campaignSettings,selectedCampaign:m.selectedCampaign,isEditingExisting:m.isEditingExisting,createCampaign:f.createCampaign,updateCampaign:f.updateCampaign,createABTest:f.createABTest,apiConfig:h.accessToken&&h.adAccountId?{accessToken:h.accessToken,adAccountId:h.adAccountId,apiVersion:h.apiVersion,currency:h.currency}:{accessToken:"",adAccountId:"",apiVersion:h.apiVersion,currency:h.currency}}),b=(0,n.useMemo)(()=>(0,ee.i)({campaignSettings:l.campaignSettings}),[l.campaignSettings]),v=(0,n.useRef)(null);(0,n.useEffect)(()=>{var e;let t=(null==(e=m.selectedCampaign)?void 0:e.id)||null;t!==v.current&&(v.current=t)},[null==(a=m.selectedCampaign)?void 0:a.id]);let{isLoadingAdSetData:y}=function(e){let{selectedAdSet:t,selectedCampaign:a,apiConfig:i,setAdSetDetailsData:s}=e,[r,l]=(0,n.useState)(!1),o=(0,n.useRef)(null),d=(0,n.useRef)(!1);return(0,n.useEffect)(()=>{(async()=>{if(t&&i.accessToken&&i.adAccountId&&o.current!==t.id&&!d.current){d.current=!0,l(!0),aa.Y.log("[useAdSetDataPopulator] Fetching ad set:",t.id);try{var e,n,r,c,u,m,p,g,h,f,x;let l=await fetch("/api/meta/adset/".concat(t.id,"?fields=").concat("id,name,status,campaign_id,targeting,billing_event,optimization_goal,bid_strategy,bid_amount,daily_budget,lifetime_budget,start_time,end_time,attribution_spec,frequency_control_specs,destination_type,promoted_object","&access_token=").concat(i.accessToken));if(!l.ok){let e=await l.json().catch(()=>({}));throw Error(e.error||"Failed to fetch ad set: ".concat(l.status))}let o=await l.json(),d=(0,t9.x$)(o.attribution_spec),b=(e=o.targeting)?{audienceAgeMin:(null==(n=e.age_min)?void 0:n.toString())||"",audienceAgeMax:null==(r=e.age_max)?void 0:r.toString(),audienceGender:(null==(c=e.genders)?void 0:c.length)===2?ef.YT.ALL:(null==(u=e.genders)?void 0:u[0])===1?ef.YT.MEN:ef.YT.WOMEN,targetLocations:(null==(p=e.geo_locations)||null==(m=p.countries)?void 0:m.map(e=>({type:ef.iF.COUNTRY,key:e,name:e,includeExclude:ef.sv.INCLUDE})))||[],languages:(null==(g=e.locales)?void 0:g.map(e=>({id:e,code:e,name:e})))||[],detailedTargeting:(null==(x=e.flexible_spec)||null==(f=x[0])||null==(h=f.interests)?void 0:h.map(e=>
1({id:e.id,name:e.name||e.id})))||[],isAdvantageDetailedTargetingEnabled:!1,isAdvantagePlusAudienceEnabled:!1}:{},v=function(e){if(e.promoted_object){if(e.promoted_object.pixel_id&&!e.promoted_object.application_id)return"WEBSITE";if(e.promoted_object.application_id)return"APP";if(e.promoted_object.page_id&&!e.promoted_object.pixel_id&&!e.promoted_object.application_id)return"FACEBOOK_PAGE"}switch(e.optimization_goal){case"LANDING_PAGE_VIEWS":case"LINK_CLICKS":case"CONVERSIONS":case"THRUPLAY":case"VIDEO_VIEWS":return"WEBSITE";case"APP_INSTALLS":case"APP_ENGAGEMENT":return"APP";case"PAGE_LIKES":case"POST_ENGAGEMENT":return"FACEBOOK_PAGE"}if("IMPRESSIONS"===e.billing_event&&"REACH"!==e.optimization_goal)return"WEBSITE"}(o),y=function(e){if(e)return({WEBSITE:ef.WB.WEBSITE,APP:ef.WB.APP,MESSAGE_DESTINATIONS:ef.WB.MESSENGER,INSTAGRAM_OR_FACEBOOK:ef.WB.INSTAGRAM,FACEBOOK_PAGE:ef.WB.INSTAGRAM,CALLS:ef.WB.CALLS,ON_YOUR_AD:ef.WB.WEBSITE,website:ef.WB.WEBSITE,app:ef.WB.APP,message_destinations:ef.WB.MESSENGER,instagram_or_facebook:ef.WB.INSTAGRAM,facebook_page:ef.WB.INSTAGRAM,calls:ef.WB.CALLS,on_your_ad:ef.WB.WEBSITE})[e]}(v),S=(null==a?void 0:a.objective)?(0,Y.tV)(a.objective):void 0,j=o.optimization_goal?(0,t8.mapMetaAPIToPerformanceGoal)(o.optimization_goal,S,v):null;j||"TRAFFIC"!==S||(j=function(e){if("WEBSITE"===e)return"MAXIMIZE_LANDING_PAGE_VIEWS_TRAFFIC";if("APP"===e);else if("MESSAGE_DESTINATIONS"===e)return"MAXIMIZE_CONVERSATIONS_TRAFFIC";else if("INSTAGRAM"===e||"FACEBOOK_PAGE"===e)return"MAXIMIZE_INSTAGRAM_PROFILE_VISITS_TRAFFIC";else if("CALLS"===e)return"MAXIMIZE_CALLS_TRAFFIC";return"MAXIMIZE_LINK_CLICKS_TRAFFIC"}(v));let A=o.billing_event?function(e){switch(e.toUpperCase()){case"IMPRESSIONS":default:return"impression";case"LINK_CLICKS":return"link_click";case"THRUPLAY":return"thruplay";case"PAGE_LIKES":return"page_like"}}(o.billing_event):null,C=function(e){if(!e)return ef.w7.ADVANTAGE_PLUS;if(e.publisher_platforms&&e.publisher_platforms.length>0){let t=e.publisher_platforms,a=t.includes("facebook")&&t.includes("instagram")&&t.includes("audience_network");return e.facebook_positions||e.instagram_positions||e.messenger_positions||e.audience_network_positions?ef.w7.MANUAL:a?ef.w7.ADVANTAGE_PLUS:ef.w7.MANUAL}return ef.w7.ADVANTAGE_PLUS}(o.targeting),w=C===ef.w7.MANUAL?function(e){if(!e)return{};let t={};return e.publisher_platforms&&e.publisher_platforms.forEach(e=>{t[e]=!0}),e.facebook_positions&&e.facebook_positions.forEach(e=>{t["facebook_".concat(e)]=!0}),e.instagram_positions&&e.instagram_positions.forEach(e=>{t["instagram_".concat(e)]=!0}),e.messenger_positions&&e.messenger_positions.forEach(e=>{t["messenger_".concat(e)]=!0}),e.audience_network_positions&&e.audience_network_positions.forEach(e=>{t["audience_network_".concat(e)]=!0}),t}(o.targeting):{};s(e=>{var t,a,i,n,s,r;return{...e,adSetName:o.name||e.adSetName,budgetType:o.daily_budget?ef.UZ.DAILY:o.lifetime_budget?ef.UZ.LIFETIME:e.budgetType,budgetValue:at(o.daily_budget)||at(o.lifetime_budget)||e.budgetValue,performanceGoal:j||e.performanceGoal,bidCap:o.bid_amount&&"LOWEST_COST_WITH_BID_CAP"===o.bid_strategy?at(o.bid_amount)||e.bidCap||"3.00":e.bidCap||"3.00",trafficChargingMethod:A||e.trafficChargingMethod,scheduleStartDate:ae(o.start_time,"date")||e.scheduleStartDate,scheduleStartTime:ae(o.start_time,"time")||e.scheduleStartTime,scheduleEndDate:ae(o.end_time,"date")||e.scheduleEndDate,scheduleEndTime:ae(o.end_time,"time")||e.scheduleEndTime,setScheduleEndDate:!!o.end_time,scheduleBudgetIncreases:e.scheduleBudgetIncreases,budgetIncreasePeriods:e.budgetIncreasePeriods,facebookPageId:(null==(t=o.promoted_object)?void 0:t.page_id)||e.facebookPageId||"",selectedDatasetId:(null==(a=o.promoted_object)?void 0:a.pixel_id)||e.selectedDatasetId||"",conversionEvent:(null==(n=o.promoted_object)||null==(i=n.custom_event_type)?void 0:i.toLowerCase())||e.conversionEvent,trafficConversionLocation:v||e.trafficConversionLocation,conversionLocation:y||e.conversionLocation,clickThrough:d.clickThrough||e.clickThrough,viewThrough:d.viewThrough||e.viewThrough,engagedView:d.engagedView||e.engagedView,dynamicCreativeEnabled:!0===o.is_dynamic_creative,frequencyControlType:o.frequency_control_specs&&o.frequency_control_specs.length>0||void 0!==o.lifetime_frequency_cap?ef.Cl.CAP:e.frequencyControlType,frequencyValue:o.frequency_control_specs&&o.frequency_control_specs.length>0?(null==(s=o.frequency_control_specs[0])?void 0:s.max_frequency)||e.frequencyValue:void 0!==o.lifetime_frequency_cap?o.lifetime_frequency_cap:e.frequencyValue,frequencyDays:o.frequency_control_specs&&o.frequency_control_specs.length>0?(null==(r=o.frequency_control_specs[0])?void 0:r.interval_days)||e.frequencyDays:void 0!==o.lifetime_frequency_cap_reset_time?o.lifetime_frequency_cap_reset_time:e.frequencyDays,...b,savedAudienceId:e.savedAudienceId,placementType:C,selectedPlacements:w||e.selectedPlacements}})}catch(e){aa.Y.error("[useAdSetDataPopulator] Error fetching detailed ad set data:",e),s(e=>({...e,adSetName:t.name}))}finally{o.current=t.id,d.current=!1,l(!1)}}})()},[t,a,i.accessToken,i.adAccountId,s]),(0,n.useEffect)(()=>{t||(o.current=null)},[t]),{isLoadingAdSetData:r}}({selectedAdSet:m.selectedAdSet,selectedCampaign:m.selectedCampaign,apiConfig:h,setAdSetDetailsData:u.setAdSetDetailsData});!function(e){let{campaignState:t,isPublishingAdSet:a,currentStep:i,setShowSuccessModal:s}=e;(0,n.useEffect)(()=>{!t.campaign||t.isLoading||t.error||a||1!==i||s(!0)},[t.campaign,t.isLoading,t.error,a,i,s])}({campaignState:f.state,isPublishingAdSet:m.isPublishingAdSet,currentStep:r.currentStep,setShowSuccessModal:m.setShowSuccessModal}),function(e){let{trigger:t,duration:a=3e3,zIndex:i=9999}=e;(0,n.useEffect)(()=>
1{if(t){let t=Date.now()+a,n={startVelocity:30,spread:360,ticks:60,zIndex:i};function e(e,t){return Math.random()*(t-e)+e}let s=setInterval(function(){let i=t-Date.now();if(i<=0)return clearInterval(s);let r=i/a*50;(0,ai.A)({...n,particleCount:r,origin:{x:e(.1,.3),y:Math.random()-.2}}),(0,ai.A)({...n,particleCount:r,origin:{x:e(.7,.9),y:Math.random()-.2}})},250);return()=>clearInterval(s)}},[t,a,i])}({trigger:m.showSuccessModal});let S=(null==(i=c.pageSectionsConfig[r.currentStep])?void 0:i.sections)||[],j=(0,n.useMemo)(()=>{var e;return(0,K.OV)(p,{isPhoneCallDestinationSupported:"TRAFFIC"===l.campaignSettings.objective&&"LOWEST_COST"===l.campaignSettings.bidStrategy&&(null==(e=u.adSetDetailsData.trafficConversionLocation)?void 0:e.toUpperCase())==="CALLS"})},[p,u.adSetDetailsData.trafficConversionLocation,l.campaignSettings.bidStrategy,l.campaignSettings.objective]),A=(0,n.useMemo)(()=>{var e;let t=r.currentStep,a=(null==(e=c.pageSectionsConfig[t])?void 0:e.sections)||[];if(t===ec.CAMPAIGN){let e={campaignName:l.campaignSettings.name,specialAdCategories:l.campaignSettings.specialAdCategories,hasSpendingLimit:l.campaignSettings.hasSpendingLimit,spendingLimitAmount:l.campaignSettings.spendingLimitAmount,isAdvantageBudgetEnabled:l.campaignSettings.isAdvantageBudgetEnabled,isAbTestEnabled:l.campaignSettings.isAbTestEnabled,abTestData:l.campaignSettings.abTestData},t=(0,t2.m3)(e);return(0,t2.qr)(1,a,t,null)}if(t===ec.AD_SET){let e=(0,t2.jk)(u.adSetDetailsData,l.campaignSettings.objective,l.campaignSettings.bidStrategy);return(0,t2._o)(a,e,u.adSetDetailsData,l.campaignSettings.objective)}return t===ec.AD?j:r.canGoToNextStep},[r.currentStep,r.canGoToNextStep,c.pageSectionsConfig,l.campaignSettings,u.adSetDetailsData,j]),C=(0,n.useCallback)(e=>{l.loadCampaignSettingsState(e.campaignSettings);let t={...e.adSetDetailsData};u.loadAdSetState(t),g(function(e){var t,a,i;let n=(t=e.selectedCreative)?t:null;return{...e,media:{type:(a=e.media).type,file:null,previewUrl:a.previewUrl,assetId:a.assetId,carouselItems:null==(i=a.carouselItems)?void 0:i.map(e=>({id:e.id,assetId:e.assetId,file:null,previewUrl:e.previewUrl,videoUrl:e.videoUrl,headline:e.headline,description:e.description,url:e.url,isVideo:e.isVideo,imageHash:e.imageHash,videoId:e.videoId})),placementCrops:a.placementCrops},selectedCreative:null!=n?n:void 0}}(e.adDetailsData)),m.loadModalSelectionState(e.selectedCampaign,e.selectedAdSet),r.goToStep(e.currentStep)},[l,u,m,r]),w=(0,n.useCallback)(()=>{m.resetModalState(),l.resetCampaignSettings(),u.resetAdSetData(),g(o.I3),r.goToStep(1)},[m,l,u,r]);return{...r,canGoToNextStep:A,...l,pageSectionsConfig:c.pageSectionsConfig,onPageSettingsSectionsChange:e=>{c.updateSectionsForStep(r.currentStep,e)},currentStepPageSettings:S,...u,isLoadingAdSetData:y,mapBidStrategyFromMetaAPI:e=>e5.xn[e]||"LOWEST_COST",...m,adDetailsData:p,setAdDetailsData:g,apiConfig:h,campaignState:f.state,createCampaign:f.createCampaign,updateCampaign:f.updateCampaign,apiService:f.apiService,resetCampaignState:f.reset,handlePublishCampaign:x.handlePublishCampaign,campaignReviewPayload:b,canPublishOrUpdateCampaign:()=>x.canPublishCampaign()&&m.isStep1Valid,user:e,loadFromDraft:C,resetAllState:w}}(x,o.UT.length),N=(0,t0.O)(),_=function(e){let{currentStep:t,canGoToNextStep:a,canGoToPreviousStep:i,goToNextStep:s,goToPreviousStep:r,goToStep:l,isStepCompleted:o,setShowConfirmationModal:d,setShowAdSetConfirmationModal:c,setShowAdConfirmationModal:u,validateAdSet:m}=e,p=(0,n.useCallback)(()=>{t===ec.AD?a&&u(!0):a&&s()},[a,s,t,u]),g=(0,n.useCallback)(()=>{i&&r()},[i,r]),h=(0,n.useCallback)(e=>{(e<=t||o(e)||e===t+1)&&l(e)},[t,o,l]);return{handleNext:p,handlePrevious:g,handleStepClick:h,handlePublishCampaignClick:(0,n.useCallback)(()=>{d(!0)},[d]),handlePublishAdSetClick:(0,n.useCallback)(()=>{m()&&c(!0)},[m,c])}}({currentStep:w.currentStep,canGoToNextStep:w.canGoToNextStep,canGoToPreviousStep:w.canGoToPreviousStep,goToNextStep:w.goToNextStep,goToPreviousStep:w.goToPreviousStep,goToStep:w.goToStep,isStepCompleted:w.isStepCompleted,setShowConfirmationModal:w.setShowConfirmationModal,setShowAdSetConfirmationModal:w.setShowAdSetConfirmationModal,setShowAdConfirmationModal:w.setShowAdConfirmationModal,validateAdSet:w.validateAdSet}),{loadError:k,retryLoad:E}=function(e){let{isOpen:t,existingCampaignId:a,existingAdSetId:i,existingAdId:s,organizationId:r,setSelectedCampaign:l,setSelectedAdSet:o,setAdSetDetailsData:d,adSetDetailsData:c,setAdDetail
1sData:u,goToStep:m}=e,[p,g]=(0,n.useState)(null),[h,f]=(0,n.useState)(0),x=(0,n.useCallback)(()=>{g(null),f(e=>e+1)},[]);return(0,n.useEffect)(()=>{(async()=>{if(t&&(a||i||s)){aa.Y.log("[useExistingDataLoader] Loading existing data:",{existingCampaignId:a,existingAdSetId:i,existingAdId:s}),g(null);try{if(a){let{data:e,error:t}=await ad("campaign",a,r);if(t){aa.Y.error("[useExistingDataLoader] Error fetching campaign:",t),g(t);return}if(e)if(l(ar(e)),i){let{data:t,error:a}=await ad("ad_set",i,r);a?(aa.Y.error("[useExistingDataLoader] Error fetching ad set:",a),g(a)):t&&(o(al(t)),d(ao(t,e.objective,c)),m(ec.AD_SET))}else m(ec.CAMPAIGN)}else if(i){let{data:e,error:t}=await ad("ad_set",i,r);if(t){aa.Y.error("[useExistingDataLoader] Error fetching ad set:",t),g(t);return}if(null==e?void 0:e.campaign_id){let{data:t,error:a}=await ad("campaign",e.campaign_id,r);a?(aa.Y.error("[useExistingDataLoader] Error fetching campaign for ad set:",a),g(a)):t&&(l(ar(t)),o(al(e)),d(ao(e,t.objective,c)),m(ec.AD_SET))}}if(s){let{data:e,error:t}=await ad("ad",s,r);t?(aa.Y.error("[useExistingDataLoader] Error fetching ad:",t),g(t)):e&&(aa.Y.log("[useExistingDataLoader] Ad data loaded:",e),u(t=>({...t,adName:e.ad_name||"",primaryText:e.primary_text_1||"",primaryTextOptions:[e.primary_text_1,e.primary_text_2,e.primary_text_3,e.primary_text_4,e.primary_text_5].filter(e=>!!e),headline:e.headline_1||"",headlineOptions:[e.headline_1,e.headline_2,e.headline_3,e.headline_4,e.headline_5].filter(e=>!!e),description:e.description_1||"",websiteUrl:e.website_url||"",displayLink:e.display_link||"",callToAction:e.call_to_action_type||"",selectedPageId:e.page_id||"",adFormat:e.ad_format||"single_image_video",media:{...null==t?void 0:t.media,type:"video"===e.media_type?"video":"image",previewUrl:e.image_url||e.thumbnail_url||e.stored_video_thumbnail_url||"",assetId:e.creative_id||""}})),m(ec.AD))}}catch(e){aa.Y.error("[useExistingDataLoader] Error loading existing data:",e),g({message:e instanceof Error?e.message:"Failed to load existing data",code:"LOAD_FAILED"})}}})()},[t,a,i,s,r,h]),{loadError:p,retryLoad:x}}({isOpen:h,existingCampaignId:y,existingAdSetId:S,existingAdId:j,organizationId:null==A?void 0:A.id,setSelectedCampaign:w.setSelectedCampaign,setSelectedAdSet:w.setSelectedAdSet,setAdSetDetailsData:w.setAdSetDetailsData,adSetDetailsData:w.adSetDetailsData,setAdDetailsData:w.setAdDetailsData,goToStep:w.goToStep}),I=(0,n.useRef)(h),[T,D]=(0,n.useState)(!1),[P,O]=(0,n.useState)(null),L=w.apiConfig.adAccountId?"https://business.facebook.com/billing_hub/?asset_id=".concat(encodeURIComponent(w.apiConfig.adAccountId.replace(/^act_/,""))):"https://business.facebook.com/billing_hub/",M=function(e){var t,a,i;let{organizationId:s,isModalOpen:r,currentStep:l,campaignSettings:o,adSetDetailsData:d,adDetailsData:c,selectedCampaign:u,selectedAdSet:m,loadFromDraft:p,autoSaveDelay:g=2e3}=e,[h,f]=(0,n.useState)(!1),[x,b]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),S=(0,n.useRef)(!1),j=(0,n.useRef)(!1),A=am(e=>e.saveDraft),C=am(e=>e.loadDraft),w=am(e=>e.clearDraft);(0,n.useEffect)(()=>{am.persist.rehydrate()},[]),(0,n.useEffect)(()=>{if(r&&s&&!S.current){S.current=!0;let e=C(s);e?(y(e),b(!0)):(y(null),b(!1))}r||(S.current=!1)},[r,s,C]);let N={name:o.name,buyingType:o.buyingType,objective:o.objective,specialAdCategories:o.specialAdCategories,hasSpendingLimit:o.hasSpendingLimit,spendingLimitAmount:o.spendingLimitAmount,isAdvantageBudgetEnabled:o.isAdvantageBudgetEnabled,isAbTestEnabled:o.isAbTestEnabled,bidStrategy:o.bidStrategy,abTestData:o.abTestData},_={...d},k={...c,media:{type:(t=c.media).type,previewUrl:t.previewUrl,assetId:t.assetId,carouselItems:null==(a=t.carouselItems)?void 0:a.slice(0,10).map(e=>({id:e.id,assetId:e.assetId,previewUrl:e.previewUrl,videoUrl:e.videoUrl,headline:e.headline,description:e.description,url:e.url,isVideo:e.isVideo,imageHash:e.imageHash,videoId:e.videoId})),placementCrops:t.placementCrops},selectedCreative:(i=c.selectedCreative)?{id:i.id,name:i.name,url:i.url,videoUrl:i.videoUrl,mimetype:i.mimetype,size:i.size,createdAt:i.createdAt,isVideo:i.isVideo,displayName:i.displayName,creativeId:i.creativeId,folderId:i.folderId}:null},E=JSON.stringify({currentStep:l,campaignSettings:N,adSetDetailsData:_,adDetailsData:k,selectedCampaignId:null==u?void 0:u.id,selectedAdSetId:null==m?void 0:m.id}),I=(0,ap.d)(E,g);(0,n.useEffect)(()=>{r&&s&&!j.current&&(""!==o.name.trim()||null!==u||l>1)&&A({organizationId:s,savedAt:new Date().toISOString(),version:1,
1currentStep:l,campaignSettings:N,adSetDetailsData:_,adDetailsData:k,selectedCampaign:u,selectedAdSet:m})},[I,r,s,A,l,N,_,k,u,m,o.name]);let T=(0,n.useCallback)(()=>{if(v&&s){f(!0),j.current=!0;try{p(v),b(!1),y(null)}catch(e){console.error("Failed to restore draft:",e)}finally{f(!1),setTimeout(()=>{j.current=!1},500)}}},[v,s,p]);return{hasSavedDraft:x,savedDraft:v,restoreDraft:T,clearDraft:(0,n.useCallback)(()=>{s&&(w(s),y(null),b(!1))},[s,w]),isRestoring:h}}({organizationId:null==A?void 0:A.id,isModalOpen:h,currentStep:w.currentStep,campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,adDetailsData:w.adDetailsData,selectedCampaign:w.selectedCampaign,selectedAdSet:w.selectedAdSet,loadFromDraft:w.loadFromDraft});(0,n.useEffect)(()=>{h&&M.hasSavedDraft&&M.savedDraft&&!y&&!S&&!j&&D(!0)},[h,M.hasSavedDraft,M.savedDraft,y,S,j]),(0,n.useEffect)(()=>{I.current=h},[h]);let F=function(e){let{campaignSettings:t,adSetDetailsData:a,selectedCampaign:i,selectedAdSet:s,isEditingExisting:r,createCampaign:l,setSelectedCampaign:o,apiService:d,apiConfig:c,mapAdSetDataToApiFormat:u,setIsPublishingAdSet:m,setPublishedAdSet:p,setShowAdSetConfirmationModal:g,setShowAdSetSuccessModal:h,syncNewEntity:f,organizationId:x,userId:b}=e;return{handlePublishAdSet:(0,n.useCallback)(async()=>{m(!0);let e=null;try{let n;if(s){if(!(n=(null==i?void 0:i.id)||""))throw Error("Campaign ID is required for updating ad set");let e=null!=d?d:await (0,eo.j)(c,x),r=u(a,t,n);await e.updateAdSet(s.id,r);let l={id:s.id,name:r.name,campaign_id:n,status:r.status||"active",budget_amount:0};p(l),g(!1),h(!0);return}if(r&&i)n=i.id;else{if(!t.name.trim())throw Error("Campaign name is required");let a=(0,ee.M)(t);e=n=await l(a)}let m=null!=d?d:await (0,eo.j)(c,x),v=u(a,t,n),y=await m.createAdSet({...v,campaign_id:n,status:v.status||"ACTIVE"});await (0,et.P)({adSetId:y.id,adSetData:v,campaignId:n,adAccountId:c.adAccountId,organizationId:x,userId:b,syncNewEntity:f});let S={id:y.id,name:v.name,campaign_id:n,status:"active",budget_amount:0};if(e){let a={id:e,name:t.name,objective:t.objective,status:ef.BE.ACTIVE,buying_type:t.buyingType||"AUCTION",created_time:new Date().toISOString(),updated_time:new Date().toISOString()};o(a)}(0,eh.Lh)("meta_ad_set_created",{campaign_id:n,ad_set_id:S.id,campaign_objective:t.objective}),p(S),g(!1),h(!0),window.dispatchEvent(new CustomEvent(em))}catch(a){let e=s?"update":"publish",t=a instanceof Error?a.message:"Unknown error";(0,$.oR)({title:"Failed to ".concat(e," ad set"),description:t,variant:"destructive"})}finally{m(!1)}},[t,a,i,s,r,l,o,d,c,u,m,p,g,h,f,x,b])}}({campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,selectedCampaign:w.selectedCampaign,selectedAdSet:w.selectedAdSet,isEditingExisting:w.isEditingExisting,createCampaign:w.createCampaign,setSelectedCampaign:w.setSelectedCampaign,apiService:w.apiService,apiConfig:{accessToken:w.apiConfig.accessToken||"",adAccountId:w.apiConfig.adAccountId||"",organizationId:null==A?void 0:A.id},mapAdSetDataToApiFormat:N.mapAdSetDataToApiFormat,setIsPublishingAdSet:w.setIsPublishingAdSet,setPublishedAdSet:w.setPublishedAdSet,setShowAdSetConfirmationModal:w.setShowAdSetConfirmationModal,setShowAdSetSuccessModal:w.setShowAdSetSuccessModal,syncNewEntity:v,organizationId:null==A?void 0:A.id,userId:null==x?void 0:x.id}),U=(null==(t=w.selectedCampaign)?void 0:t.id)||(null==(a=w.campaignState.campaign)?void 0:a.id)||null,R=(null==(c=w.selectedAdSet)?void 0:c.id)||(null==(u=w.publishedAdSet)?void 0:u.id)||null,B=(0,n.useMemo)(()=>{try{var e;let t=U||(null==(e=w.selectedCampaign)?void 0:e.id)||"pending-campaign",a=N.mapAdSetDataToApiFormat(w.adSetDetailsData,w.campaignSettings,t);return(0,ee.i)({campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,includeCampaignItems:!1,adSetPayload:a})}catch(e){return console.error("[CreateCampaignModal] Failed to map ad set settings for review",e),{...(0,ee.i)({campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,includeCampaignItems:!1}),mappingError:e instanceof Error?e.message:"Failed to map ad set settings to the publish payload"}}}
1,[N,w.adSetDetailsData,w.campaignSettings,null==(m=w.selectedCampaign)?void 0:m.id,U]),V=(0,n.useMemo)(()=>{var e;let t=null==(e=w.adDetailsData.selectedCreative)?void 0:e.id,a=t&&/^\d+$/.test(t)?t:void 0;return(0,ee.i)({campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,adDetailsData:w.adDetailsData,includeCampaignItems:!1,...a?{adPayload:{creative:{creative_id:a}}}:{}})},[w.adDetailsData,w.adSetDetailsData,w.campaignSettings]),G=function(e){let{campaignSettings:t,adSetDetailsData:a,adDetailsData:i,campaignId:s,adSetId:r,apiService:l,apiConfig:o,connectedPages:c,setIsPublishingAd:u,setPublishedAd:m,setShowAdConfirmationModal:p,onPublishStarted:g,onBillingPaymentError:h,createCampaign:f,mapAdSetDataToApiFormat:x,setSelectedCampaign:b,setPublishedAdSet:v,syncNewEntity:y,organizationId:S,userId:j}=e;return{handlePublishAd:(0,n.useCallback)(async()=>{u(!0),p(!1);let e=W.oR.loading("Publishing ad...",{description:"You can keep working while Meta finishes creating the ad.",duration:1/0});null==g||g();let n=s,A=r;try{if(!i.adName.trim())throw Error("Ad name is required");if(!o.accessToken||!o.adAccountId)throw Error("API configuration is required");!function(e,t,a,i){var n,s,r,l,o,c,u,m;let p="use_existing_post"===e.adCreationType,g="TRAFFIC"===a&&"LOWEST_COST"===i&&((null==t||null==(n=t.trafficConversionLocation)?void 0:n.toUpperCase())==="CALLS"||(null==t||null==(s=t.conversionLocation)?void 0:s.toUpperCase())==="CALLS");if(p&&!(null==(r=e.existingPostId)?void 0:r.trim()))throw Error("An existing post ID is required to publish an existing post ad.");if(p)return;if(e.multiAdvertiserAdsEnabled)throw Error("Multi-advertiser ads are not available for interactive publish yet because the Meta enrollment field is not wired.");if(e.partnershipAdEnabled)throw Error("Partnership ads are not available for interactive publish yet because the Meta partnership payload is not wired.");if("collection"===e.adFormat)throw Error("Collection ads are not available for interactive Meta publish yet because the Instant Experience payload is not wired.");if(g&&"carousel"===e.adFormat)throw Error("Carousel ads are not available for Meta traffic call ads yet.");if("carousel"===e.adFormat){let t=null!=(u=null==(c=e.media)?void 0:c.carouselItems)?u:[];if(t.length<2)throw Error("Carousel ads require at least 2 cards before publishing.");if(t.some(e=>e.isVideo&&!(0,K.KT)(e)))throw Error("Carousel video cards require a video source and thumbnail image hash before publishing.");let a=X(e.websiteUrl||e.destinationUrl);if(t.some(e=>{var t;return!!(null==(t=e.url)?void 0:t.trim())&&!X(e.url)}))throw Error("Carousel card links must be valid http or https URLs before publishing.");let i=t.every(e=>X(e.url));if(!a&&!i)throw Error("Carousel ads require a website URL or a valid link on every card before publishing.")}if(g&&"phone_call"!==e.destinationType)throw Error("Traffic call ads require the phone call destination before publishing.");if(e.destinationType&&"website"!==e.destinationType&&!("phone_call"===e.destinationType&&g))throw Error("Only website destinations are currently supported for interactive Meta publish.");if("phone_call"===e.destinationType&&!(0,d.YD)(e))throw Error("A phone number with country code is required to publish a Meta call ad.");if(!(0,Z.ix)(e.callToAction))throw Error("The selected Meta call-to-action is not available for publishing.");if(!(e.selectedPageId||(null==t?void 0:t.facebookPageId)))throw Error("A Facebook Page is required to publish an ad. Please select a page in the Ad Set or Ad details.");let h=e.websiteUrl||e.destinationUrl;if("carousel"!==e.adFormat&&!g&&!X(h))throw Error("A website URL is required. Please enter a valid destination URL for your ad.");if(null==(l=e.displayLink)?void 0:l.trim())throw Error("Display links are not available for interactive Meta publish yet because the display URL payload is not wired.");if(e.browserAddOn&&"none"!==e.browserAddOn)throw Error("Browser add-ons are not available for interactive Meta publish yet because the call extension payload is not wired.");if(!0===e.trackWebsiteEvents||!0===e.trackAppEvents||!0===e.trackOfflineEvents||(null!=(m=null==(o=e.trackingPixels)?void 0:o.length)?m:0)>0)throw Error("Tracking controls beyond URL parameters are not available for interactive publish yet.")}(i,a,eg(t.objective),t.bidStrategy),(0,ep.qH)({objective:eg(t.objective),conversionLocation:a.trafficConversionLocation||a.conversionLocation,performanceGoal:a.performanceGoal,selectedPageId:i.selectedPageId||a.facebookPageId||a.trafficMessagePageId,selectedDatasetId:a.selectedDatasetId,selectedDatasetMetadata:(0,ed.FB)(a),...function(e){var t,a,i,n,s;let r=e.selectedCreative,l=null==r?void 0:r.previewUrl,o=null!=(s=null==(t=e.media)?void 0:t.carouselItems)?s:[],d=!!((null==r?void 0:r.isVideo)||(null==r?void 0:r.videoUrl)||(null==r||null==(a=r.mimetype)?void 0:a.startsWith("video/"))),c=!!((null==(i=e.media)?void 0:i.type)==="image"&&(e.media.file||e.media.assetId||e.media.previewUrl)||r&&!d&&(r.url||l||r.id)||o.some(e=>!!e.imageHash||!e.isVideo&&!!(e.file||e.previewUrl))),u=!!((null==(n=e.media)?void 0:n.type)==="video"&&e.media.file||r&&d&&(r.videoUrl||r.url||r.id)||o.some(e=>e.isVideo&&!!(e.videoId||e.videoUrl||e.file)));return{hasImageAsset:c,hasVideoAsset:u,existingCreativeId:(null==r?void 0:r.id)&&/^\d+$/.test(r.id)?null==r?void 0:r.id:void 0,existingPostId:e.existingPostId}}(i),leadFormId:i.leadFormId,phoneNumber:i.phoneNumber,appId:a.trafficAppId,appStoreUrl:a.appStoreUrl,bidStrategy:t.bidStrategy,adFormat:function(e){if(e)return"single_image"===e||"single_video"===e?"single_image_video":e}(i.adFormat)});let s=null!=l?l:await (0,eo.j)(o,S);n=await ei({campaignId:n,campaignSettings:t,createCampaign:f,setSelectedCampaign:b}),A=await en({adSetId:A,campaignId:n,apiService:s,adSetDetailsData:a,campaignSettings:t,mapAdSetDataToApiFormat:
1x,apiConfig:o,organizationId:S,userId:j,syncNewEntity:y,setPublishedAdSet:v});let{creativeResult:r,isCarousel:u,isVideo:p}=await es({apiService:s,adDetailsData:i,adSetDetailsData:a}),g=await s.createAd({name:i.adName,adset_id:A,creative:{creative_id:r.creativeId},status:"ACTIVE"});await er({adResult:g,adDetailsData:i,adSetDetailsData:a,adSetId:A,campaignId:n,creativeResult:r,isCarousel:u,isVideo:p,apiConfig:o,connectedPages:c,syncNewEntity:y});let h={id:g.id,name:i.adName,adset_id:A,campaign_id:n,creative_id:r.creativeId,status:"ACTIVE"};m(h),W.oR.dismiss(e),W.oR.success("Ad published",{description:"Your ad is live in Ads Manager.",duration:2e3}),window.dispatchEvent(new CustomEvent(em)),el("meta.ad_published",g.id,{campaignId:n,adSetId:A,adId:g.id},S)}catch(a){let t=(0,d.PE)(a);throw W.oR.dismiss(e),el("meta.ad_publish_failed","unknown",{error:t},S),(0,d.kZ)(t)&&h?(p(!1),h(t)):(0,$.oR)({title:"Failed to publish ad",description:t,variant:"destructive"}),u(!1),Error(t)}finally{u(!1)}},[s,r,t,i,a,l,o,u,m,p,g,h,c,f,x,b,v,y,S,j])}}({campaignSettings:w.campaignSettings,adSetDetailsData:w.adSetDetailsData,adDetailsData:w.adDetailsData,campaignId:U,adSetId:R,apiService:w.apiService,apiConfig:{accessToken:w.apiConfig.accessToken||"",adAccountId:w.apiConfig.adAccountId||""},connectedPages:C||[],setIsPublishingAd:w.setIsPublishingAd,setPublishedAd:w.setPublishedAd,setShowAdConfirmationModal:w.setShowAdConfirmationModal,setShowAdSuccessModal:w.setShowAdSuccessModal,onPublishStarted:()=>f(!1),onBillingPaymentError:O,createCampaign:w.createCampaign,mapAdSetDataToApiFormat:N.mapAdSetDataToApiFormat,setSelectedCampaign:w.setSelectedCampaign,setPublishedAdSet:w.setPublishedAdSet,syncNewEntity:v,organizationId:null==A?void 0:A.id,userId:null==x?void 0:x.id}),{handleCloseSuccessModal:z,handleCloseAdSetSuccessModal:q,handleCloseAdSuccessModal:H}=function(e){let{modalState:t,syncNewEntity:a,onSuccess:i,onOpenChange:n,clearDraft:s}=e;return{handleCloseSuccessModal:async()=>{var e;t.setShowSuccessModal(!1),(null==(e=t.campaignState.campaign)?void 0:e.id)&&a&&(await a("campaign",t.campaignState.campaign.id),await new Promise(e=>setTimeout(e,500))),t.resetCampaignState(),t.isEditingExisting||(t.resetCampaignSettings(),t.setSelectedCampaign(null)),null==s||s(),i&&i()},handleCloseAdSetSuccessModal:async()=>{var e;t.setShowAdSetSuccessModal(!1),(null==(e=t.publishedAdSet)?void 0:e.id)&&a&&(await a("ad_set",t.publishedAdSet.id),await new Promise(e=>setTimeout(e,500))),t.setPublishedAdSet(null),t.selectedAdSet||(t.resetAdSetData(),t.isEditingExisting||t.selectedCampaign||t.resetCampaignSettings(),t.setSelectedAdSet(null)),null==s||s(),i&&i()},handleCloseAdSuccessModal:async()=>{var e;t.setShowAdSuccessModal(!1),(null==(e=t.publishedAd)?void 0:e.id)&&a&&(await a("ad",t.publishedAd.id),await new Promise(e=>setTimeout(e,500))),t.setPublishedAd(null);let r=eG.d4.getState();r.resetAd(),r.resetAdSet(),r.resetCampaign(),null==s||s(),i&&i(),n(!1)}}}({modalState:w,syncNewEntity:v,onSuccess:b,onOpenChange:f,clearDraft:M.clearDraft});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(tV,{isOpen:h,onOpenChange:f,currentStep:w.currentStep,loadError:k,onRetryLoad:E,user:w.user,onStepClick:_.handleStepClick,isStepCompleted:w.isStepCompleted,isPageSettingsOpen:w.isPageSettingsOpen,setIsPageSettingsOpen:w.setIsPageSettingsOpen,currentStepPageSettings:w.currentStepPageSettings,onPageSettingsSectionsChange:w.onPageSettingsSectionsChange,campaignSettings:{...w.campaignSettings,abTestData:null!=(g=w.campaignSettings.abTestData)?g:void 0},setCampaignNameCallback:w.setCampaignNameCallback,handleBuyingTypeChangeCallback:w.handleBuyingTypeChangeCallback,setCampaignObjectiveCallback:w.setCampaignObjectiveCallback,displayedObjectives:w.displayedObjectives||[],selectedObjectiveDetails:w.selectedObjectiveDetails,setSpecialAdCategoriesCallback:w.setSpecialAdCategoriesCallback,setHasSpendingLimitCallback:w.setHasSpendingLimitCallback,onSpendingLimitAmountChange:w.setSpendingLimitAmountCallback,setIsAdvantageBudgetEnabledCallback:w.setIsAdvantageBudgetEnabledCallback,setIsAbTestEnabledCallback:w.setIsAbTestEnabledCallback,setCampaignBidStrategyCallback:w.setCampaignBidStrategyCallback,setAbTestDataCallback:e=>w.setAbTestDataCallback(e),adSetDetailsData:w.adSetDetailsData,setAdSetDetailsData:w.setAdSetDetailsData,adDetailsData:w.adDetailsData,setAdDetail
1sData:w.setAdDetailsData,accessToken:w.apiConfig.accessToken||"",adAccountId:w.apiConfig.adAccountId||"",currency:w.apiConfig.currency,selectedCampaign:w.selectedCampaign,onCampaignSelect:w.setSelectedCampaign,selectedAdSet:w.selectedAdSet,onAdSetSelect:w.setSelectedAdSet,isEditingExisting:w.isEditingExisting,onValidationChange:w.setIsStep1Valid,sectionValidation:w.sectionValidation,canGoToPreviousStep:w.canGoToPreviousStep,canGoToNextStep:w.canGoToNextStep,canPublishCampaign:w.canPublishOrUpdateCampaign(),canPublishAdSet:w.canPublishAdSet(w.currentStep),isLoading:w.campaignState.isLoading,isPublishingAdSet:w.isPublishingAdSet,onPrevious:_.handlePrevious,onNext:_.handleNext,onPublishCampaign:_.handlePublishCampaignClick,onPublishAdSet:_.handlePublishAdSetClick,connectedPages:C,publishedCampaignId:null==(p=w.campaignState.campaign)?void 0:p.id,organizationId:null==A?void 0:A.id}),(0,i.jsx)(tX,{showSuccessModal:w.showSuccessModal,onCloseSuccessModal:z,campaign:w.campaignState.campaign,selectedObjectiveDetails:w.selectedObjectiveDetails,showConfirmationModal:w.showConfirmationModal,setShowConfirmationModal:w.setShowConfirmationModal,onConfirmPublishCampaign:w.handlePublishCampaign,isCampaignLoading:w.campaignState.isLoading,campaignReviewPayload:w.campaignReviewPayload,showAdSetConfirmationModal:w.showAdSetConfirmationModal,setShowAdSetConfirmationModal:w.setShowAdSetConfirmationModal,onConfirmPublishAdSet:F.handlePublishAdSet,isPublishingAdSet:w.isPublishingAdSet,selectedAdSet:w.selectedAdSet,adSetReviewPayload:B,showAdSetSuccessModal:w.showAdSetSuccessModal,onCloseAdSetSuccessModal:q,publishedAdSet:w.publishedAdSet,campaignName:w.campaignSettings.name||"Campaign Name",showAdConfirmationModal:w.showAdConfirmationModal,setShowAdConfirmationModal:w.setShowAdConfirmationModal,onConfirmPublishAd:G.handlePublishAd,isPublishingAd:w.isPublishingAd,adReviewPayload:V,showAdSuccessModal:w.showAdSuccessModal,onCloseAdSuccessModal:H,publishedAd:w.publishedAd,adSetName:w.adSetDetailsData.adSetName||"Ad Set",adBillingErrorMessage:P,onCloseAdBillingError:()=>O(null),billingCenterUrl:L}),M.savedDraft&&(0,i.jsx)(tQ,{open:T,onOpenChange:D,draft:M.savedDraft,onContinue:()=>{M.restoreDraft()},onStartFresh:()=>{M.clearDraft(),w.resetAllState()}})]})}},7125:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]])},15239:(e,t,a)=>{a.d(t,{default:()=>n.a});var i=a(54652),n=a.n(i)},15870:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]])},21786:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]])},26989:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("settings-2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]])},38392:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]])},40583:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]])},42196:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]])},52099:(e,t,a)=>{a.d(t,{Lh:()=>m,Ml:()=>d,Vz:()=>o,bR:()=>c,ur:()=>u});let i=null,n=!1,s=!0;
1function r(){return i||(i=a.e(8229).then(a.bind(a,26614)).then(e=>{var t;return null!=(t=e.default)?t:e}).catch(()=>null)),i}function l(e){try{var t,a,i,n;s?(null==(t=e.opt_in_capturing)||t.call(e),null==(a=e.startSessionRecording)||a.call(e)):(null==(i=e.stopSessionRecording)||i.call(e),null==(n=e.opt_out_capturing)||n.call(e))}catch(e){}}function o(){let e="phc_pWPmFKrvRjMdKtUaMmsRGGa5ZxqD4YHaVSwTSVZWxMEj";e&&r().then(t=>{if(t)try{n||(t.init(e,{api_host:"https://us.i.posthog.com",person_profiles:"identified_only",autocapture:!0,capture_pageview:!0,session_recording:{maskAllInputs:!0,maskTextSelector:"[data-ph-mask], [data-ph-mask] *"}}),n=!0),l(t)}catch(e){}})}function d(e){s=e,n&&r().then(e=>{e&&l(e)})}function c(e){let{id:t,organization_id:a}=e;t&&r().then(e=>{if(e&&n)try{if(e.identify(t,a?{organization_id:a}:void 0),a){var i;null==(i=e.group)||i.call(e,"organization",a)}}catch(e){}})}function u(){n&&r().then(e=>{if(e)try{e.reset()}catch(e){}})}function m(e,t){r().then(a=>{if(a&&n)try{a.capture(e,t)}catch(e){}})}},54652:(e,t,a)=>{Object.defineProperty(t,"__esModule",{value:!0}),!function(e,t){for(var a in t)Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}(t,{default:function(){return o},getImageProps:function(){return l}});let i=a(28140),n=a(75040),s=a(81356),r=i._(a(71124));function l(e){let{props:t}=(0,n.getImgProps)(e,{defaultLoader:r.default,imgConf:{deviceSizes:[640,750,828,1080,1200,1920,2048,3840],imageSizes:[16,32,48,64,96,128,256,384],path:"/_next/image",loader:"default",dangerouslyAllowSVG:!0,unoptimized:!1}});for(let[e,a]of Object.entries(t))void 0===a&&delete t[e];return{props:t}}let o=s.Image},69065:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},74054:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("chevrons-up-down",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]])},78519:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("credit-card",[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]])},78874:(e,t,a)=>{a.d(t,{A:()=>i});let i=(0,a(71847).A)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]])}}]);

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.