@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: ~'@{clinia-prefix}-form';
@form-component-height: @input-height-base;
@form-component-max-height: @input-height-lg;
@form-feedback-icon-size: @font-size-base;
@form-help-margin-top: (@form-component-height - @form-component-max-height) / 2 + 2px;

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

.@{form-prefix-cls}-item-required:before {
  display: inline-block;
  margin-right: 4px;
  content: '*';
  line-height: 1;
  font-size: @font-size-base;
  color: @label-required-color;
  .@{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
.@{clinia-prefix}-radio-inline,
.@{clinia-prefix}-radio-vertical,
.@{clinia-prefix}-checkbox-inline,
.@{clinia-prefix}-checkbox-vertical {
  &.disabled {
    cursor: not-allowed;
  }
}

// These classes are used on elements with <label> descendants
.@{clinia-prefix}-radio,
.@{clinia-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} {
      vertical-align: top;
      font-size: @font-size-base;
    }
  }

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

  &-control {
    line-height: @form-component-max-height - 0.0001px; // https://github.com/ant-design/ant-design/issues/8220
    position: relative;
    .clearfix;
  }

  &-children {
    position: relative;
  }

  &-with-help {
    margin-bottom: @form-item-margin-bottom - @font-size-base * @line-height-base -
      @form-help-margin-top;
  }

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

    label {
      color: @label-color;
      font-size: @font-size-md;
      font-weight: @font-weight-bold;
      line-height: 22px;
      font-family: @title-font-family;

      &:after {
        & when (@form-item-trailing-colon=true) {
          content: ':';
        }
        & when not (@form-item-trailing-colon=true) {
          content: ' ';
        }
        margin: 0 8px 0 2px;
        position: relative;
        top: -0.5px;
      }
    }
  }

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

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

.@{form-prefix-cls}-explain,
.@{form-prefix-cls}-extra {
  color: @text-color-secondary;
  // Magic tweak pixel number to float line-height diff in windows
  // Fix https://github.com/ant-design/ant-design/issues/12803
  line-height: @line-height-base + 0.024;
  transition: color 0.3s @ease-out; // sync input color transition
  margin-top: @form-help-margin-top;
  clear: both;
}

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

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

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

form {
  .has-feedback {
    .@{clinia-prefix}-input {
      padding-right: 24px;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  .@{clinia-prefix}-select-selection--single {
    margin-left: -1px;
    height: @input-height-lg;
    background-color: #eee;
    .@{clinia-prefix}-select-selection__rendered {
      padding-left: 8px;
      padding-right: 25px;
      line-height: 30px;
    }
  }

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

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

  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
.@{clinia-prefix}-col-24.@{form-prefix-cls}-item-label,
.@{clinia-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,
  .@{form-prefix-cls}-extra {
    margin-top: 2px;
    margin-bottom: -4px;
  }
}

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

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

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

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

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

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

    &-with-help {
      margin-bottom: 24px;
    }

    > .@{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;
    visibility: visible;
    pointer-events: none;
    width: @form-component-height;
    height: 20px;
    line-height: 20px;
    margin-top: -10px;
    text-align: center;
    font-size: @form-feedback-icon-size;
    animation: zoomIn 0.3s @ease-out-back;
    z-index: 1;

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

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

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

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

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

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

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

  .@{clinia-prefix}-cascader-picker:focus .@{clinia-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 !important;
  }

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

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

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

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

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

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

  // transfer
  .@{clinia-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;
  }
}

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

    &-with-help {
      margin-bottom: @form-item-margin-bottom - @font-size-base * @line-height-base -
        @form-help-margin-top;
    }
  }
}

.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% {
    opacity: 0;
    transform: translateY(-5px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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