(()=>{"use strict";var e={n:t=>{var c=t&&t.__esModule?()=>t.default:()=>t;return e.d(c,{a:c}),c},d:(t,c)=>{for(var o in c)e.o(c,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:c[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,c=window.jQuery;var o=e.n(c);const n=window.CDEKWidget;var a=e.n(n);const l=window.wp.element,i=window.lodash,r=window.wp.i18n,d=window.wc.wcSettings,s=({rules:e,onRulesUpdate:c})=>{const o=(t,o)=>{e[o].to=parseInt(t.target.value),e.forEach(((t,c)=>{0!==c&&null!==t.to&&t.to<=e[c-1].to&&(e[c].to=e[c-1].to+1)})),c([...e])},n=(0,l.useCallback)((0,i.debounce)(o,4e3),[e]),a=(t,o)=>{e[o].value=t.target.value,c([...e])},s=(0,l.useCallback)((0,i.debounce)(a,4e3),[e]);return e.map(((l,i)=>(0,t.createElement)("div",{key:l.to+l.value+l.type+i},(0,r.__)("Сумма заказа","cdek-official")," ",e[i-1]&&(0,t.createElement)(t.Fragment,null,(0,r.__)("от","cdek-official")," ",e[i-1].to,d.CURRENCY.symbol)," ",l.to&&(0,t.createElement)(t.Fragment,null,(0,r.__)("меньше или равно","cdek-official"),(0,t.createElement)("input",{defaultValue:l.to,min:e[i-1]?e[i-1].to+1:0,type:"number",onBlur:e=>o(e,i),onInput:e=>n(e,i)}),d.CURRENCY.symbol)," ",1===e.length&&(0,t.createElement)(t.Fragment,null,(0,r.__)("любая","cdek-official")),", ",(0,r.__)("стоимость доставки","cdek-official"),(0,t.createElement)("select",{onChange:t=>((t,o)=>{e[o].type=t.target.value,c([...e])})(t,i),className:"cdek-selector",defaultValue:l.type},(0,t.createElement)("option",{value:"free"},(0,r.__)("бесплатно","cdek-official")),(0,t.createElement)("option",{value:"percentage"},(0,r.__)("взять в процентах","cdek-official")),(0,t.createElement)("option",{value:"fixed"},(0,r.__)("фиксировать на","cdek-official")),(0,t.createElement)("option",{value:"amount"},(0,r.__)("изменить на","cdek-official"))),"free"!==l.type&&(0,t.createElement)("input",{defaultValue:l.value,type:"number",min:"amount"===l.type?null:0,onBlur:e=>a(e,i),onInput:e=>s(e,i)}),"percentage"===l.type&&(0,t.createElement)(t.Fragment,null,"%"),("amount"===l.type||"fixed"===l.type)&&(0,t.createElement)(t.Fragment,null,d.CURRENCY.symbol),0!==i&&(0,t.createElement)("span",{className:"button button-link-delete",onClick:()=>(t=>{t===e.length-1&&(e[t-1].to=null),c(e.filter(((e,c)=>c!==t)))})(i)},"-"))))},u=({input:e})=>{const[c,o]=(0,l.useState)([]),[n,a]=(0,l.useState)([]),d=(0,l.useCallback)((0,i.debounce)(((t,c)=>{e.val(JSON.stringify({door:t,office:c}))}),300),[]);return(0,l.useEffect)((()=>{d(c,n)}),[c,n]),(0,l.useEffect)((()=>{try{const t=JSON.parse(e.val());o(t.door),a(t.office)}catch(e){o([{to:null,type:"percentage",value:100}]),a([{to:null,type:"percentage",value:100}])}}),[]),(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",{className:"cdek-delivery-rules"},(0,t.createElement)("div",{className:"cdek-header"},(0,t.createElement)("h4",null,(0,r.__)("Правила для доставки курьером","cdek-official")),(0,t.createElement)("span",{className:"button",onClick:()=>{c[c.length-1].to=(c[c.length-2]||{to:0}).to+1,o([...c,{to:null,type:"percentage",value:100}])}},"+")),(0,t.createElement)(s,{rules:c,onRulesUpdate:o}),(0,t.createElement)("div",{className:"cdek-header"},(0,t.createElement)("h4",null,(0,r.__)("Правила для доставки до ПВЗ/Постаматов","cdek-official")),(0,t.createElement)("span",{className:"button",onClick:()=>{n[n.length-1].to=(n[n.length-2]||{to:0}).to+1,a([...n,{to:null,type:"percentage",value:100}])}},"+")),(0,t.createElement)(s,{rules:n,onRulesUpdate:a})))};o().getJSON(window.cdek_admin_settings.api.check_auth).done((()=>o()(".token-wrong").remove())).fail((e=>{console.error(e),o()("p:contains('Custom Shipping Method for Cdek')").after('