import{g as l,b as e,c}from"./state.B1AUjM8Q.js";import{s,b as o,h as g}from"./ui-helpers.EB085fFg.js";import{a as d}from"./field-updater.CG-zcKt8.js";import{c as u,s as f}from"../../../common/credit-toast.DauYY3RS.js";import"./modal-manager.Cg_dcz_T.js";import"../../../common/index.CPcBO1Os.js";import"../../../common/modal.BiaPupKG.js";function v(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}function N(){if(!u())return;const t=jQuery,n=m();if(!p(n))return;s();const a={attachment_id:l().toString(),generate_alt:n.generate_alt.toString(),generate_caption:n.generate_caption.toString(),generate_title:n.generate_title.toString(),generate_description:n.generate_description.toString()},i=c();i&&(a.post_context=i),n.generate_alt&&(a.current_alt=_()),n.generate_caption&&(a.current_caption=h()),n.generate_title&&(a.current_title=x()),n.generate_description&&(a.current_description=C()),t.ajax({url:e.restUrl,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":e.nonce},data:a}).done(r=>{if(r.success)d(r.data),r.usage&&f(r.usage);else throw new Error("Generation failed")}).fail(r=>{console.error("Generation error:",r),o("Failed to generate alt tags. Please try again.")}).always(()=>{g()})}function m(){if(!e.modal||e.modal.length===0)return{generate_alt:!1,generate_caption:!1,generate_title:!1,generate_description:!1};const t=e.modal.find('input[name="generate_alt"]:checked'),n=e.modal.find('input[name="generate_caption"]:checked'),a=e.modal.find('input[name="generate_title"]:checked'),i=e.modal.find('input[name="generate_description"]:checked');return{generate_alt:t.length>0,generate_caption:n.length>0,generate_title:a.length>0,generate_description:i.length>0}}function p(t){return!t.generate_alt&&!t.generate_caption&&!t.generate_title&&!t.generate_description?(o("Please select at least one option to generate."),!1):!0}function _(){if(!e.modal||e.modal.length===0)return"";const t=e.modal.find(".saai-current-field:nth-child(1) .saai-current-value").text().trim();return t==="None"?"":t}function h(){if(!e.modal||e.modal.length===0)return"";const t=e.modal.find(".saai-current-field:nth-child(2) .saai-current-value").text().trim();return t==="None"?"":t}function x(){return!e.modal||e.modal.length===0?"":e.modal.find(".saai-current-field:nth-child(3) .saai-current-value").text().trim()}function C(){if(!e.modal||e.modal.length===0)return"";const t=e.modal.find(".saai-current-field:nth-child(4) .saai-current-value").text().trim();return t==="None"?"":t}export{v as __vite_legacy_guard,N as g};
