import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import"./TableTextFilter.css";import{IconSearchStroked}from"@consta/icons/IconSearchStroked";import React,{useMemo,useState}from"react";import{cnMixScrollBar}from"../../../mixs/MixScrollBar";import{cn}from"../../../utils/bem";import{Button}from"../../Button/Button";import{CheckboxGroup}from"../../CheckboxGroup";import{Text}from"../../Text/Text";import{TextField}from"../../TextField/TextField";import{TableFilterContainer}from"../FilterContainer/TableFilterContainer";var cnTextFilter=cn("TableTextFilter");export var TableTextFilter=function(a){var b=a.items,c=void 0===b?[]:b,d=a.withSearch,e=a.onConfirm,f=a.onCancel,g=a.filterValue,h=a.title,i=a.emptySearchText,j=void 0===i?"\u041D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E :(":i,k=useState(null),l=_slicedToArray(k,2),m=l[0],n=l[1],o=useState(g||c),p=_slicedToArray(o,2),q=p[0],r=p[1],s=useMemo(function(){return m?c.filter(function(a){var b=a.name;return b.match(new RegExp("".concat(m),"i"))}):c},[m,c]),t=useMemo(function(){return s.length===(null===q||void 0===q?void 0:q.length)},[s,q]),u=useMemo(function(){return null===q||void 0===q?void 0:q.length},[q]);return React.createElement(TableFilterContainer,{title:h,onCancel:f,onConfirm:function confirmHandler(){n(null),e(null===q?[]:q)}},void 0!==d&&d&&React.createElement(TextField,{value:m,onChange:n,leftSide:IconSearchStroked,size:"s",placeholder:"\u041D\u0430\u0439\u0442\u0438 \u0432 \u0441\u043F\u0438\u0441\u043A\u0435",className:cnTextFilter("Searchbar")}),React.createElement("div",{className:cnTextFilter("Controls")},React.createElement(Button,{size:"m",type:"button",form:"brick",label:"\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0432\u0441\u0435",view:"clear",onClick:function setAll(){r(s)},disabled:!s.length||t}),React.createElement(Button,{size:"m",form:"brick",type:"button",label:"\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C",view:"clear",onClick:function resetHandler(){r(null)},disabled:!s.length||!u})),React.createElement("div",{className:cnTextFilter("Checkboxes",[cnMixScrollBar()])},s.length?React.createElement(CheckboxGroup,{items:s,value:q,getItemLabel:function getItemLabel(a){return a.name},onChange:r,name:"checkboxGroup"}):React.createElement(Text,{lineHeight:"2xs",view:"primary",size:"m"},j)))};
//# sourceMappingURL=TableTextFilter.js.map