var React = require("react")
var {div, span, label} = React.DOM
var cx = require("classnames")

module.exports = {
  errorList(errors) {
    let i = 0
    return (errors || []).map( (msg) => module.exports.error(msg, i++))
  },

  error(msg, i=0) {
    return span({className: "help-block", key: `error-${i}`},
      React.DOM.i({className: "fa fa-exclamation-circle"}, ` ${msg}`),
    )
  },

  label(props, overrides = {}) {
    let horizontalClasses = sizeClassNames(props.labelWidth, {offsets: false})
    if (!props.label || props.block) {
      if (props.layout === "horizontal" && !props.block) {
        return div({className: horizontalClasses})
      }
      else {
        return ""
      }
    }
    let labelHtml = Object.assign({}, props, overrides)
    labelHtml.className = cx(labelHtml.className, {
      [horizontalClasses]: props.layout === "horizontal",
    })

    return div({}, label(labelHtml, props.label))
  },

  savedText({saved, className}) {
    className = className || "frigb-saved pull-right"
    if (!saved) return ""
    return span({className, key: "saved"}, "saved")
  },

  savedNotification({parentProps, label, overrideSaved, className}) {
    let isSaved = overrideSaved || parentProps.saved && parentProps.modified

    className = cx({
      className: className !== undefined,
      "frigb-saved-inline": label === undefined,
    })

    return savedText({isSaved, className})
  },

  inputContainerCx(props) {
    let labelWidth = props.labelWidth || {}
    let inputWidth = {}
    // The width of the input is the number of columns left after the label
    // is placed on the row. If the label takes a full row (12 coluns) then
    // the input is given another row (12 columns wide).
    for (let k in labelWidth) inputWidth[k] = (12 - labelWidth[k]) || 12
    let horizontalClasses = sizeClassNames(inputWidth, {offsets: false})
    return cx({
      [horizontalClasses]: props.layout === "horizontal" && !props.block,
      ["col-xs-12"]: props.layout === "horizontal" && props.block,
    })
  },

  sizeClassNames(props = {}, opts = {offsets: true}) {
    var classes = {}
    var sizes = ["xs", "sm", "md", "lg"]
    // Adding column classes
    for (var k of sizes) {
      if (props[k] != null) classes[`col-${k}-${props[k]}`] = true
    }
    // Adding offset classes
    if (opts.offsets) {
      for (var size of sizes) {
        k = `${size}Offset`
        if (props[k] == null) continue
        classes[`col-${size}-offset-${props[k]}`] = true
      }
    }
    return cx(classes)
  },

  formGroupCx(props, overrides = {}) {
    let isCheckbox = props.inputHtml.type === "checkbox"
    return cx(Object.assign({
      "form-group": !isCheckbox,
      "checkbox": isCheckbox,
      "has-error": props.errors != null,
      "has-success": props.modified && props.errors == null,
    }, overrides))
  },

}

var {savedText, sizeClassNames} = module.exports

@@ -1107,325 +1107,8 @@
 %7D,%0A%0A
-  savedNotification(%7BparentProps, label, overrideSaved, className%7D) %7B%0A    let isSaved = overrideSaved %7C%7C parentProps.saved && parentProps.modified%0A%0A    className = cx(%7B%0A      className: className !== undefined,%0A      %22frigb-saved-inline%22: label === undefined,%0A    %7D)%0A%0A    return savedText(%7BisSaved, className%7D)%0A  %7D,%0A%0A
   in

Remove Notification SendText Same Functionality