@import '../../style/themes/index';
@import '../../style/mixins/index';
@import '../../input/style/mixin';
@import '../../button/style/mixin';
@import '../../grid/style/mixin';
@import './mixin';

@yee-form-prefix-cls: ~'@{yee-prefix}-form';
@yee-form-component-height: @yee-input-height-base;
@yee-form-component-max-height: @yee-input-height-lg;
@yee-form-feedback-icon-size: @yee-font-size-base;
@yee-form-help-margin-top: (@yee-form-component-height - @yee-form-component-max-height) / 2 + 2px;
@yee-form-explain-font-size: @yee-font-size-base;
// Extends additional 1px to fix precision issue.
// https://github.com/ant-design/ant-design/issues/12803
// https://github.com/ant-design/ant-design/issues/8220
@yee-form-explain-precision: 1px;
@yee-form-explain-height: floor(@yee-form-explain-font-size * @yee-line-height-base);

.@{yee-form-prefix-cls} {
  .yee-reset-component;
  .yee-reset-form;
}

.@{yee-form-prefix-cls}-item-required::before {
  display: inline-block;
  margin-right: 4px;
  color: @yee-label-required-color;
  font-size: @yee-font-size-base;
  font-family: SimSun, sans-serif;
  line-height: 1;
  content: '*';
  .@{yee-form-prefix-cls}-hide-required-mark & {
    display: none;
  }
}

.@{yee-form-prefix-cls}-item-label > label {
  color: @yee-label-color;

  &::after {
    & when (@yee-form-item-trailing-colon=true) {
      content: ':';
    }
    & when not (@yee-form-item-trailing-colon=true) {
      content: ' ';
    }

    position: relative;
    top: -0.5px;
    margin: 0 @yee-form-item-label-colon-margin-right 0 @yee-form-item-label-colon-margin-left;
  }

  &.@{yee-form-prefix-cls}-item-no-colon::after {
    content: ' ';
  }
}

// Form items
// You should wrap labels and controls in .@{yee-form-prefix-cls}-item for optimum spacing
.@{yee-form-prefix-cls}-item {
  label {
    position: relative;

    > .@{yee-iconfont-css-prefix} {
      font-size: @yee-font-size-base;
      vertical-align: top;
    }
  }

  .yee-reset-component;

  margin-bottom: @yee-form-item-margin-bottom;
  vertical-align: top;

  &-control {
    position: relative;
    line-height: @yee-form-component-max-height;
    .yee-clearfix;
  }

  &-children {
    position: relative;
  }

  &-with-help {
    margin-bottom: max(0, @yee-form-item-margin-bottom - @yee-form-explain-height - @yee-form-help-margin-top);
  }

  &-label {
    display: inline-block;
    overflow: hidden;
    line-height: @yee-form-component-max-height - 0.0001px;
    white-space: nowrap;
    text-align: right;
    vertical-align: middle;

    &-left {
      text-align: left;
    }
  }

  .@{yee-prefix}-switch {
    margin: 2px 0 4px;
  }
}

.@{yee-form-prefix-cls}-explain,
.@{yee-form-prefix-cls}-extra {
  clear: both;
  min-height: @yee-form-explain-height + @yee-form-explain-precision;
  margin-top: @yee-form-help-margin-top;
  color: @yee-text-color-secondary;
  font-size: @yee-form-explain-font-size;
  line-height: @yee-line-height-base;
  transition: color 0.3s @yee-ease-out; // sync input color transition
}

.@{yee-form-prefix-cls}-explain {
  margin-bottom: -@yee-form-explain-precision;
}

.@{yee-form-prefix-cls}-extra {
  padding-top: 4px;
}

.@{yee-form-prefix-cls}-text {
  display: inline-block;
  padding-right: 8px;
}

.@{yee-form-prefix-cls}-split {
  display: block;
  text-align: center;
}

