import{b as t,g as u}from"./state.B1AUjM8Q.js";import{c as f}from"./modal-manager.Cg_dcz_T.js";import{c as m}from"./ui-helpers.EB085fFg.js";function p(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}function w(e){const i=jQuery;if(!t.modal||t.modal.length===0)return;i(".saai-result-field").removeClass("show");const n=e.alt||e.alt_text;n&&(t.modal.find(".saai-alt-text").text(n),i('.saai-result-field[data-field="alt"]').addClass("show")),e.caption&&(t.modal.find(".saai-caption").text(e.caption),i('.saai-result-field[data-field="caption"]').addClass("show")),e.title&&(t.modal.find(".saai-title").text(e.title),i('.saai-result-field[data-field="title"]').addClass("show")),e.description&&(t.modal.find(".saai-description").text(e.description),i('.saai-result-field[data-field="description"]').addClass("show")),t.results&&t.results.show(),t.generateButton&&t.generateButton.hide(),t.saveButton&&t.saveButton.show()}function y(){if(jQuery,!t.modal||t.modal.length===0)return;const e=t.modal.find(".saai-alt-text").text().trim(),i=t.modal.find(".saai-caption").text().trim(),n=t.modal.find(".saai-title").text().trim(),r=t.modal.find(".saai-description").text().trim();h(e,i,n,r),f(),m("Image details updated successfully!")}function h(e,i,n,r){var d,o;jQuery;let a=!1;const s=(o=(d=window.wp)==null?void 0:d.media)==null?void 0:o.frame;if(s&&s.state()){const g=s.state().get("selection");if(g&&g.first()){const l=g.first();e&&(l.set("alt",e),a=!0),i&&(l.set("caption",i),a=!0),n&&(l.set("title",n),a=!0),r&&(l.set("description",r),a=!0),a&&l.save().done(()=>{c(e,i,n,r)});return}}c(e,i,n,r)}function c(e,i,n,r){const a=jQuery,s=u();e&&(a('span.setting[data-setting="alt"] input').val(e).trigger("input").trigger("change"),a('span.setting[data-setting="alt"] textarea').val(e).trigger("input").trigger("change"),a('.compat-field-image_alt textarea, input[name="attachments['+s+'][image_alt]"]').val(e).trigger("input").trigger("change"),a("#attachment_alt").val(e).trigger("input").trigger("change"),t.modal&&t.modal.length>0&&t.modal.find(".saai-current-field:nth-child(1) .saai-current-value").text(e)),i&&(a('span.setting[data-setting="caption"] textarea').val(i).trigger("input").trigger("change"),a('input[name="attachments['+s+'][post_excerpt]"]').val(i).trigger("input").trigger("change"),a("#attachment_caption").val(i).trigger("input").trigger("change"),t.modal&&t.modal.length>0&&t.modal.find(".saai-current-field:nth-child(2) .saai-current-value").text(i)),n&&(a('span.setting[data-setting="title"] input').val(n).trigger("input").trigger("change"),a('input[name="attachments['+s+'][post_title]"]').val(n).trigger("input").trigger("change"),a('#attachment_post_title, input[name="post_title"]').val(n).trigger("input").trigger("change"),t.modal&&t.modal.length>0&&t.modal.find(".saai-current-field:nth-child(3) .saai-current-value").text(n)),r&&(a('span.setting[data-setting="description"] textarea').val(r).trigger("input").trigger("change"),a('textarea[name="attachments['+s+'][post_content]"]').val(r).trigger("input").trigger("change"),a("#attachment_content, #content").val(r).trigger("input").trigger("change"),t.modal&&t.modal.length>0&&t.modal.find(".saai-current-field:nth-child(4) .saai-current-value").text(r))}export{p as __vite_legacy_guard,w as a,y as s};
