define(["require","exports","tslib","react","react","./common","./constants","./FormElementOuter","./keyboard","./utils","./assets/stock"],function(T,b,g,h,A,D,w,O,R,N,M){"use strict";var P;Object.defineProperty(b,"__esModule",{value:!0}),h=g.__importStar(h),O=g.__importDefault(O),b.renderScanner=function(e,t){return h.default.createElement(r,{component:e,element:t})},(e=P=b.ScanType||(b.ScanType={})).BarCode="barcode",e.QrCode="qrcode",b.TEXT_AREA_DEFAULT_ROWS=5;var x,e;(e=x=x||{}).Camera="camera",e.Manual="manual";var r=function(e){var t=A.useState(),o=t[0],c=t[1],r=A.useState(""),a=r[0],n=r[1],u=A.useState(!1),i=u[0],s=u[1],l=A.useState(!0),d=l[0],m=l[1],f=A.useRef(),v=e.component,_=e.element,p=v.props,E=p.host,C=p.name,t="barcode"!==_.scanType,B=_.value;A.useEffect(function(){return s(!0),function(){return s(!1)}},[]),A.useEffect(function(){i&&_.enabled&&_.autoActivate&&(_.autoActivate=!1,F())},[i]),A.useEffect(function(){function e(){m(!1),setTimeout(function(){i&&m(!0)},1500)}return o&&e(),function(){o&&(o.reset(),e())}},[o]);r=h.useCallback(function(e){D.renderFocus(e,C,E)},[]);B&&(N.isScanRef(B)&&B.value||(_.value=B=void 0));function S(e,t,r){e&&(B&&B.value===e||(_.value=t={refValueType:"scan",value:e,scanType:r,entryMethod:t},n(e),E.post("changed",{name:v.props.name,value:t})))}var u=E.renderText(_.tooltip),y=function(a){return g.__awaiter(void 0,void 0,void 0,function(){var t,r;return g.__generator(this,function(e){switch(e.label){case 0:return[4,new Promise(function(e,t){T(["@zxing/library"],e,t)}).then(g.__importStar)];case 1:return t=e.sent(),r=void 0,a===P.QrCode?r=[t.BarcodeFormat.QR_CODE,t.BarcodeFormat.DATA_MATRIX,t.BarcodeFormat.AZTEC,t.BarcodeFormat.PDF_417,t.BarcodeFormat.MAXICODE]:a===P.BarCode&&(r=[t.BarcodeFormat.CODABAR,t.BarcodeFormat.CODE_39,t.BarcodeFormat.CODE_93,t.BarcodeFormat.CODE_128,t.BarcodeFormat.EAN_8,t.BarcodeFormat.EAN_13,t.BarcodeFormat.ITF,t.BarcodeFormat.RSS_14,t.BarcodeFormat.RSS_EXPANDED,t.BarcodeFormat.UPC_A,t.BarcodeFormat.UPC_E]),[2,r]}})})},F=function(){return g.__awaiter(void 0,void 0,void 0,function(){var t,r,a;return g.__generator(this,function(e){switch(e.label){case 0:return o?(c(null),E.post("cancel",{name:v.props.name,type:"cancel"}),[2]):(t=function(n){return g.__awaiter(void 0,void 0,void 0,function(){var t,r,a;return g.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,4,,5]),[4,n.listVideoInputDevices()];case 1:if(!(t=e.sent())||0==t.length)throw new DOMException("No video input devices detected.");return[4,n.decodeOnceFromVideoDevice(void 0,f.current)];case 2:return r=e.sent(),[4,y(P.QrCode)];case 3:return a=e.sent(),a=a.indexOf(r.getBarcodeFormat())<0?P.BarCode:P.QrCode,S(r.toString(),x.Camera,a),c(null),[3,5];case 4:return(a=e.sent())instanceof DOMException&&(_.error=a.message,c(null)),[3,5];case 5:return[2]}})})},[4,new Promise(function(e,t){T(["@zxing/library"],e,t)}).then(g.__importStar)]);case 1:return r=e.sent(),i?[4,(n=_.scanType,g.__awaiter(void 0,void 0,void 0,function(){var t,r,a;return g.__generator(this,function(e){switch(e.label){case 0:return[4,new Promise(function(e,t){T(["@zxing/library"],e,t)}).then(g.__importStar)];case 1:return t=e.sent(),[4,y(n)];case 2:return r=e.sent(),(a=new Map).set(t.DecodeHintType.POSSIBLE_FORMATS,r),[2,a]}})}))]:[2];case 2:return a=e.sent(),a=new r.BrowserMultiFormatReader(a),c(a),[4,t(a)];case 3:return e.sent(),[2]}var n})})},l=function(e){o&&c(null),S(e.currentTarget.value,x.Manual)},e=function(e){n(e.currentTarget.value)},p=[_.type,N.makeSafeClassName(C)];return h.default.createElement(O.default,{className:p.join(" "),component:v,element:_,errorClassName:w.CssClasses.ERROR},h.default.createElement("div",{className:"items"},h.default.createElement("div",{className:"scanner-container"},h.default.createElement("video",{className:"video-element",hidden:!o,ref:f}),h.default.createElement("div",{className:"user-controls"},t?h.default.createElement("textarea",{className:"manual-entry",disabled:!(_.enabled&&_.manualEntry),onBlur:l,onChange:e,onKeyDown:function(e){return e.stopPropagation()},ref:r,rows:_.size||b.TEXT_AREA_DEFAULT_ROWS,spellCheck:!1,title:u,value:a}):h.default.createElement("input",{className:"manual-entry",disabled:!(_.enabled&&_.manualEntry),onBlur:l,onChange:e,onKeyDown:function(e){var t=e.currentTarget;"enter"===R.getKeyString(e)&&(e.stopPropagation(),o&&c(null),S(t.value,x.Manual))},ref:r,title:u,type:"text",value:a}),h.default.createElement("button",{className:o?"scan activated":"scan",disabled:!(_.enabled&&d),title:u,onClick:function(e){return F()},ref:r},o?M.renderRemove():_.scanType===P.BarCode?M.renderScanBarcode():_.scanType===P.QrCode?M.renderScanQrcode():M.renderScanMulti())))))}});