form {
  .has-feedback {
    .@{yee-prefix}-input {
      padding-right: @yee-input-padding-horizontal-base + @yee-input-affix-width;
    }

    // https://github.com/ant-design/ant-design/issues/19884
    .@{yee-prefix}-input-affix-wrapper {
      .@{yee-prefix}-input-suffix {
        padding-right: 18px;
      }
      .@{yee-prefix}-input {
        padding-right: @yee-input-padding-horizontal-base + @yee-input-affix-width * 2;
      }
      &.@{yee-prefix}-input-affix-wrapper-input-with-clear-btn {
        .@{yee-prefix}-input {
          padding-right: @yee-input-padding-horizontal-base + @yee-input-affix-width * 3;
        }
      }
    }

    // Fix overlapping between feedback icon and <Select>'s arrow.
    // https://github.com/ant-design/ant-design/issues/4431
    > .@{yee-prefix}-select .@{yee-prefix}-select-arrow,
    > .@{yee-prefix}-select .@{yee-prefix}-select-selection__clear,
    :not(.@{yee-prefix}-input-group-addon) > .@{yee-prefix}-select .@{yee-prefix}-select-arrow,
    :not(.@{yee-prefix}-input-group-addon) > .@{yee-prefix}-select .@{yee-prefix}-select-selection__clear {
      right: (@yee-form-component-height / 2) + @yee-form-feedback-icon-size - 2px;
    }
    > .@{yee-prefix}-select .@{yee-prefix}-select-selection-selected-value,
    :not(.@{yee-prefix}-input-group-addon) > .@{yee-prefix}-select .@{yee-prefix}-select-selection-selected-value {
      padding-right: 42px;
    }

    .@{yee-prefix}-cascader-picker {
      &-arrow {
        margin-right: (@yee-form-component-height / 2) + @yee-form-feedback-icon-size - 13px;
      }
      &-clear {
        right: (@yee-form-component-height / 2) + @yee-form-feedback-icon-size - 2px;
      }
    }

    // Fix issue: https://github.com/ant-design/ant-design/issues/7854
    .@{yee-prefix}-input-search:not(.@{yee-prefix}-input-search-enter-button) {
      .@{yee-prefix}-input-suffix {
        right: (@yee-form-component-height / 2) + @yee-form-feedback-icon-size - 2px;
      }
    }

    // Fix issue: https://github.com/ant-design/ant-design/issues/4783
    .@{yee-prefix}-calendar-picker,
    .@{yee-prefix}-time-picker {
      &-icon,
      &-clear {
        right: (@yee-form-component-height / 2) + @yee-form-feedback-icon-size - 2px;
      }
    }
  }

  .@{yee-prefix}-mentions,
  textarea.@{yee-prefix}-input {
    height: auto;
    margin-bottom: 4px;
  }

  // input[type=file]
  .@{yee-prefix}-upload {
    background: transparent;
  }

  input[type='radio'],
  input[type='checkbox'] {
    width: 14px;
    height: 14px;
  }

  // Radios and checkboxes on same line
  .@{yee-prefix}-radio-inline,
  .@{yee-prefix}-checkbox-inline {
    display: inline-block;
    margin-left: 8px;
    font-weight: normal;
    vertical-align: middle;
    cursor: pointer;

    &:first-child {
      margin-left: 0;
    }
  }

  .@{yee-prefix}-checkbox-vertical,
  .@{yee-prefix}-radio-vertical {
    display: block;
  }

  .@{yee-prefix}-checkbox-vertical + .@{yee-prefix}-checkbox-vertical,
  .@{yee-prefix}-radio-vertical + .@{yee-prefix}-radio-vertical {
    margin-left: 0;
  }

  .@{yee-prefix}-input-number {
    + .@{yee-form-prefix-cls}-text {
      margin-left: 8px;
    }
    &-handler-wrap {
      z-index: 2; // https://github.com/ant-design/ant-design/issues/6289
    }
  }

  .@{yee-prefix}-select,
  .@{yee-prefix}-cascader-picker {
    width: 100%;
  }

  // Don't impact select inside input group
  .@{yee-prefix}-input-group .@{yee-prefix}-select,
  .@{yee-prefix}-input-group .@{yee-prefix}-cascader-picker {
    width: auto;
  }

  // fix input with addon position. https://github.com/ant-design/ant-design/issues/8243
  :not(.@{yee-prefix}-input-group-wrapper) > .@{yee-prefix}-input-group,
  .@{yee-prefix}-input-group-wrapper {
    display: inline-block;
    vertical-align: middle;
  }

  // https://github.com/ant-design/ant-design/issues/20616
  &:not(.@{yee-form-prefix-cls}-vertical) {
    :not(.@{yee-prefix}-input-group-wrapper) > .@{yee-prefix}-input-group,
    .@{yee-prefix}-input-group-wrapper {
      position: relative;
      top: -1px;
    }
  }
}

// Form layout
//== Vertical Form
.yee-make-vertical-layout-label() {
  display: block;
  margin: @yee-form-vertical-label-margin;
  padding: @yee-form-vertical-label-padding;
  line-height: @yee-line-height-base;
  white-space: initial;
  text-align: left;

  label::after {
    display: none;
  }
}

