import { createGlobalStyle } from "styled-components";

const EditorGlobalStyles = createGlobalStyle`
  html:root {
    --ck-color-base-foreground: ${({ theme }) => theme.colors.neutral100};
    --ck-color-base-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-base-border: ${({ theme }) => theme.colors.neutral200};
    --ck-color-base-text: ${({ theme }) => theme.colors.neutral800};
    --ck-color-base-active: ${({ theme }) => theme.colors.primary600};
    --ck-color-base-active-focus: ${({ theme }) => theme.colors.primary700};
    --ck-color-focus-border: ${({ theme }) => theme.colors.primary600};
    --ck-color-focus-outer-shadow: ${({ theme }) => theme.colors.primary100};
    --ck-color-text: ${({ theme }) => theme.colors.neutral800};
    --ck-color-shadow-drop: rgba(0, 0, 0, 0.15);
    --ck-color-shadow-inner: transparent;

    --ck-color-toolbar-background: ${({ theme }) => theme.colors.neutral100};
    --ck-color-toolbar-border: ${({ theme }) => theme.colors.neutral200};

    --ck-color-button-default-background: transparent;
    --ck-color-button-default-hover-background: ${({ theme }) => theme.colors.neutral150};
    --ck-color-button-default-active-background: ${({ theme }) => theme.colors.neutral200};
    --ck-color-button-default-disabled-background: transparent;
    --ck-color-button-on-background: ${({ theme }) => theme.colors.primary100};
    --ck-color-button-on-hover-background: ${({ theme }) => theme.colors.primary200};
    --ck-color-button-on-active-background: ${({ theme }) => theme.colors.primary200};
    --ck-color-button-on-color: ${({ theme }) => theme.colors.primary600};

    --ck-color-dropdown-panel-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-dropdown-panel-border: ${({ theme }) => theme.colors.neutral200};
    --ck-color-panel-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-panel-border: ${({ theme }) => theme.colors.neutral200};

    --ck-color-dialog-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-dialog-form-header-border: ${({ theme }) => theme.colors.neutral200};

    --ck-color-list-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-list-button-hover-background: ${({ theme }) => theme.colors.neutral150};
    --ck-color-list-button-on-background: ${({ theme }) => theme.colors.primary600};
    --ck-color-list-button-on-background-focus: ${({ theme }) => theme.colors.primary700};
    --ck-color-list-button-on-text: ${({ theme }) => theme.colors.neutral0};

    --ck-color-input-background: ${({ theme }) => theme.colors.neutral0};
    --ck-color-input-border: ${({ theme }) => theme.colors.neutral200};
    --ck-color-input-text: ${({ theme }) => theme.colors.neutral800};
    --ck-color-input-disabled-background: ${({ theme }) => theme.colors.neutral150};
    --ck-color-input-disabled-border: ${({ theme }) => theme.colors.neutral200};
    --ck-color-input-disabled-text: ${({ theme }) => theme.colors.neutral500};
    --ck-color-labeled-field-label-background: ${({ theme }) => theme.colors.neutral0};

    --ck-color-tooltip-background: ${({ theme }) => theme.colors.neutral900};
    --ck-color-tooltip-text: ${({ theme }) => theme.colors.neutral0};

    --ck-color-toggle-checked-background: ${({ theme }) => theme.colors.primary600};

    --ck-color-widget-blurred-border: ${({ theme }) => theme.colors.neutral200};
    --ck-color-widget-hover-border: ${({ theme }) => theme.colors.primary200};
    --ck-color-widget-editable-focus-background: ${({ theme }) => theme.colors.neutral0};

    --ck-fullscreen-background: ${({ theme }) => theme.colors.neutral100};
  }

  html .ck.ck-fullscreen__main-wrapper {
    background: ${({ theme }) => theme.colors.neutral100};
  }

  html .ck-fullscreen__main-wrapper .ck-fullscreen__editable .ck.ck-editor__editable:not(.ck-editor__nested-editable) {
    background: ${({ theme }) => theme.colors.neutral0};
    border-color: ${({ theme }) => theme.colors.neutral200};
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  }

  .ckstudio-editor .ck.ck-editor__editable_inline {
    min-height: 200px;
  }

  .ck.ck-content.ck-editor__editable {
    color: ${({ theme }) => theme.colors.neutral800};
    background: ${({ theme }) => theme.colors.neutral0};
    font-size: 14px;
    line-height: 1.5;
  }

  .ck.ck-content.ck-editor__editable h1 {
    font-size: 2.3em;
    font-weight: 600;
    line-height: 1.25;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable h2 {
    font-size: 1.9em;
    font-weight: 600;
    line-height: 1.25;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable h3 {
    font-size: 1.55em;
    font-weight: 600;
    line-height: 1.3;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable h4 {
    font-size: 1.3em;
    font-weight: 600;
    line-height: 1.3;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable h5 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable h6 {
    font-size: 0.95em;
    font-weight: 600;
    text-transform: uppercase;
    margin: 0.7em 0 0.35em;
  }

  .ck.ck-content.ck-editor__editable p {
    margin: 0.4em 0;
  }

  .ck.ck-content.ck-editor__editable ul {
    list-style: disc;
    padding-left: 2em;
    margin: 0.4em 0;
  }

  .ck.ck-content.ck-editor__editable ol {
    list-style: decimal;
    padding-left: 2em;
    margin: 0.4em 0;
  }

  .ck.ck-content.ck-editor__editable ul ul {
    list-style: circle;
  }

  .ck.ck-content.ck-editor__editable blockquote {
    border-left: 4px solid ${({ theme }) => theme.colors.neutral300};
    padding-left: 1em;
    font-style: italic;
    margin: 0.8em 0;
  }

  .ck.ck-content.ck-editor__editable a {
    color: ${({ theme }) => theme.colors.primary600};
    text-decoration: underline;
  }

  /* Block spacing dropdown form */
  .ck.ck-spacing-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    min-width: 200px;
  }

  .ck.ck-spacing-form__actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 2px;
  }

  /* Color palette as a labelled list (preset colorLayout: "list") */
  body.ckstudio-colors-list .ck.ck-color-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile {
    width: 100%;
    min-width: 100%;
    height: auto;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--ck-border-radius);
    background-image: linear-gradient(
      var(--ck-color-dropdown-panel-background),
      var(--ck-color-dropdown-panel-background)
    );
    box-shadow: none;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile:hover:not(.ck-disabled),
  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile:focus:not(.ck-disabled) {
    background-image: linear-gradient(
      var(--ck-color-button-default-hover-background),
      var(--ck-color-button-default-hover-background)
    );
    box-shadow: none;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile.ck-on {
    background-image: linear-gradient(
      var(--ck-color-button-on-background),
      var(--ck-color-button-on-background)
    );
    box-shadow: none;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile::before {
    content: "";
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background-color: inherit;
    box-shadow: inset 0 0 0 1px var(--ck-color-base-border);
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile .ck-button__label {
    display: inline-block;
    flex: 1;
    text-align: left;
    color: var(--ck-color-text);
    line-height: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile.ck-on .ck-button__label {
    color: var(--ck-color-button-on-color);
    font-weight: 600;
  }

  body.ckstudio-colors-list .ck.ck-color-grid .ck-color-grid__tile .ck.ck-icon {
    display: none;
  }

  /* Heading dropdown previews flattened by the Strapi admin CSS reset */
  .ck.ck-dropdown__panel .ck-heading_heading1 .ck-button__label {
    font-size: 1.5em;
    font-weight: 600;
  }

  .ck.ck-dropdown__panel .ck-heading_heading2 .ck-button__label {
    font-size: 1.3em;
    font-weight: 600;
  }

  .ck.ck-dropdown__panel .ck-heading_heading3 .ck-button__label {
    font-size: 1.15em;
    font-weight: 600;
  }

  .ck.ck-dropdown__panel .ck-heading_heading4 .ck-button__label {
    font-size: 1.05em;
    font-weight: 600;
  }
`;

export default EditorGlobalStyles;
