import { baseTheme } from '@toeverything/theme';
import { css, unsafeCSS } from 'lit';

const editAIStyle = css`
  .flex {
    display: flex;
  }
  .align-center {
    align-items: center;
  }
  .none {
    display: none;
  }
  .affine-ai-edit-popover {
    box-sizing: border-box;
    width: 404px;
    height: 112px;
    padding: 12px;
    box-shadow: var(--affine-shadow-2);
    background: var(--affine-background-overlay-panel-color);
    border-radius: 8px;
    display: grid;
    grid-template-columns: auto auto auto;
    grid-template-rows: repeat(2, 1fr);
    gap: 12px;
    grid-template-areas:
      'text-area .'
      'ai-area btn';
    justify-items: center;
    align-items: center;
    /* breaks 'basic ai' test in chromium */
    /* user-select: none; */
  }

  .affine-edit-text-area {
    grid-area: text-area;
    width: 338px;
    display: grid;
    gap: 6px;
    grid-template-columns: auto auto auto;
    grid-template-rows: repeat(1, 1fr);
    grid-template-areas: 'text span text-input';
    justify-items: center;
    align-items: center;
    user-select: none;
  }

  .affine-edit-ai-area {
    grid-area: ai-area;
    width: 338px;
    display: grid;
    gap: 6px;
    grid-template-columns: auto auto auto;
    grid-template-rows: repeat(1, 1fr);
    grid-template-areas: 'ai span ai-input';
    justify-items: center;
    align-items: center;
  }

  .affine-ai-popover-dividing-line {
    grid-area: span;
  }
  .affine-edit-text-text {
    grid-area: text;
  }

  .affine-edit-text-input {
    grid-area: text-input;
  }

  .affine-edit-ai-text {
    grid-area: ai;
  }

  .affine-edit-ai-input {
    grid-area: ai-input;
  }

  .affine-confirm-button {
    grid-area: btn;
    user-select: none;
  }
`;

export const AIPopupStyle = css`
  :host {
    box-sizing: border-box;
  }

  .mock-selection {
    position: absolute;
    background-color: rgba(35, 131, 226, 0.28);
  }

  .popup-container {
    font-family: ${unsafeCSS(baseTheme.fontSansFamily)};
    font-size: var(--affine-font-base);
    font-style: normal;
    line-height: 24px;
    color: var(--affine-text-primary-color);
    z-index: var(--affine-z-index-popover);
    animation: affine-popover-fade-in 0.2s ease;
    position: absolute;
    min-height: 500px;
  }

  @keyframes affine-popover-fade-in {
    from {
      opacity: 0;
      transform: translateY(-3px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .overlay-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: var(--affine-z-index-popover);
  }
  .affine-edit-text-area {
    border: 1px solid var(--affine-border-color);
    outline: none;
    border-radius: 10px;
    background: transparent;
  }
  .affine-edit-text-area:focus-within {
    border: 1px solid var(--affine-primary-color);
  }
  .affine-edit-ai-area {
    border: 1px solid var(--affine-border-color);
    outline: none;
    border-radius: 10px;
    background: transparent;
  }
  .affine-edit-ai-area:focus-within {
    border: 1px solid var(--affine-primary-color);
  }

  label {
    font-family: ${unsafeCSS(baseTheme.fontSansFamily)};
    font-size: var(--affine-font-sm);
    box-sizing: border-box;
    padding: 6px 0 6px 12px;
    color: var(--affine-icon-color);
  }

  input {
    font-family: ${unsafeCSS(baseTheme.fontSansFamily)};
    font-size: var(--affine-font-base);
    box-sizing: border-box;
    padding: 6px 12px 6px 0;
    width: 260px;
    height: 34px;
    color: inherit;
    border: none;
    background: transparent;
  }
  input::placeholder {
    color: var(--affine-placeholder-color);
  }
  input:focus {
    outline: none;
  }
  input:focus ~ label,
  input:active ~ label {
    color: var(--affine-primary-color);
  }

  .affine-ai-popover {
    width: 100%;
  }

  .affine-ai-popover-chat {
    width: 100%;
    max-width: 370px;
    padding: 8px;
    background: var(--affine-background-overlay-panel-color);
    box-shadow: var(--affine-shadow-2);
    border-radius: 8px;
  }

  .affine-ai-popover-menu {
    display: none;

    margin-top: 6px;
    width: 100%;
    font-size: var(--affine-font-sm);
    box-sizing: border-box;
    min-width: 178px;
    padding: 8px 8px;
    max-height: 370px;
    overflow-y: auto;

    background: var(--affine-background-overlay-panel-color);
    box-shadow: var(--affine-shadow-2);
    border-radius: 8px;
    z-index: var(--affine-z-index-popover);
  }

  .menu-panel-heading {
    color: var(--affine-text-secondary-color);
    padding: 4px;
  }

  .ai-pre-icon {
    padding-right: 10px;
    display: flex;
    align-items: center;
    height: 100%;
  }
  .ai-pre-icon svg {
    color: #a680c2;
    width: 18px;
    hright: 18px;
  }

  .affine-ai-popover-input {
    border: none;
  }
  .affine-ai-popover-input::placeholder {
    color: var(--affine-placeholder-color);
  }
  .affine-ai-popover-input:focus {
    border: none;
  }

  .affine-ai-popover-input-loading {
    box-sizing: border-box;
    font-family: Inter, 'Source Sans 3', Poppins, apple-system,
      BlinkMacSystemFont, 'Helvetica Neue', Tahoma, 'PingFang SC',
      'Microsoft Yahei', Arial, 'Hiragino Sans GB', sans-serif,
      'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
      'Noto Color Emoji';
    font-size: var(--affine-font-base);
    padding: 6px 12px 6px 0px;
    width: 260px;
    height: 34px;
    color: inherit;
    background: transparent;
  }

  .affine-ai-popover-input-loading span {
    display: flex;
    align-items: center;
  }

  .affine-ai-popover-input-loading .loading,
  .affine-ai-popover-input-loading .loading > div {
    position: relative;
    box-sizing: border-box;
  }

  .affine-ai-popover-input-loading .loading {
    display: block;
    font-size: 0;
    color: #000;
  }

  .affine-ai-popover-input-loading .loading.la-dark {
    color: #333;
  }

  .affine-ai-popover-input-loading .loading > div {
    display: inline-block;
    float: none;
    background-color: currentColor;
    border: 0 solid currentColor;
  }

  .affine-ai-popover-input-loading .loading {
    width: 54px;
    height: 18px;
  }

  .affine-ai-popover-input-loading .loading > div {
    width: 10px;
    height: 10px;
    margin: 4px;
    border-radius: 100%;
    animation: ball-beat 0.7s -0.15s infinite linear;
  }

  .affine-ai-popover-input-loading .loading > div:nth-child(2n-1) {
    animation-delay: -0.5s;
  }

  @keyframes ball-beat {
    50% {
      opacity: 0.2;
      transform: scale(0.75);
    }

    100% {
      opacity: 1;
      transform: scale(1);
    }
  }

  .affine-ai-preview {
    width: 260px;
    height: 28px;
    display: flex;
    align-items: center;
    user-select: none;
    cursor: pointer;
    white-space: nowrap;
  }

  .affine-ai-popover-dividing-line {
    margin: 0 6px;
    width: 1px;
    height: 20px;
    background-color: var(--affine-border-color);
  }

  ${editAIStyle}
`;
