import e from"../../@babel/runtime/helpers/esm/objectSpread2.js";import t from"../../@babel/runtime/helpers/esm/toConsumableArray.js";import o from"../../@babel/runtime/helpers/esm/objectWithoutProperties.js";import{useMemo as i,useCallback as n}from"react";import{H as a,D as r}from"./index-6ea50319.esm.js";import{g as s,b as l}from"./Select-ce3716e1.esm.js";var p=["allowCreateWhileLoading","createOptionPosition","formatCreateLabel","isValidNewOption","getNewOptionData","onCreateOption","options","onChange"],u=function(){var e=arguments.length>1?arguments[1]:void 0,t=arguments.length>2?arguments[2]:void 0,o=String(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").toLowerCase(),i=String(t.getOptionValue(e)).toLowerCase(),n=String(t.getOptionLabel(e)).toLowerCase();return i===o||n===o},c={formatCreateLabel:function(e){return'Create "'.concat(e,'"')},isValidNewOption:function(e,t,o,i){return!(!e||t.some((function(t){return u(e,t,i)}))||o.some((function(t){return u(e,t,i)})))},getNewOptionData:function(e,t){return{label:t,value:e,__isNew__:!0}}};function m(u){var m=u.allowCreateWhileLoading,f=void 0!==m&&m,g=u.createOptionPosition,d=void 0===g?"last":g,v=u.formatCreateLabel,b=void 0===v?c.formatCreateLabel:v,O=u.isValidNewOption,C=void 0===O?c.isValidNewOption:O,w=u.getNewOptionData,h=void 0===w?c.getNewOptionData:w,L=u.onCreateOption,N=u.options,V=void 0===N?[]:N,j=u.onChange,D=o(u,p),S=D.getOptionValue,_=void 0===S?s:S,y=D.getOptionLabel,A=void 0===y?l:y,P=D.inputValue,W=D.isLoading,x=D.isMulti,H=D.value,M=D.name,k=i((function(){return C(P,a(H),V,{getOptionValue:_,getOptionLabel:A})?h(P,b(P)):void 0}),[b,h,A,_,P,C,V,H]),q=i((function(){return!f&&W||!k?V:"first"===d?[k].concat(t(V)):[].concat(t(V),[k])}),[f,d,W,k,V]),z=n((function(e,o){if("select-option"!==o.action)return j(e,o);var i=Array.isArray(e)?e:[e];if(i[i.length-1]!==k)j(e,o);else if(L)L(P);else{var n=h(P,P),s={action:"create-option",name:M,option:n};j(r(x,[].concat(t(a(H)),[n]),n),s)}}),[h,P,x,M,k,L,j,H]);return e(e({},D),{},{options:q,onChange:z})}export{m as u};
//# sourceMappingURL=useCreatable-cfa66f15.esm.js.map
