/*!
 * Copyright © 2018 Splunk Inc.
 * SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
 * in part without a valid written license from Splunk Inc. is PROHIBITED.
 */(()=>{"use strict";var e={9967:(e,t,r)=>{r.d(t,{default:()=>C});var l=r(2649),o=r.n(l),n=r(6195),a=r.n(n);const i=require("@babel/runtime/helpers/objectWithoutProperties");var u=r.n(i),s=r(9497),c=r.n(s),d=r(23),p=r.n(d),b=r(4793),f=r(4082),m=r.n(f),v=r(4008),g=r.n(v),h=r(5862);const y=["onChange","name","value","label","labelPosition","labelWidth","labelStyle","hideLabel","isAdvanced","isDisabled","help","tooltip","validate","error"];function O(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);t&&(l=l.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,l)}return r}const j={},P=e=>{let{onChange:t,name:r,value:l="",label:n,labelPosition:i="top",labelWidth:d,labelStyle:p=j,hideLabel:f=!1,isAdvanced:v,isDisabled:P=!1,help:C,tooltip:x,validate:k,error:_}=e,E=u()(e,y);const[q,w]=(0,s.useState)(l),S=(0,s.useCallback)((e=>"function"==typeof k?k({value:e}):null),[k]),[D,A]=(0,s.useState)(S(l)),L=(0,s.useMemo)((()=>(0,b.debounce)((e=>{A(S(e))}),250)),[S]);(0,s.useEffect)((()=>()=>{L.cancel()}),[L]),(0,s.useEffect)((()=>{w(l),A(S(l))}),[S,l]);const M=(0,s.useCallback)(((e,{value:t})=>{w(t),L(t)}),[L]),B=(0,s.useCallback)((e=>{const o=q.trim();if(o===l)return;const n=S(o);A(n),n||t(e,r,o)}),[q,l,S,t,r]),R=(0,s.useCallback)((e=>{"Enter"===e.key&&B(e)}),[B]),$=(0,s.useMemo)((()=>n&&""!==n?p:function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?O(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},p)),[n,p]);return c().createElement(g(),{label:n,labelPosition:i,labelWidth:d,style:$,hideLabel:f,help:C,tooltip:x,error:(null==D?void 0:D.message)||_,isAdvanced:v},c().createElement(m(),o()({key:l,"data-test":r,style:h.editorStyle,onChange:M,onKeyDown:R,onBlur:B,value:q,disabled:P,canClear:!0},E,{error:!!D||_})))};P.propTypes={onChange:p().func.isRequired,name:p().string.isRequired,label:p().string.isRequired,value:p().string,labelPosition:p().oneOf(["top","left"]),labelWidth:p().number,labelStyle:p().object,hideLabel:p().bool,isAdvanced:p().bool,isDisabled:p().bool,validate:p().func,error:p().bool,help:p().string,tooltip:p().string};const C=P},4008:function(e,t,r){var l=this&&this.__createBinding||(Object.create?function(e,t,r,l){void 0===l&&(l=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,l,o)}:function(e,t,r,l){void 0===l&&(l=r),e[l]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&l(t,e,r);return o(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AdvancedConfigButton=void 0;const i=n(r(9497)),u=n(r(23)),s=a(r(232)),c=r(6649),d=a(r(6643)),p=r(3563),b=a(r(6379)),f=a(r(7020)),m=a(r(9250)),v=(0,s.default)(m.default)`
    margin-top: 0;
    padding: 0;
    // adjust bottom margin according to theme
    margin-bottom: ${p.variables.spacingMedium};
    width: 100%;

    // remove top margin of the first component in control group
    &:first-child {
        margin-top: 0;
    }

    // remove bottom margin of the last component in control group
    &:last-child {
        margin-bottom: 0;
    }
    // remove top padding on label of the first control group
    [data-test='label']:first-of-type {
        padding-top: 0;
    }
`,g=(0,s.default)(b.default)`
    display: flex;
    > span {
        display: flex;
        width: 35px;
    }
`,h=(0,s.default)(f.default)`
    color: ${p.variables.contentColorActive} !important;
    &:hover {
        background-color: ${p.variables.interactiveColorOverlayDrag} !important;
    }
`;t.AdvancedConfigButton=({label:e="",onClick:t})=>i.default.createElement(g,{"data-test":`${e}-advanced-config-button-tooltip`,content:(0,c._)("Advanced configurations")},i.default.createElement(h,{"data-test":`${e}-advanced-config-button`,icon:i.default.createElement(d.default,{"data-test":`${e}-advanced-config-button-icon`}),appearance:"subtle",onClick:t}));const y=({"data-test":e,children:r,isAdvanced:l=!1,label:o,hideLabel:n,labelPosition:a,labelWidth:u,tooltip:s,help:c,style:d,error:p,controlsLayout:b,onClick:f,onAdvancedConfigButtonClick:m})=>i.default.createElement(v,{"data-test":null!=e?e:"control-group",label:o,hideLabel:n,labelPosition:a,labelWidth:u,tooltip:s,help:c,error:p,style:d,onClick:f,controlsLayout:b},l?i.Children.toArray(r).filter(Boolean).map((e=>(0,i.cloneElement)(e,{style:{flex:1}}))):r,l?i.default.createElement(t.AdvancedConfigButton,{label:o,onClick:m}):null);y.propTypes={style:u.object,isAdvanced:u.bool,onClick:u.func,onAdvancedConfigButtonClick:u.func},t.default=y},5862:(e,t)=>{t.editorStyle=void 0,t.editorStyle={width:"100%"}},6195:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},2649:e=>{e.exports=require("@babel/runtime/helpers/extends")},6643:e=>{e.exports=require("@splunk/react-icons/SlidersDoubleHorizontal")},7020:e=>{e.exports=require("@splunk/react-ui/Button")},9250:e=>{e.exports=require("@splunk/react-ui/ControlGroup")},8965:e=>{e.exports=require("@splunk/react-ui/FormRows")},4082:e=>{e.exports=require("@splunk/react-ui/Text")},6379:e=>{e.exports=require("@splunk/react-ui/Tooltip")},3563:e=>{e.exports=require("@splunk/themes")},6649:e=>{e.exports=require("@splunk/ui-utils/i18n")},4793:e=>{e.exports=require("lodash")},23:e=>{e.exports=require("prop-types")},9497:e=>{e.exports=require("react")},232:e=>{e.exports=require("styled-components")}},t={};function r(l){var o=t[l];if(void 0!==o)return o.exports;var n=t[l]={exports:{}};return e[l].call(n.exports,n,n.exports,r),n.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var l in t)r.o(t,l)&&!r.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};(()=>{r.r(l),r.d(l,{default:()=>q});var e=r(6195),t=r.n(e),o=r(9497),n=r.n(o),a=r(23),i=r.n(a),u=r(232),s=r.n(u),c=r(4793),d=r(6649),p=r(8965),b=r.n(p),f=r(9967),m=r(4008),v=r.n(m);function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);t&&(l=l.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,l)}return r}function h(e){for(var r=1;r<arguments.length;r++){var l=null!=arguments[r]?arguments[r]:{};r%2?g(Object(l),!0).forEach((function(r){t()(e,r,l[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(l)):g(Object(l)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(l,t))}))}return e}const y=s().div`
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    [data-test='control-group'] {
        margin: 0;
    }
`,O=n().createElement(y,null,n().createElement("span",{"data-test":"form-row-header-label"},(0,d._)("Label")),n().createElement("span",{"data-test":"form-row-header-value"},(0,d._)("Value"))),j=(e,t)=>e.filter(((e,r)=>r!==t)),P=(e,t,r)=>"string"!=typeof e||""===e.trim()||t.filter((t=>t[r]===e)).length>1,C=(e,t)=>P(e,t,"label"),x=(e,t)=>P(e,t,"value"),k=s().div`
    width: 100%;
`,_=[],E=({onChange:e,name:t,value:r=_,labelPosition:l="top",label:a="",validate:i})=>{const[u,s]=(0,o.useState)(r),[p,m]=(0,o.useState)(r.length);(0,o.useEffect)((()=>{s(r),r.length>p&&m(r.length)}),[r,p]);const g=(0,o.useCallback)((l=>{var o;(0,c.isEqual)(l,r)||((o=l).some((({label:e,value:t})=>"string"!=typeof e||""===e.trim()||"string"!=typeof t||""===t.trim()))||(0,c.uniqBy)(o,(e=>e.value)).length!==o.length||(0,c.uniqBy)(o,(e=>e.label)).length!==o.length)?s(l):e(null,t,l)}),[r,t,e]),P=(0,o.useCallback)(((e,{index:t})=>{const r=j(u,t);g(r)}),[u,g]),E=(0,o.useCallback)((({fromIndex:e,toIndex:t})=>{const r=u[e],l=j(u,e);l.splice(t,0,r),g(l)}),[u,g]),q=(0,o.useCallback)(((e,t)=>(r,l,o="")=>{const n=u[e],a=[...u];a.splice(e,1,h(h({},n),{},{[t]:o.trim()})),g(a)}),[u,g]),w=(0,o.useCallback)((()=>{const e=u.concat({label:`Label ${p}`,value:`menu_v${p}`});m(p+1),g(e)}),[u,p,g]),S=u.map(((e,t)=>{const{label:r,value:l}=e;return n().createElement(b().Row,{index:t,key:`${r}_${l}_${t}`,onRequestRemove:P},n().createElement(y,null,n().createElement(f.default,{label:(0,d._)("Label"),hideLabel:!0,value:r,onChange:q(t,"label"),name:"item-label-editor",error:C(r,u),validate:i}),n().createElement(f.default,{label:(0,d._)("Value"),hideLabel:!0,value:l,onChange:q(t,"value"),name:"item-value-editor",error:x(l,u),validate:i})))}));return n().createElement(v(),{label:a,labelPosition:l},n().createElement(k,null,n().createElement(b(),{addLabel:(0,d._)("Add new"),header:O,onRequestAdd:w,onRequestMove:E},S)))};E.propTypes={onChange:i().func.isRequired,name:i().string.isRequired,label:i().string,value:i().arrayOf(i().exact({label:i().string,value:i().string})),labelPosition:i().oneOf(["top","left"]),validate:i().func};const q=E})(),module.exports=l})();
//# sourceMappingURL=StaticItemEditor.js.map