import { css } from '@emotion/react';
import { cssAbsolute } from './position';
import { mq, breakpoints } from './mq';

export const cssArticle = css`
  b,
  strong,
  em {
    font-weight: bold;
  }
  code {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    padding: 0.2rem;
    margin-top: 0;
    border-radius: 0.25rem;
  }
  p,
  div,
  ul,
  ol {
    margin: 0.5rem 0 2rem;
  }
  h2 + p,
  h2 + ul,
  h3 + p,
  h3 + ul {
    margin-top: 1rem;
  }
  h2 + h3 {
    margin-top: 0.5rem;
  }
  figure,
  img,
  video,
  iframe,
  table,
  blockquote,
  pre,
  div:not(.remark-code-title) {
    margin: 2rem 0 0.5rem;
  }
  h2,
  h3,
  h4 {
    font-weight: bold;
    margin: 3rem 0 0.5rem;
    border-color: rgb(0, 0, 0);
    border-style: solid;
    border-width: 0;
  }

  h2 {
    font-size: 2rem;
    border-bottom-width: 4px;
  }

  h3 {
    font-size: 1.6rem;
    border-bottom-width: 2px;
  }

  h4 {
    font-size: 1.3rem;
    border-bottom-width: 1px;
  }

  ul,
  ol {
    li {
      margin: 0 0 0.4rem 1.2rem;

      ul {
        margin: 0.4rem 0 0.8rem;
      }
    }
  }
  ul {
    list-style-type: disc;
  }
  ol {
    list-style-type: decimal;
  }

  blockquote {
    position: relative;
    background-color: rgb(220, 220, 220);
    padding: 1.1rem 1rem 1rem 3.4rem;
    p {
      margin: 0.5rem 0 0.5rem;
    }
    &:before {
      content: '>';
      font-size: 3rem;
      display: block;
      ${cssAbsolute(['0.2rem', null, null, '1rem'])}
    }
  }

  table {
    margin-left: auto;
    margin-right: auto;
  }
  th,
  td {
    padding: 0.5rem 0.75rem;
    border: solid 1px rgb(200, 200, 200);
  }

  figure {
    img {
      margin-bottom: 0;
    }
  }
`;

const articleAndMacPadding = 64;

export const cssMainWidth = css`
  ${mq('sm')} {
    max-width: ${breakpoints['sm']}px;
  }
  ${mq('md')} {
    max-width: ${breakpoints['md']}px;
  }
  ${mq('lg')} {
    max-width: ${breakpoints['lg']}px;
  }
  ${mq('xl')} {
    max-width: ${breakpoints['xl']}px;
  }
`;

export const cssArticleWidth = (sidebarWidth = 256) => css`
  max-width: 100%;

  ${mq('lg')} {
    max-width: ${breakpoints['lg'] - articleAndMacPadding - sidebarWidth}px;
  }
  ${mq('xl')} {
    max-width: ${breakpoints['xl'] - articleAndMacPadding - sidebarWidth}px;
  }
`;
