(()=>{"use strict";var e,a={9650:()=>{const e=window.wp.blocks,a=window.wp.i18n,s=window.wp.blockEditor,i=window.wp.components,o=window.wp.element,l=window.wp.data,r=window.wp.coreData,t=window.ReactJSXRuntime,n=JSON.parse('{"UU":"carhop-blocks/audio-player"}');(0,e.registerBlockType)(n.UU,{edit:function({attributes:e,setAttributes:n}){const{audioUrl:c,audioId:d,title:u,caption:p}=e,h=(0,o.useRef)(null),_=(0,o.useRef)(null),{saveEntityRecord:m}=(0,l.useDispatch)(r.store),[b,w]=(0,o.useState)(!1),[x,y]=(0,o.useState)(""),v=e=>{n({caption:e}),d&&(async e=>{if(d)try{w(!0),y(""),await m("postType","attachment",{id:d,caption:e}),y((0,a.__)("Légende mise à jour dans la médiathèque.","carhop-blocks"))}catch(e){y((0,a.__)("Erreur lors de la mise à jour dans la médiathèque.","carhop-blocks"))}finally{w(!1)}})(e)},j=e=>{n({audioUrl:e.url,audioId:e.id,caption:e.caption||""})},g=e=>{n({audioUrl:e,audioId:0})};return(0,o.useEffect)(()=>{if(c&&h.current&&void 0!==window.Plyr)return _.current&&_.current.destroy(),_.current=new window.Plyr(h.current,{controls:["play-large","play","progress","current-time","mute","volume","settings"],settings:["speed"],speed:{selected:1,options:[.5,.75,1,1.25,1.5,2]}}),()=>{_.current&&(_.current.destroy(),_.current=null)}},[c]),(0,t.jsxs)("div",{...(0,s.useBlockProps)({className:"audio-player"}),children:[(0,t.jsx)(s.InspectorControls,{children:(0,t.jsxs)(i.PanelBody,{title:(0,a.__)("Informations","carhop-blocks"),initialOpen:!0,children:[(0,t.jsx)(i.TextControl,{label:(0,a.__)("Titre","carhop-blocks"),value:u,onChange:e=>n({title:e})}),(0,t.jsx)(i.TextControl,{label:(0,a.__)("Légende","carhop-blocks"),value:p,onChange:v}),d?b?(0,t.jsx)(i.Notice,{status:"info",isDismissible:!1,children:(0,a.__)("Sauvegarde…","carhop-blocks")}):x?(0,t.jsx)(i.Notice,{status:"success",isDismissible:!1,children:x}):null:(0,t.jsx)(i.Notice,{status:"info",isDismissible:!1,children:(0,a.__)("Média externe : la légende n'est pas synchronisée dans la médiathèque.","carhop-blocks")})]})}),(0,t.jsx)(s.RichText,{className:"audio-player__title",value:u,onChange:e=>n({title:e}),tagName:"h4"}),c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.BlockControls,{children:[(0,t.jsx)(s.MediaReplaceFlow,{mediaId:d,mediaURL:c,allowedTypes:["audio"],accept:"audio/*",onSelectURL:g,onSelect:j}),(0,t.jsx)(i.ToolbarButton,{onClick:()=>{n({audioUrl:"",audioId:0,caption:""})},children:(0,a.__)("Retirer","carhop-blocks")})]}),(0,t.jsx)("div",{className:"audio-player-preview",children:(0,t.jsx)("audio",{ref:h,className:"js-plyr",src:c,preload:"metadata",children:(0,a.__)("Votre navigateur ne supporte pas l'élément audio.","carhop-blocks")})})]}):(0,t.jsx)(s.MediaPlaceholder,{icon:"format-audio",onSelect:j,onSelectURL:g,accept:"audio/*",allowedTypes:["audio"],labels:{title:(0,a.__)("Fichier audio","carhop-blocks"),instructions:(0,a.__)("Téléchargez un fichier audio, sélectionnez-en un depuis la médiathèque ou insérez-en un depuis une URL.","carhop-blocks")}}),(0,t.jsxs)("p",{className:"audio-player__details",children:[(0,t.jsx)("span",{className:"audio-player__details__label",children:"Audio"}),(0,t.jsx)(s.RichText,{className:"audio-player__details__caption",placeholder:(0,a.__)("Renseignez ici la légende de l'audio","carhop-blocks"),value:p,onChange:e=>v(e),tagName:"span"})]})]})},save:function({attributes:e}){const{audioUrl:a,title:i,caption:o}=e;return a?(0,t.jsxs)("div",{...s.useBlockProps.save({className:"audio-player"}),children:[(0,t.jsx)(s.RichText.Content,{value:i,className:"audio-player__title",tagName:"h4"}),(0,t.jsx)("audio",{className:"js-plyr",src:a,preload:"metadata",children:"Votre navigateur ne supporte pas l'élément audio."}),(0,t.jsxs)("p",{className:"audio-player__details",children:[(0,t.jsx)("span",{className:"audio-player__details__label",children:"Audio"}),(0,t.jsx)("span",{className:"audio-player__details__caption",children:null!=o?o:""})]})]}):null}})}},s={};function i(e){var o=s[e];if(void 0!==o)return o.exports;var l=s[e]={exports:{}};return a[e](l,l.exports,i),l.exports}i.m=a,e=[],i.O=(a,s,o,l)=>{if(!s){var r=1/0;for(d=0;d<e.length;d++){for(var[s,o,l]=e[d],t=!0,n=0;n<s.length;n++)(!1&l||r>=l)&&Object.keys(i.O).every(e=>i.O[e](s[n]))?s.splice(n--,1):(t=!1,l<r&&(r=l));if(t){e.splice(d--,1);var c=o();void 0!==c&&(a=c)}}return a}l=l||0;for(var d=e.length;d>0&&e[d-1][2]>l;d--)e[d]=e[d-1];e[d]=[s,o,l]},i.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),(()=>{var e={7962:0,7710:0};i.O.j=a=>0===e[a];var a=(a,s)=>{var o,l,[r,t,n]=s,c=0;if(r.some(a=>0!==e[a])){for(o in t)i.o(t,o)&&(i.m[o]=t[o]);if(n)var d=n(i)}for(a&&a(s);c<r.length;c++)l=r[c],i.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return i.O(d)},s=globalThis.webpackChunkcarhop_blocks=globalThis.webpackChunkcarhop_blocks||[];s.forEach(a.bind(null,0)),s.push=a.bind(null,s.push.bind(s))})();var o=i.O(void 0,[7710],()=>i(9650));o=i.O(o)})();