.yee-make-vertical-layout() {
  .@{yee-form-prefix-cls}-item-label,
  .@{yee-form-prefix-cls}-item-control-wrapper {
    display: block;
    width: 100%;
  }
  .@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

.@{yee-form-prefix-cls}-vertical .@{yee-form-prefix-cls}-item-label,
  // when labelCol is 24, it is a vertical form
.@{yee-prefix}-col-24.@{yee-form-prefix-cls}-item-label,
.@{yee-prefix}-col-xl-24.@{yee-form-prefix-cls}-item-label {
  .yee-make-vertical-layout-label();
}

.@{yee-form-prefix-cls}-vertical {
  .@{yee-form-prefix-cls}-item {
    padding-bottom: 8px;
  }
  .@{yee-form-prefix-cls}-item-control {
    line-height: @yee-line-height-base;
  }
  .@{yee-form-prefix-cls}-explain {
    margin-top: 2px;
    margin-bottom: -4px - @yee-form-explain-precision;
  }
  .@{yee-form-prefix-cls}-extra {
    margin-top: 2px;
    margin-bottom: -4px;
  }
}

@media (max-width: @yee-screen-xs-max) {
  .yee-make-vertical-layout();
  .@{yee-prefix}-col-xs-24.@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

@media (max-width: @yee-screen-sm-max) {
  .@{yee-prefix}-col-sm-24.@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

@media (max-width: @yee-screen-md-max) {
  .@{yee-prefix}-col-md-24.@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

@media (max-width: @yee-screen-lg-max) {
  .@{yee-prefix}-col-lg-24.@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

@media (max-width: @yee-screen-xl-max) {
  .@{yee-prefix}-col-xl-24.@{yee-form-prefix-cls}-item-label {
    .yee-make-vertical-layout-label();
  }
}

//== Inline Form
.@{yee-form-prefix-cls}-inline {
  .@{yee-form-prefix-cls}-item {
    display: inline-block;
    margin-right: 16px;
    margin-bottom: 0;

    &-with-help {
      margin-bottom: @yee-form-item-margin-bottom;
    }

    > .@{yee-form-prefix-cls}-item-control-wrapper,
    > .@{yee-form-prefix-cls}-item-label {
      display: inline-block;
      vertical-align: top;
    }
  }

  .@{yee-form-prefix-cls}-text {
    display: inline-block;
  }

  .has-feedback {
    display: inline-block;
  }
}

// Validation state
.has-success,
.has-warning,
.has-error,
.is-validating {
  &.has-feedback .@{yee-form-prefix-cls}-item-children-icon {
    position: absolute;
    top: 50%;
    right: 0;
    z-index: 1;
    width: @yee-form-component-height;
    height: 20px;
    margin-top: -10px;
    font-size: @yee-form-feedback-icon-size;
    line-height: 20px;
    text-align: center;
    visibility: visible;
    animation: zoomIn 0.3s @yee-ease-out-back;
    pointer-events: none;

    & svg {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: auto;
    }
  }
}

.has-success {
  &.has-feedback .@{yee-form-prefix-cls}-item-children-icon {
    color: @yee-success-color;
    animation-name: diffZoomIn1 !important;
  }
}

.has-warning {
  .yee-form-control-validation(@yee-warning-color; @yee-warning-color; @yee-form-warning-input-bg;);

  &.has-feedback .@{yee-form-prefix-cls}-item-children-icon {
    color: @yee-warning-color;
    animation-name: diffZoomIn3 !important;
  }

  //select
  .@{yee-prefix}-select {
    &-selection {
      border-color: @yee-warning-color;
      &:hover {
        border-color: @yee-warning-color;
      }
    }
    &-open .@{yee-prefix}-select-selection,
    &-focused .@{yee-prefix}-select-selection {
      .yee-active(@yee-warning-color);
    }
  }

  // arrow and icon
  .@{yee-prefix}-calendar-picker-icon::after,
  .@{yee-prefix}-time-picker-icon::after,
  .@{yee-prefix}-picker-icon::after,
  .@{yee-prefix}-select-arrow,
  .@{yee-prefix}-cascader-picker-arrow {
    color: @yee-warning-color;
  }

  //input-number, timepicker
  .@{yee-prefix}-input-number,
  .@{yee-prefix}-time-picker-input {
    border-color: @yee-warning-color;
    &-focused,
    &:focus {
      .yee-active(@yee-warning-color);
    }
    &:not([disabled]):hover {
      border-color: @yee-warning-color;
    }
  }

  .@{yee-prefix}-cascader-picker {
    &:focus .@{yee-prefix}-cascader-input {
      .yee-active(@yee-warning-color);
    }
    &:hover .@{yee-prefix}-cascader-input {
      border-color: @yee-warning-color;
    }
  }
}

.has-error {
  .yee-form-control-validation(@yee-error-color; @yee-error-color; @yee-form-error-input-bg;);

  &.has-feedback .@{yee-form-prefix-cls}-item-children-icon {
    color: @yee-error-color;
    animation-name: diffZoomIn2 !important;
  }

  //select
  .@{yee-prefix}-select {
    &-selection {
      border-color: @yee-error-color;
      &:hover {
        border-color: @yee-error-color;
      }
    }
    &-open .@{yee-prefix}-select-selection,
    &-focused .@{yee-prefix}-select-selection {
      .yee-active(@yee-error-color);
    }
  }

  .@{yee-prefix}-select.@{yee-prefix}-select-auto-complete {
    .@{yee-prefix}-input:focus {
      border-color: @yee-error-color;
    }
  }

  .@{yee-prefix}-input-group-addon .@{yee-prefix}-select {
    &-selection {
      border-color: transparent;
      box-shadow: none;
    }
  }

  // arrow and icon
  .@{yee-prefix}-calendar-picker-icon::after,
  .@{yee-prefix}-time-picker-icon::after,
  .@{yee-prefix}-picker-icon::after,
  .@{yee-prefix}-select-arrow,
  .@{yee-prefix}-cascader-picker-arrow {
    color: @yee-error-color;
  }

  //input-number, timepicker
  .@{yee-prefix}-input-number,
  .@{yee-prefix}-time-picker-input {
    border-color: @yee-error-color;
    &-focused,
    &:focus {
      .yee-active(@yee-error-color);
    }
    &:not([disabled]):hover {
      border-color: @yee-error-color;
    }
  }
  .@{yee-prefix}-mention-wrapper {
    .@{yee-prefix}-mention-editor {
      &,
      &:not([disabled]):hover {
        border-color: @yee-error-color;
      }
    }
    &.@{yee-prefix}-mention-active:not([disabled]) .@{yee-prefix}-mention-editor,
    .@{yee-prefix}-mention-editor:not([disabled]):focus {
      .yee-active(@yee-error-color);
    }
  }

  .@{yee-prefix}-cascader-picker {
    &:focus .@{yee-prefix}-cascader-input {
      .yee-active(@yee-error-color);
    }
    &:hover .@{yee-prefix}-cascader-input {
      border-color: @yee-error-color;
    }
  }

  // transfer
  .@{yee-prefix}-transfer {
    &-list {
      border-color: @yee-error-color;

      &-search:not([disabled]) {
        border-color: @yee-input-border-color;

        &:hover {
          .yee-hover();
        }

        &:focus {
          .yee-active();
        }
      }
    }
  }
}

.is-validating {
  &.has-feedback .@{yee-form-prefix-cls}-item-children-icon {
    display: inline-block;
    color: @yee-primary-color;
  }
}

.@{yee-prefix}-advanced-search-form {
  .@{yee-form-prefix-cls}-item {
    margin-bottom: @yee-form-item-margin-bottom;

    &-with-help {
      margin-bottom: @yee-form-item-margin-bottom - @yee-form-explain-height - @yee-form-help-margin-top;
    }
  }
}

.yee-show-help-motion(@yee-className, @keyframeName, @yee-duration: @yee-animation-duration-slow) {
  .yee-make-motion(@yee-className, @keyframeName, @yee-duration);
  .@{yee-className}-enter,
  .@{yee-className}-appear {
    opacity: 0;
    animation-timing-function: @yee-ease-in-out;
  }
  .@{yee-className}-leave {
    animation-timing-function: @yee-ease-in-out;
  }
}

.yee-show-help-motion(show-help, antShowHelp, 0.3s);

@keyframes antShowHelpIn {
  0% {
    transform: translateY(-5px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes antShowHelpOut {
  to {
    transform: translateY(-5px);
    opacity: 0;
  }
}

// need there different zoom animation
// otherwise won't trigger anim
@keyframes diffZoomIn1 {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes diffZoomIn2 {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes diffZoomIn3 {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}
