!function(){"use strict";window.aipkit_chatUI_handleImageGeneration=function(e,i,n,t,a){let{state:o,elements:d,config:s,setButtonStateAction:r,handleError:c,focusInputAction:p}=a,{inputField:g,voiceInputButton:m,messagesEl:I,container:_}=d;o.isSending=!0,g.disabled=!0,m&&(m.disabled=!0),r("sending",!0,o);let w=null;"function"==typeof window.aipkit_chatUI_showImageLoadingIndicator?w=window.aipkit_chatUI_showImageLoadingIndicator(I,s):"function"==typeof window.aipkit_chatUI_showTypingIndicator&&window.aipkit_chatUI_showTypingIndicator(I,s);let l={prompt:e,original_user_text:i,user_message_id:n};if("function"!=typeof window.aipkit_frontendApiRequest)return c("Internal script error (image gen).",!1,!0),"function"==typeof window.aipkit_chatUI_removeImageLoadingIndicator&&window.aipkit_chatUI_removeImageLoadingIndicator(I,w),o.isSending=!1,g.disabled=s.requireConsentCompliance&&!o.consentGiven,m&&(m.disabled=s.requireConsentCompliance&&!o.consentGiven),r("send",!1,o),void((!s.requireConsentCompliance||o.consentGiven)&&p());window.aipkit_frontendApiRequest("aipkit_chat_generate_image",l,s).then(i=>{if("function"==typeof window.aipkit_chatUI_removeImageLoadingIndicator?window.aipkit_chatUI_removeImageLoadingIndicator(I,w):"function"==typeof window.aipkit_chatUI_removeTypingIndicator&&window.aipkit_chatUI_removeTypingIndicator(I),"image"===i?.type&&i.images&&i.images.length>0){let n={type:"image",images:i.images,prompt:e};window.aipkit_chatUI_appendMessage(I,n,"bot",s,!1,!1,i.message_id,!0),_&&_.dispatchEvent(new CustomEvent("aipkit:messageReceived",{detail:{messageId:i.message_id,conversationUUID:window.aipkit_current_conversation_uuid,newConversation:t}}))}else c(`Image generation failed: ${i?.message||"Invalid response for image generation (no images)."}`,!1,!0)}).catch(e=>{"function"==typeof window.aipkit_chatUI_removeImageLoadingIndicator?window.aipkit_chatUI_removeImageLoadingIndicator(I,w):"function"==typeof window.aipkit_chatUI_removeTypingIndicator&&window.aipkit_chatUI_removeTypingIndicator(I),c("Image generation failed: "+(e.message||"Unknown error"),!1,!0)}).finally(()=>{o.isSending=!1,g.disabled=s.requireConsentCompliance&&!o.consentGiven,m&&(m.disabled=s.requireConsentCompliance&&!o.consentGiven),r("send",!1,o),(!s.requireConsentCompliance||o.consentGiven)&&p()})}}();