(()=>{"use strict";const e=window.wp.blockEditor,t=window.wp.blocks,r=window.wp.components,a=window.wp.data,o=window.wp.i18n,c=window.ReactJSXRuntime;(0,t.registerBlockType)("orbem/paragraph-mp3",{title:(0,o.__)("Paragraph with MP3","custom"),description:(0,o.__)("A paragraph block with an MP3 upload option.","custom"),category:"orbem-order-studio",icon:"media-audio",supports:{html:!1},attributes:{content:{type:"string",source:"html",selector:"p"},mp3Url:{type:"string",default:""},selectedCharacter:{type:"number",default:null},selectedVoice:{type:"string",default:""},triggerPath:{type:"boolean",default:!1}},edit:({attributes:t,setAttributes:l})=>{const s=(0,a.useSelect)((e=>e("core").getEntityRecords("postType","explore-character",{per_page:-1})),[]),{content:n,mp3Url:i,selectedCharacter:d,selectedVoice:p}=t,u=(h=d,(0,a.useSelect)((e=>{const t=e("core").getEntityRecord("postType","explore-character",h)?.meta;return t?t["explore-voice"]:null}),[h]));var h;return p===u&&null!=p||l({selectedVoice:u}),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(e.InspectorControls,{children:[(0,c.jsxs)(r.PanelBody,{title:(0,o.__)("MP3 File","custom"),children:[(0,c.jsx)(e.MediaUploadCheck,{children:(0,c.jsx)(e.MediaUpload,{onSelect:e=>l({mp3Url:e.url}),allowedTypes:["audio"],render:({open:e})=>(0,c.jsx)(r.Button,{onClick:e,variant:"secondary",children:i?(0,o.__)("Replace MP3","custom"):(0,o.__)("Upload MP3","custom")})})}),i&&(0,c.jsx)("div",{style:{marginTop:"10px"},children:(0,c.jsx)("audio",{controls:!0,src:i,style:{width:"100%"}})})]}),(0,c.jsx)(r.PanelBody,{title:(0,o.__)("Explore Character Select","custom"),children:Array.isArray(s)?s.length>0?(0,c.jsx)(r.SelectControl,{label:(0,o.__)("Select a Character","custom"),value:d,options:[{label:(0,o.__)("None","custom"),value:null},...s.map((e=>({label:e.title.rendered,value:e.id})))],onChange:e=>{l({selectedCharacter:parseInt(e,10),selectedVoice:u})}}):(0,c.jsx)("p",{children:(0,o.__)("No characters found.","custom")}):(0,c.jsx)("p",{children:(0,o.__)("Loading characters…","custom")})}),(0,c.jsx)(r.PanelBody,{title:(0,o.__)("Trigger Path","custom"),children:(0,c.jsx)(r.CheckboxControl,{label:(0,o.__)("Enable Trigger Path","custom"),checked:t.triggerPath,onChange:e=>l({triggerPath:e})})})]}),(0,c.jsxs)("span",{className:`explore-character-${d}`,"data-voice":p,...t.triggerPath?{"data-triggerpath":"true"}:{},children:[(0,c.jsx)(e.RichText,{tagName:"p",value:n,onChange:e=>l({content:e}),placeholder:(0,o.__)("Write your paragraph here…","custom")}),i&&(0,c.jsx)("audio",{controls:!0,src:i,style:{position:"absolute",left:"-56000px"}})]})]})},save:({attributes:t})=>{const{content:r,mp3Url:a,selectedCharacter:o,selectedVoice:l}=t,s=o?`explore-character-${o}`:"";return(0,c.jsxs)("span",{className:s,"data-voice":l,...t.triggerPath?{"data-triggerpath":"true"}:{},children:[(0,c.jsx)(e.RichText.Content,{tagName:"p",value:r}),a&&(0,c.jsx)("audio",{controls:!0,src:a,style:{position:"absolute",left:"-56000px"}})]})}})})();