(()=>{"use strict";const e=window.wp.blocks;function t(e){var r,o,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var s=e.length;for(r=0;r<s;r++)e[r]&&(o=t(e[r]))&&(n&&(n+=" "),n+=o)}else for(o in e)e[o]&&(n&&(n+=" "),n+=o);return n}const r=window.wp.element,o=window.wp.data,n=window.wp.components,s=window.wp.i18n,a=window.wp.blockEditor,l=window.ReactJSXRuntime,i=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"godam/srfm-recorder","title":"GoDAM Recorder","icon":"video-alt","category":"sureforms","description":"Enable audio/video submissions inside forms using the GoDAM Recorder field that supports webcam, screencast, and audio recording","keywords":["sureforms","godam","recorder"],"textdomain":"godam","supports":{"reusable":false,"html":false},"example":{"attributes":{"preview":true}},"attributes":{"blockId":{"type":"string"},"required":{"type":"boolean","default":false},"label":{"type":"string","default":"GoDAM Recorder"},"description":{"type":"string","default":""},"recordButton":{"type":"string"},"fileSelector":{"type":"array","default":["screen_capture","webcam","audio"]},"maxFileSize":{"type":"number"},"formId":{"type":"number","default":""},"slug":{"type":"string","default":""},"errorMsg":{"type":"string","default":""},"blockIndex":{"type":"integer"}},"editorScript":["file:./index.js"],"render":"file:./render.php"}'),{name:d}=i;!function(t){if(!t)return;const{metadata:r,settings:o,name:n}=t;(0,e.registerBlockType)({name:n,...r},o)}({name:d,metadata:i,settings:{example:{attributes:{src:"https://upload.wikimedia.org/wikipedia/commons/d/dd/Armstrong_Small_Step.ogg"},viewportWidth:350},edit:function(e){const{clientId:i,attributes:d,setAttributes:c,className:m}=e,{blockId:u,label:g,description:p,recordButton:f,formId:_,required:x,fileSelector:b,maxFileSize:h,errorMsg:w,blockIndex:k}=d,C=(e=>(0,o.useSelect)(t=>{const r=t(a.store).getBlockParents(e),o=t(a.store).getBlocksByClientId(r?.[0]),n=t("core/editor").getCurrentPostId();return o?.[0]?.attributes?.id||n}))(i),[j,y]=(0,r.useState)(!1),M=function(){for(var e,r,o=0,n="",s=arguments.length;o<s;o++)(e=arguments[o])&&(r=t(e))&&(n&&(n+=" "),n+=r);return n}(m,{"godam-srfm-recorder":!0,"srfm-block":!0}),S=(0,a.useBlockProps)({className:M}),B=function(){const e=window?._wpPluploadSettings?.defaults?.filters?.max_file_size,t=e.replace(/b$/i,""),r=parseInt(t,10);return Math.floor(r/1048576)}(),N=x?" srfm-required":"";(0,r.useEffect)(()=>{_!==C&&c({formId:C})},[_,c,C]),(0,r.useEffect)(()=>{c({blockId:i.substring(0,8)})},[i,c]),(0,r.useEffect)(()=>{0===b.length&&c({fileSelector:["webcam","screen_capture"]})});const{currentMessage:v,setCurrentMessage:I}=(e=>{const[t,o]=(0,r.useState)();return(0,r.useEffect)(()=>{o(e)},[e]),{currentMessage:t,setCurrentMessage:o}})(w),E=(0,o.useSelect)(e=>{const{getBlocks:t}=e("core/block-editor");return t().filter(e=>"godam/srfm-recorder"===e.name).findIndex(e=>e.clientId===i)},[i]);(0,r.useEffect)(()=>{k!==E+1&&c({blockIndex:E+1})},[k,E,c]);const z=e=>{let t=[];t=b.includes(e)?b.filter(t=>t!==e):[...b,e],0!==t.length?(j&&y(!1),c({fileSelector:t})):y(!0)},D=e=>b.includes(e),R=[{id:"label",component:(0,l.jsx)(n.TextControl,{placeholder:(0,s.__)("GoDAM Recorder","godam"),__next40pxDefaultSize:!0,label:(0,s.__)("Label","godam"),help:(0,s.__)("Enter label for the field","godam"),onChange:e=>{c({label:e})},value:g})},{id:"description",component:(0,l.jsx)(n.TextControl,{placeholder:(0,s.__)("Enter description","godam"),__next40pxDefaultSize:!0,label:(0,s.__)("Description","godam"),help:(0,s.__)("Enter description for the field","godam"),onChange:e=>{c({description:e})},value:p})},{id:"file-selector",component:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.__experimentalText,{isBlock:!0,style:{marginBottom:"20px"},children:(0,s.__)("Choose file selector","godam")}),j&&(0,l.jsx)("div",{style:{marginBottom:"16px"},children:(0,l.jsx)(n.Notice,{isDismissible:!0,onDismiss:()=>y(!1),status:"error",children:(0,s.__)("Select min of 1 file selector")})}),(0,l.jsx)(n.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,s.__)("Local files","godam"),checked:D("file_input"),onChange:()=>z("file_input")}),(0,l.jsx)(n.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,s.__)("Webcam","godam"),checked:D("webcam"),onChange:()=>z("webcam")}),(0,l.jsx)(n.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,s.__)("Screencast","godam"),checked:D("screen_capture"),onChange:()=>z("screen_capture")}),(0,l.jsx)(n.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,s.__)("Audio","godam"),checked:D("audio"),onChange:()=>z("audio")})]})},{id:"max-file-size",component:(0,l.jsx)(n.__experimentalNumberControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,placeholder:(0,s.__)("100 MB","godam"),label:(0,s.__)("Maximum file size (in MB)","godam"),help:(0,s.sprintf)(
// Translators: %s will be replaced with the maximum file upload size allowed on the server (e.g., "300MB").
// Translators: %s will be replaced with the maximum file upload size allowed on the server (e.g., "300MB").
(0,s.__)("Maximum allowed on this server: %s MB","godam"),B),onChange:e=>{c({maxFileSize:parseInt(e,10)})},max:B,step:1,min:10,value:parseInt(h,10)})},{id:"required",component:(0,l.jsx)(n.ToggleControl,{checked:x,label:(0,s.__)("Is recorder field required?","godam"),onChange:()=>c({required:!x})})},{id:"error-message",component:x?(0,l.jsx)(n.TextControl,{placeholder:(0,s.__)("Enter error message","godam"),label:(0,s.__)("Required Error Message"),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,help:(0,s.__)("Enter the required error message","godam"),value:v,onChange:e=>{I(e),c({errorMsg:e})}}):null}];return(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)("div",{...S,children:[(0,l.jsx)(a.InspectorControls,{children:(0,l.jsx)(n.PanelBody,{title:(0,s.__)("Field settings","godam"),children:R.map(e=>e.component)})}),(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(a.RichText,{tagName:"label",value:""===g?(0,s.__)("Untitled","godam"):g,onChange:e=>{c({label:e})},className:`srfm-block-label${N}`,id:u+"-label",multiline:!1,allowedFormats:[]}),p?(0,l.jsx)(a.RichText,{tagName:"label",value:p,onChange:e=>{c({description:e})},className:"srfm-description",id:u,multiline:!1,allowedFormats:[]}):null,(0,l.jsx)("button",{style:{margin:"4px 0"},className:"srfm-button",children:(0,l.jsx)(a.RichText,{type:"label",value:null!=f?f:(0,s.__)("Start Recording","godam"),onChange:e=>{c({recordButton:e})},className:"godam-srf-record-button",multiline:!1,allowedFormats:[]})}),(0,l.jsx)("p",{className:"srfm-description",children:(0,s.sprintf)(
// Translators: %s will be replaced with the maximum file upload size allowed on the server (e.g., "300MB").
// Translators: %s will be replaced with the maximum file upload size allowed on the server (e.g., "300MB").
(0,s.__)("Maximum allowed size: %s MB","godam"),isNaN(h)||void 0===h?B:h)})]})]})})},save:function(){return null}}})})();