"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.PickerStandaloneLayoutHeader = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _bexCore = require("@wix/bex-core");
var _mobxReactLite = require("mobx-react-lite");
var _react = _interopRequireWildcard(require("react"));
var _reactTransitionGroup = require("react-transition-group");
var _designSystem = require("@wix/design-system");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _CollectionSearch = require("../CollectionSearch");
var _EditorXLogo = require("../EditorXLogo");
var _WixLogo = require("../WixLogo");
var _PickerStandaloneLayoutTitles = require("./PickerStandaloneLayoutTitles");
var _Collapse = require("../Collapse");
var _Fade = require("../Fade");
var _ExpandableSearch = require("../ExpandableSearch");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/PickerStandaloneLayout/PickerStandaloneLayoutHeader.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _PickerStandaloneLayoutHeader(props) {
  const {
    state,
    hideSearch
  } = props;
  const {
    picker,
    logoType,
    isMobileView,
    isDuringSearch
  } = state;
  const {
    collection,
    isScrollTop
  } = picker;
  const searchRef = (0, _react.useRef)();
  const onSearchFocus = () => {
    state.setIsDuringSearch(true);
  };
  const onSearchBlur = () => {
    if (collection.query.search.isEmpty) {
      state.setIsDuringSearch(false);
    }
  };
  const onBackClicked = async () => {
    var _searchRef$current, _searchRef$current2;
    (_searchRef$current = searchRef.current) == null || _searchRef$current.focus();
    await collection.clearSearch();
    (_searchRef$current2 = searchRef.current) == null || _searchRef$current2.blur();
  };
  const {
    headerProps,
    header,
    headerDivider,
    titleSearchContainerProps,
    titleDivider
  } = isMobileView ? {
    headerProps: {
      padding: '12px 24px',
      align: 'space-between'
    },
    header: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.SwitchTransition, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 65,
        columnNumber: 13
      }
    }, /*#__PURE__*/_react.default.createElement(_Fade.Fade, {
      timeout: 150,
      key: isDuringSearch ? 1 : 0,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 66,
        columnNumber: 15
      }
    }, /*#__PURE__*/_react.default.createElement("div", {
      style: {
        display: 'flex'
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 67,
        columnNumber: 17
      }
    }, isDuringSearch ? /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ChevronLeftLarge, {
      height: 24,
      width: 24,
      onClick: onBackClicked,
      style: {
        cursor: 'pointer'
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 69,
        columnNumber: 21
      }
    }) : /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      align: "center",
      verticalAlign: "middle",
      boxSizing: "border-box",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 76,
        columnNumber: 21
      }
    }, logoType === 'editorx' ? /*#__PURE__*/_react.default.createElement(_EditorXLogo.EditorXLogo, {
      height: 16,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 82,
        columnNumber: 25
      }
    }) : /*#__PURE__*/_react.default.createElement(_WixLogo.WixLogo, {
      height: 16,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 84,
        columnNumber: 25
      }
    }))))), /*#__PURE__*/_react.default.createElement(_ExpandableSearch.ExpandableSearch, {
      visibility: hideSearch ? 'hidden' : undefined,
      expandable: true,
      onBlur: onSearchBlur,
      onFocus: onSearchFocus,
      inputRef: input => {
        searchRef.current = input;
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 91,
        columnNumber: 13
      }
    })),
    headerDivider: undefined,
    titleSearchContainerProps: {
      paddingBottom: !isScrollTop && !collection.result.isEmpty ? 0 : 'SP2'
    },
    titleDivider: !isScrollTop && !collection.result.isEmpty && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      margin: "0 15px",
      height: "12px",
      boxShadow: "0 5px 5px -5px rgb(32 48 60 / 20%)",
      zIndex: 9999999,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 107,
        columnNumber: 11
      }
    })
  } : {
    headerProps: {
      padding: '24px 30px',
      align: 'center'
    },
    header: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      align: "center",
      verticalAlign: "middle",
      boxSizing: "border-box",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 121,
        columnNumber: 11
      }
    }, logoType === 'editorx' ? /*#__PURE__*/_react.default.createElement(_EditorXLogo.EditorXLogo, {
      height: 18,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 123,
        columnNumber: 15
      }
    }) : /*#__PURE__*/_react.default.createElement(_WixLogo.WixLogo, {
      height: 24,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 125,
        columnNumber: 15
      }
    })),
    headerDivider: /*#__PURE__*/_react.default.createElement(_designSystem.Divider, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 129,
        columnNumber: 24
      }
    }),
    titleSearchContainerProps: {
      paddingTop: 'SP4',
      paddingBottom: 'SP3',
      gap: 'SP3'
    },
    titleDivider: !hideSearch && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      display: "flex",
      direction: "vertical",
      paddingLeft: "94px",
      paddingRight: "94px",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 136,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_CollectionSearch.CollectionSearch, {
      minWidthPixels: "100%",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 142,
        columnNumber: 13
      }
    }))
  };
  const [collapse] = (0, _react.useState)(() => new _bexCore.TransitionState(true));
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_designSystem.Box, (0, _extends2.default)({
    direction: "horizontal",
    boxSizing: "border-box",
    verticalAlign: "middle"
  }, headerProps, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 151,
      columnNumber: 7
    }
  }), header), headerDivider, /*#__PURE__*/_react.default.createElement(_designSystem.Box, (0, _extends2.default)({
    display: "grid",
    direction: "vertical"
  }, titleSearchContainerProps, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 160,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_Collapse.Collapse, {
    state: collapse,
    in: !isDuringSearch,
    timeout: 300,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 161,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_Fade.Fade, {
    in: !isDuringSearch,
    timeout: 300,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 162,
      columnNumber: 11
    }
  }, /*#__PURE__*/_react.default.createElement(_PickerStandaloneLayoutTitles.PickerStandaloneLayoutTitles, (0, _extends2.default)({}, props, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 163,
      columnNumber: 13
    }
  })))), titleDivider));
}
const PickerStandaloneLayoutHeader = exports.PickerStandaloneLayoutHeader = (0, _mobxReactLite.observer)(_PickerStandaloneLayoutHeader);
//# sourceMappingURL=PickerStandaloneLayoutHeader.js.map