'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

function _jade_template_fn(locals) {
  locals = locals || {};;;
  var result_of_with = function ($helpers, Array, JSON, Object, String, editingPropertyType, propertyFilter, searchFilter) {
    var h = require('panel').h;
    var jade_mixins = {};
    jade_mixins['filter-operator-dropdown'] = function () {
      var block = this && this.block,
          attributes = this && this.attributes || {};

      return function () {
        var __jade_nodes = [];
        __jade_nodes = __jade_nodes.concat(h("mp-builder-dropdown", {
          "attrs": {
            options: JSON.stringify($helpers.getFilterOperators()),
            'selected-option': propertyFilter.filterOperator
          },
          "on": {
            change: function change(e) {
              return $helpers.changeFilterOperator(e.detail.value);
            }
          },
          "class": {
            'pvs-filter-operator-dropdown': true
          }
        }));;
        return __jade_nodes;
      }.call(this);
    };

    jade_mixins['filter-number-input'] = function (_ref) {
      var _ref$value = _ref.value,
          value = _ref$value === undefined ? '' : _ref$value,
          _ref$onInput = _ref.onInput,
          onInput = _ref$onInput === undefined ? null : _ref$onInput,
          _ref$autofocus = _ref.autofocus,
          autofocus = _ref$autofocus === undefined ? false : _ref$autofocus,
          _ref$key = _ref.key,
          key = _ref$key === undefined ? null : _ref$key;

      var block = this && this.block,
          attributes = this && this.attributes || {};

      return function () {
        var __jade_nodes = [];
        __jade_nodes = __jade_nodes.concat(h("input", {
          "attrs": {
            type: 'number'
          },
          "props": {
            value: value
          },
          "on": {
            input: onInput
          },
          "hook": {
            insert: autofocus ? function (vnode) {
              return $helpers.focusInput(vnode.elm);
            } : null
          },
          "key": key,
          "class": {
            'pvs-filter-numdate-input': true
          }
        }));;
        return __jade_nodes;
      }.call(this);
    };

    jade_mixins['filter-string-input'] = function () {
      var block = this && this.block,
          attributes = this && this.attributes || {};

      return function () {
        var __jade_nodes = [];
        __jade_nodes = __jade_nodes.concat(h("input", {
          "attrs": {
            type: 'text'
          },
          "props": {
            value: propertyFilter.filterValue
          },
          "on": {
            input: function input(e) {
              return $helpers.changeFilterValue(e.target.value);
            }
          },
          "key": 'string-' + propertyFilter.filterOperator,
          "hook": {
            insert: function insert(vnode) {
              return $helpers.focusInput(vnode.elm);
            }
          },
          "class": {
            'pvs-filter-string-input': true
          }
        }));;
        return __jade_nodes;
      }.call(this);
    };

    var __vjadeSafeCode = function __vjadeSafeCode(code) {
      return code || String(code);
    };
    return {
      value: h("div", {
        "hook": {
          postpatch: $helpers.dispatchDraw
        },
        "class": Object.assign({}, {
          'pvs-display-context-custom-event': $helpers.getDisplayContext() === $helpers.PropertyFilterDisplayContext.CustomEvent
        }, {
          'pvs-container': true
        })
      }, function () {
        var __jade_nodes = [];
        __jade_nodes = __jade_nodes.concat(h("div", {
          "class": {
            'pvs-title-section': true
          }
        }, function () {
          var __jade_nodes = [];
          __jade_nodes = __jade_nodes.concat($helpers.hasBackButton() ? function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("div", {
              "on": {
                click: $helpers.clickBackButton
              },
              "class": {
                'pvs-back-button': true
              }
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("svg-icon", {
                "attrs": {
                  icon: 'caret-left'
                }
              }));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));;
            return __jade_nodes;
          }.call(this) : undefined);
          __jade_nodes = __jade_nodes.concat(h("div", {
            "class": {
              'pvs-property-type-container': true
            }
          }, function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("div", {
              "on": {
                click: $helpers.clickPropertyTypeButton
              },
              "class": {
                'pvs-property-type-button': true
              }
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("svg-icon", {
                "attrs": {
                  icon: $helpers.getPropertyTypeIcon()
                }
              }));
              var propertyLabel = $helpers.getPropertyLabel();
              __jade_nodes = __jade_nodes.concat(h("span", {
                "attrs": {
                  title: propertyLabel
                },
                "class": {
                  'pvs-property-type-label': true
                }
              }, [__vjadeSafeCode($helpers.truncateMiddle(propertyLabel, 30))]));
              __jade_nodes = __jade_nodes.concat(h("svg-icon", {
                "attrs": {
                  icon: 'caret-down'
                }
              }));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));
            __jade_nodes = __jade_nodes.concat(h("div", {
              "class": {
                'pvs-property-types-menu': true
              }
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("mp-drop-menu", {
                "attrs": {
                  open: editingPropertyType
                },
                "on": {
                  change: $helpers.changePropertyTypesMenu
                }
              }, function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("mp-items-menu", {
                  "attrs": {
                    sections: JSON.stringify($helpers.getPropertyTypeMenuSections())
                  },
                  "on": {
                    clickItem: $helpers.clickPropertyTypesMenuItem
                  }
                }));;
                return __jade_nodes;
              }.call(this).filter(Boolean)));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));;
            return __jade_nodes;
          }.call(this).filter(Boolean)));;
          return __jade_nodes;
        }.call(this).filter(Boolean)));
        __jade_nodes = __jade_nodes.concat(h("div", {
          "class": {
            'pvs-filter-section': true
          }
        }, function () {
          var __jade_nodes = [];
          var propertyType = propertyFilter.propertyType;

          __jade_nodes = __jade_nodes.concat(propertyType == $helpers.PropertyType.Number ? function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("div", {
              "class": {
                'pvs-filter-fixed-subsection': true
              }
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(jade_mixins['filter-operator-dropdown'].call(this));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));
            __jade_nodes = __jade_nodes.concat(h("div", {
              "class": Object.assign({}, {
                'pvs-filter-numdate-between': propertyFilter.filterOperator === $helpers.NumberOperator.Between
              }, {
                'pvs-filter-fixed-subsection': true
              })
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(propertyFilter.filterOperator == $helpers.NumberOperator.Between ? function () {
                var __jade_nodes = [];

                var _propertyFilter$filte = _slicedToArray(propertyFilter.filterValue, 2),
                    minNum = _propertyFilter$filte[0],
                    maxNum = _propertyFilter$filte[1];

                __jade_nodes = __jade_nodes.concat(jade_mixins['filter-number-input'].call(this, {
                  value: minNum,
                  onInput: function onInput(ev) {
                    return $helpers.changeFilterValue([$helpers.parseNumber(ev.target.value), maxNum]);
                  },
                  autofocus: true,
                  key: 'num-min'
                }));
                __jade_nodes = __jade_nodes.concat(h("div", {
                  "class": {
                    'pvs-filter-conjunction': true
                  }
                }, function () {
                  var __jade_nodes = [];
                  __jade_nodes = __jade_nodes.concat("and");;
                  return __jade_nodes;
                }.call(this).filter(Boolean)));
                __jade_nodes = __jade_nodes.concat(jade_mixins['filter-number-input'].call(this, {
                  value: maxNum,
                  onInput: function onInput(ev) {
                    return $helpers.changeFilterValue([minNum, $helpers.parseNumber(ev.target.value)]);
                  },
                  autofocus: false,
                  key: 'num-max'
                }));;
                return __jade_nodes;
              }.call(this) : function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(jade_mixins['filter-number-input'].call(this, {
                  value: propertyFilter.filterValue,
                  onInput: function onInput(e) {
                    return $helpers.changeFilterValue($helpers.parseNumber(e.target.value));
                  },
                  autofocus: true,
                  key: 'num-val-' + propertyFilter.filterOperator
                }));;
                return __jade_nodes;
              }.call(this));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));;
            return __jade_nodes;
          }.call(this) : propertyType == $helpers.PropertyType.Boolean || propertyType == $helpers.PropertyType.List ? function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("div", {
              "class": {
                'pvs-filter-fixed-subsection': true,
                'pvs-filter-radio-list': true
              }
            }, function () {
              var __jade_nodes = []; /*  TODO(mack): For the custom events property filter, we only support 'contains' operator. */
              /*  Use a different UI rather than a single radio button in this case? */
              __jade_nodes = __jade_nodes.concat(function () {
                var $$obj = $helpers.getFilterOperators();
                var $$eachNodes;
                var $$iterated = false;
                if (Array.isArray($$obj)) {
                  $$eachNodes = $$obj.reduce(function ($$eachNodes, filterOperator, $index) {
                    $$iterated = true;
                    return $$eachNodes.concat(function () {
                      var __jade_nodes = [];
                      __jade_nodes = __jade_nodes.concat(h("div", {
                        "class": {
                          'pvs-radio-button-container': true
                        }
                      }, function () {
                        var __jade_nodes = [];
                        __jade_nodes = __jade_nodes.concat(h("mp-radio-button", {
                          "attrs": {
                            selected: filterOperator === propertyFilter.filterOperator
                          },
                          "on": {
                            click: function click() {
                              return $helpers.changeFilterOperator(filterOperator);
                            }
                          }
                        }, [__vjadeSafeCode(filterOperator)]));;
                        return __jade_nodes;
                      }.call(this).filter(Boolean)));;
                      return __jade_nodes;
                    }.call(this));
                  }, []);
                } else {
                  $$eachNodes = [];
                  for (var $$objKey in $$obj) {
                    (function () {
                      var $index = $$objKey;
                      if ($$obj.hasOwnProperty($index)) {
                        $$iterated = true;
                        var filterOperator = $$obj[$index];
                        $$eachNodes = $$eachNodes.concat(function () {
                          var __jade_nodes = [];
                          __jade_nodes = __jade_nodes.concat(h("div", {
                            "class": {
                              'pvs-radio-button-container': true
                            }
                          }, function () {
                            var __jade_nodes = [];
                            __jade_nodes = __jade_nodes.concat(h("mp-radio-button", {
                              "attrs": {
                                selected: filterOperator === propertyFilter.filterOperator
                              },
                              "on": {
                                click: function click() {
                                  return $helpers.changeFilterOperator(filterOperator);
                                }
                              }
                            }, [__vjadeSafeCode(filterOperator)]));;
                            return __jade_nodes;
                          }.call(this).filter(Boolean)));;
                          return __jade_nodes;
                        }.call(this));
                      }
                    })();
                  }
                }

                return $$eachNodes;
              }());;
              return __jade_nodes;
            }.call(this).filter(Boolean)));
            __jade_nodes = __jade_nodes.concat(propertyType === $helpers.PropertyType.List ? function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("div", {
                "class": {
                  'pvs-filter-fixed-subsection': true
                }
              }, function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(jade_mixins['filter-string-input'].call(this));;
                return __jade_nodes;
              }.call(this).filter(Boolean)));;
              return __jade_nodes;
            }.call(this) : undefined);;
            return __jade_nodes;
          }.call(this) : propertyType == $helpers.PropertyType.String ? function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("div", {
              "class": {
                'pvs-filter-fixed-subsection': true
              }
            }, function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(jade_mixins['filter-operator-dropdown'].call(this));;
              return __jade_nodes;
            }.call(this).filter(Boolean)));
            __jade_nodes = __jade_nodes.concat(propertyFilter.filterOperator == $helpers.StringOperator.Contains || propertyFilter.filterOperator == $helpers.StringOperator.DoesNotContain ? function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("div", {
                "class": {
                  'pvs-filter-fixed-subsection': true
                }
              }, function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(jade_mixins['filter-string-input'].call(this));;
                return __jade_nodes;
              }.call(this).filter(Boolean)));
              __jade_nodes = __jade_nodes.concat($helpers.isLoadingPropertyValues() ? function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("div", {
                  "class": {
                    'pvs-filter-property-values-loading': true
                  }
                }, function () {
                  var __jade_nodes = [];
                  __jade_nodes = __jade_nodes.concat(h("mp-spinner"));;
                  return __jade_nodes;
                }.call(this).filter(Boolean)));;
                return __jade_nodes;
              }.call(this) : function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("div", {
                  "class": {
                    'pvs-filter-property-values': true
                  }
                }, function () {
                  var __jade_nodes = [];
                  __jade_nodes = __jade_nodes.concat(h("mp-items-menu", {
                    "attrs": $helpers.filterAttributes({
                      progressive: true,
                      'search-filter': propertyFilter.filterValue ? $helpers.renamePropertyValue(propertyFilter.filterValue) : null,
                      sections: JSON.stringify($helpers.getPropertyValueSections())
                    }),
                    "on": {
                      clickItem: function clickItem(e) {
                        return $helpers.selectContainsPropertyValue(e.detail.item.propertyValue);
                      },
                      draw: $helpers.propagateEvent
                    },
                    "props": $helpers.getItemsMenuProps(),
                    "class": {
                      'pvs-property-value-list': true
                    }
                  }));;
                  return __jade_nodes;
                }.call(this).filter(Boolean)));;
                return __jade_nodes;
              }.call(this));;
              return __jade_nodes;
            }.call(this) : propertyFilter.filterOperator == $helpers.StringOperator.Equals || propertyFilter.filterOperator == $helpers.StringOperator.DoesNotEqual ? function () {
              var __jade_nodes = [];
              __jade_nodes = __jade_nodes.concat(h("div", {
                "class": {
                  'pvs-filter-fixed-subsection': true
                }
              }, function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("mp-icon-input", {
                  "attrs": {
                    icon: 'search',
                    placeholder: 'Search'
                  },
                  "props": {
                    value: searchFilter
                  },
                  "key": 'string-' + propertyFilter.filterOperator,
                  "hook": {
                    insert: function insert(vnode) {
                      return $helpers.insertedIconInput(vnode.elm);
                    }
                  },
                  "on": {
                    input: function input(e) {
                      return $helpers.changeSearchFilter(e.target.value);
                    }
                  }
                }));;
                return __jade_nodes;
              }.call(this).filter(Boolean)));
              __jade_nodes = __jade_nodes.concat($helpers.isLoadingPropertyValues() && !searchFilter ? function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("div", {
                  "class": {
                    'pvs-filter-property-values-loading': true
                  }
                }, function () {
                  var __jade_nodes = [];
                  __jade_nodes = __jade_nodes.concat(h("mp-spinner"));;
                  return __jade_nodes;
                }.call(this).filter(Boolean)));;
                return __jade_nodes;
              }.call(this) : function () {
                var __jade_nodes = [];
                __jade_nodes = __jade_nodes.concat(h("div", {
                  "class": {
                    'pvs-filter-property-values': true
                  }
                }, function () {
                  var __jade_nodes = [];
                  __jade_nodes = __jade_nodes.concat(h("mp-checkbox-list", {
                    "attrs": $helpers.filterAttributes({
                      progressive: true,
                      'search-filter': searchFilter,
                      items: JSON.stringify($helpers.getPropertyValueItems())
                    }),
                    "on": {
                      selectAll: $helpers.selectAllPropertyValues,
                      unselectAll: $helpers.unselectAllPropertyValues,
                      clickItem: function clickItem(e) {
                        return $helpers.toggleFilterItem(e.detail.item);
                      },
                      draw: $helpers.propagateEvent
                    },
                    "props": $helpers.getItemsMenuProps()
                  }));;
                  return __jade_nodes;
                }.call(this).filter(Boolean)));;
                return __jade_nodes;
              }.call(this));;
              return __jade_nodes;
            }.call(this) : undefined);;
            return __jade_nodes;
          }.call(this) : propertyType == $helpers.PropertyType.Datetime ? function () {
            var __jade_nodes = [];
            __jade_nodes = __jade_nodes.concat(h("mp-date-range-picker", {
              "attrs": $helpers.filterAttributes({
                'display-context': $helpers.getDateRangePickerDisplayContext(),
                'date-range': JSON.stringify(propertyFilter.filterValue)
              }),
              "on": {
                changeDateRange: $helpers.changeDateRange,
                draw: $helpers.propagateEvent
              }
            }));;
            return __jade_nodes;
          }.call(this) : undefined);;
          return __jade_nodes;
        }.call(this).filter(Boolean)));
        __jade_nodes = __jade_nodes.concat(h("mp-button-bar", {
          "attrs": {
            disabled: !propertyFilter.isValid()
          },
          "on": {
            click: $helpers.clickAddFilter
          },
          "class": {
            'mp-button-bar-primary': true
          }
        }, function () {
          var __jade_nodes = [];
          __jade_nodes = __jade_nodes.concat("Add filter");;
          return __jade_nodes;
        }.call(this).filter(Boolean)));;
        return __jade_nodes;
      }.call(this).filter(Boolean))
    };
  }.call(this, "$helpers" in locals ? locals.$helpers : typeof $helpers !== "undefined" ? $helpers : undefined, "Array" in locals ? locals.Array : typeof Array !== "undefined" ? Array : undefined, "JSON" in locals ? locals.JSON : typeof JSON !== "undefined" ? JSON : undefined, "Object" in locals ? locals.Object : typeof Object !== "undefined" ? Object : undefined, "String" in locals ? locals.String : typeof String !== "undefined" ? String : undefined, "editingPropertyType" in locals ? locals.editingPropertyType : typeof editingPropertyType !== "undefined" ? editingPropertyType : undefined, "propertyFilter" in locals ? locals.propertyFilter : typeof propertyFilter !== "undefined" ? propertyFilter : undefined, "searchFilter" in locals ? locals.searchFilter : typeof searchFilter !== "undefined" ? searchFilter : undefined);
  if (result_of_with) return result_of_with.value;
}
module.exports = _jade_template_fn;