System.register(["./state-legacy.BfeTROjz.js","./ui-helpers-legacy.DZ1NznsM.js","./field-updater-legacy.CGuGhQjx.js","../../../common/credit-toast-legacy.BMoKCCCk.js","./modal-manager-legacy.BN0zLM7v.js","../../../common/index-legacy.sLMPZLm9.js","../../../common/modal-legacy.DcruUX9x.js"],(function(e,t){"use strict";var n,a,r,i,o,l,c,d,g;return{setters:[e=>{n=e.g,a=e.b,r=e.c},e=>{i=e.s,o=e.b,l=e.h},e=>{c=e.a},e=>{d=e.c,g=e.s},null,null,null],execute:function(){e("g",(function(){if(!d())return;const e=jQuery,t=function(){if(!a.modal||0===a.modal.length)return{generate_alt:!1,generate_caption:!1,generate_title:!1,generate_description:!1};const e=a.modal.find('input[name="generate_alt"]:checked'),t=a.modal.find('input[name="generate_caption"]:checked'),n=a.modal.find('input[name="generate_title"]:checked'),r=a.modal.find('input[name="generate_description"]:checked');return{generate_alt:e.length>0,generate_caption:t.length>0,generate_title:n.length>0,generate_description:r.length>0}}();if(!function(e){return!!(e.generate_alt||e.generate_caption||e.generate_title||e.generate_description)||(o("Please select at least one option to generate."),!1)}(t))return;i();const s={attachment_id:n().toString(),generate_alt:t.generate_alt.toString(),generate_caption:t.generate_caption.toString(),generate_title:t.generate_title.toString(),generate_description:t.generate_description.toString()},u=r();u&&(s.post_context=u),t.generate_alt&&(s.current_alt=function(){if(!a.modal||0===a.modal.length)return"";const e=a.modal.find(".saai-current-field:nth-child(1) .saai-current-value").text().trim();return"None"===e?"":e}()),t.generate_caption&&(s.current_caption=function(){if(!a.modal||0===a.modal.length)return"";const e=a.modal.find(".saai-current-field:nth-child(2) .saai-current-value").text().trim();return"None"===e?"":e}()),t.generate_title&&(s.current_title=a.modal&&0!==a.modal.length?a.modal.find(".saai-current-field:nth-child(3) .saai-current-value").text().trim():""),t.generate_description&&(s.current_description=function(){if(!a.modal||0===a.modal.length)return"";const e=a.modal.find(".saai-current-field:nth-child(4) .saai-current-value").text().trim();return"None"===e?"":e}()),e.ajax({url:a.restUrl,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":a.nonce},data:s}).done((e=>{if(!e.success)throw new Error("Generation failed");c(e.data),e.usage&&g(e.usage)})).fail((e=>{console.error("Generation error:",e),o("Failed to generate alt tags. Please try again.")})).always((()=>{l()}))}))}}}));
