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

@form-prefix-cls: ~'@{yg-prefix}-form';
@form-component-height: @input-height-base;
@form-component-max-height: 30px;// @input-height-lg;
@form-feedback-icon-size: @font-size-base;
@form-help-margin-top: 2px;
@form-explain-font-size: @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
@form-explain-precision: 1px;
@form-explain-height: 20px;// floor(@form-explain-font-size * @line-height-base);

@feedbackwith: @input-width-sm - 14px;
@selectfeedwidth: @input-width-sm - 42px;

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

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

// Radio && Checkbox
input[type='radio'],
input[type='checkbox'] {
  &[disabled],
  &.disabled {
    cursor: not-allowed;
  }
}

// These classes are used directly on <label>s
.@{yg-prefix}-radio-inline,
.@{yg-prefix}-radio-vertical,
.@{yg-prefix}-checkbox-inline,
.@{yg-prefix}-checkbox-vertical {
  &.disabled {
    cursor: not-allowed;
  }
}

// These classes are used on elements with <label> descendants
.@{yg-prefix}-radio,
.@{yg-prefix}-checkbox {
  &.disabled {
    label {
      cursor: not-allowed;
    }
  }
}

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

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

  .reset-component;
  margin-bottom: @form-item-margin-bottom;
  vertical-align: top;

  &-control {
    position: relative;
    .clearfix;
  }

  &-children {
    position: relative;
  }

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

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

    &-left {
      text-align: left;
    }

    > label {
      color: @label-color;
      margin-right: 5px;
    }
  }

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

  &-no-colon &-label label::after {
    content: ' ';
  }
}

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

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

.@{form-prefix-cls}-text {
  display: inline-block;
  padding-right: 8px;
  line-height: @form-component-max-height;
}
.@{form-prefix-cls}-item-control .@{yg-prefix}-radio-group{
  line-height: @form-component-max-height;
}
.@{form-prefix-cls}-item-control .@{yg-prefix}-checkbox-group{
  line-height: @form-component-max-height;
}
.@{form-prefix-cls}-item-control .@{yg-prefix}-row{
  width: 100%;
}
.@{form-prefix-cls}-split {
  display: block;
  text-align: center;
}

// 表单下的输入框尺寸唯一: 大尺寸
form {
  .has-feedback {
    .@{yg-prefix}-input {
      padding-right: 24px;
      width: @feedbackwith;
    }

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

    .@{yg-prefix}-cascader-picker {
      &-arrow {
        margin-right: 17px;
      }
      &-clear {
        right: 28px;
      }
    }

    // Fix issue: https://github.com/ant-design/ant-design/issues/7854
    .@{yg-prefix}-input-search:not(.@{yg-prefix}-input-search-enter-button) {
      .@{yg-prefix}-input-suffix {
        right: 28px;
      }
    }

    // Fix issue: https://github.com/ant-design/ant-design/issues/4783
    .@{yg-prefix}-calendar-picker,
    .@{yg-prefix}-time-picker {
      &-icon,
      &-clear {
        right: 28px;
      }
    }
  }

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

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

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

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

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

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

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

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

  .@{yg-prefix}-select,
  .@{yg-prefix}-cascader-picker,
  .@{yg-prefix}-input-number {
    width: @input-width-sm + 22px;
  }

  .@{yg-prefix}-select-selection-selected-value{
    width: @input-width-sm;
  }
  .@{yg-prefix}-cascader-picker-arrow{
    right: 10px;
  }
  // Don't impact select inside input group
  .@{yg-prefix}-input-group .@{yg-prefix}-select,
  .@{yg-prefix}-input-group .@{yg-prefix}-cascader-picker {
    width: auto;
  }

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

// Input combined with select
.@{yg-prefix}-input-group-wrap {
  .@{yg-prefix}-select-selection {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    &:hover {
      border-color: @border-color-base;
    }
  }

  .@{yg-prefix}-select-selection--single {
    height: @input-height-lg;
    margin-left: -1px;
    background-color: fade(@black, 7%);
    .@{yg-prefix}-select-selection__rendered {
      padding-right: 25px;
      padding-left: 8px;
      line-height: 30px;
    }
  }

  .@{yg-prefix}-select-open .@{yg-prefix}-select-selection {
    border-color: @border-color-base;
    box-shadow: none;
  }
}

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

  label::after {
    display: none;
  }
}

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

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

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

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

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

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

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

@media (max-width: @screen-xl-max) {
  .@{yg-prefix}-col-xl-24.@{form-prefix-cls}-item-label {
    .make-vertical-layout-label();
  }
}
.@{form-prefix-cls}-horizontal {
  .@{form-prefix-cls}-item {
    > .@{form-prefix-cls}-item-control-wrapper,
    > .@{form-prefix-cls}-item-label {
      display: inline-block;
      vertical-align: top;
    }
  }
}
//== Inline Form
.@{form-prefix-cls}-inline {
  .@{form-prefix-cls}-item {
    display: inline-block;
    margin-right: 16px;
    margin-bottom: 0;

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

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

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

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

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

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

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

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

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

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

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

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

  .@{yg-prefix}-cascader-picker:focus .@{yg-prefix}-cascader-input {
    .active(@warning-color);
  }
}

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

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

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

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

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

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

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

  .@{yg-prefix}-cascader-picker:focus .@{yg-prefix}-cascader-input {
    .active(@error-color);
  }

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

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

        &:hover {
          .hover();
        }

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

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

.@{yg-prefix}-advanced-search-form {
  .@{yg-prefix}-search-item-one.moreitem {
    display: none;
  }
  .@{form-prefix-cls}-item {
    margin-bottom: @form-item-margin-bottom;

    &-label{
      text-align: right;
      font-size: 12px;
      label{ width: 72px; display: inline-block;}
    }

    &-with-help {
      margin-bottom: @form-item-margin-bottom - @form-explain-height - @form-help-margin-top;
    }
  }
  .@{yg-prefix}-search-item-one.row {
      flex: 0 0 100%;
      text-align: left;
      width: 100%;
  }
}

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

.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);
  }
}
