import{g as l,b as e}from"./state.B1AUjM8Q.js";import{b as r,a as n,u as o}from"./ui-helpers.EB085fFg.js";function p(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}function _(){const t=jQuery;l()&&m().then(()=>{e.modal=t("#saai-image-alt-tags-modal"),c()}).catch(a=>{console.error("Failed to load form data:",a),r("Failed to load image data. Please try again.")})}function F(){e.modal&&e.modal.length>0&&(e.modal.hide(),s())}function c(){e.modal&&e.modal.length>0&&(e.modal.show(),n(),o())}function s(){!e.modal||e.modal.length===0||(e.loading&&e.loading.hide(),e.results&&e.results.hide(),e.error&&e.error.hide(),e.generateButton&&e.generateButton.show(),e.saveButton&&e.saveButton.hide(),u(),e.modal.find('input[name="generate_alt"]').prop("checked",e.defaultFields.includes("alt")),e.modal.find('input[name="generate_caption"]').prop("checked",e.defaultFields.includes("caption")),e.modal.find('input[name="generate_title"]').prop("checked",e.defaultFields.includes("title")),e.modal.find('input[name="generate_description"]').prop("checked",e.defaultFields.includes("description")),n())}function u(){!e.modal||e.modal.length===0||e.modal.find(".saai-alt-text, .saai-caption, .saai-title, .saai-description").text("")}function m(){const t=jQuery;return new Promise((a,d)=>{t.ajax({url:"".concat(e.restUrl,"form?attachment_id=").concat(l()),method:"GET",headers:{"X-WP-Nonce":e.nonce}}).done(i=>{f(i),a()}).fail(i=>{d(new Error("HTTP error! status: ".concat(i.status)))})})}function f(t){if(!e.modal||e.modal.length===0)return;const a=e.modal.find(".saai-image-preview img");a.length&&t.image_url&&(a.attr("src",t.image_url),a.attr("alt",t.current_alt||"")),e.modal.find(".saai-current-field-alt .saai-current-value").text(t.current_alt||"None"),e.modal.find(".saai-current-field-caption .saai-current-value").text(t.caption||"None"),e.modal.find(".saai-current-field-title .saai-current-value").text(t.title||"None"),e.modal.find(".saai-current-field-description .saai-current-value").text(t.description||"None"),e.modal.find('input[name="generate_alt"]').prop("checked",e.defaultFields.includes("alt")),e.modal.find('input[name="generate_caption"]').prop("checked",e.defaultFields.includes("caption")),e.modal.find('input[name="generate_title"]').prop("checked",e.defaultFields.includes("title")),e.modal.find('input[name="generate_description"]').prop("checked",e.defaultFields.includes("description")),n(),o()}export{p as __vite_legacy_guard,F as c,_ as o};
