import styled, {createGlobalStyle} from 'styled-components';
import {
  spacing,
  fontNormal,
  gray95,
  actionColor,
  borderRadius,
  black,
  errorColor,
} from '@propellerads/stylevariables';

const StyledCodeviewer = styled.div`
  position: relative;
  margin: 0;
`;

const CodeviewerCopyButton = styled.button`
    width: ${spacing * 8}px;
    height: ${spacing * 8}px;
    background-color: ${gray95};
    border: 0;
    border-radius: ${borderRadius}px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    right: 0;
    top: 0;
    outline: none;
    cursor: pointer;
    
    svg {
      pointer-events: none;
    }
    
    &:hover {
        svg {
          fill: ${actionColor}
        }
    }
`;

const CommonCodeViewerStyles = createGlobalStyle`
/**
 * VS theme by Andrew Lock (https://andrewlock.net)
 * Inspired by Visual Studio syntax coloring
 */

code[class*="language-"],
pre[class*="language-"] {
    color: #393a34;
    font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;
    direction: ltr;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    font-size: 14px;
    line-height: 1.2em;
    -webkit-font-smoothing: initial;
    tab-size: 4;

    hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
    background: #c1def1;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
    background: #c1def1;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
    padding: 1px .2em;
    background: #f8f8f8;
    border: 1px solid #dddddd;
}

.token {
  -webkit-font-smoothing: initial;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #008000; font-style: italic;
}

.token.namespace {
    opacity: .7;
}

.token.string {
    color: #a31515;
}

.token.punctuation,
.token.operator {
    color: #393a34; /* no highlight */
}

.token.url,
.token.symbol,
.token.number,
.token.boolean,
.token.variable,
.token.constant,
.token.inserted {
    color: #36acaa;
}

.token.atrule,
.token.keyword,
.token.attr-value,
.language-autohotkey .token.selector,
.language-json .token.boolean,
.language-json .token.number,
code[class*="language-css"] {
    color: #0000ff;
}

.token.function {
    color: #393a34;
}
.token.deleted,
.language-autohotkey .token.tag {
    color: #9a050f;
}

.token.selector,
.language-autohotkey .token.keyword {
    color: #00009f;
}

.token.important,
.token.bold {
    font-weight: bold;
}

.token.italic {
    font-style: italic;
}

.token.class-name,
.language-json .token.property {
    color: #2b91af;
}

.token.tag,
.token.selector {
    color: #800000;
}

.token.attr-name,
.token.property,
.token.regex,
.token.entity {
    color: #ff0000;
}

.token.directive.tag  .tag {
    background: #ffff00;
    color: #393a34;
}

/* overrides color-values for the Line Numbers plugin
 * http://prismjs.com/plugins/line-numbers/
 */
.line-numbers .line-numbers-rows {
    border-right-color: #a5a5a5;
}

.line-numbers-rows > span:before {
    color: #2b91af;
}

/* overrides color-values for the Line Highlight plugin
* http://prismjs.com/plugins/line-highlight/
*/
.line-highlight {
    background: rgba(193, 222, 241, 0.2);
    background: linear-gradient(to right, rgba(193, 222, 241, 0.2) 70%, rgba(221, 222, 241, 0));
}

  //OVERWRITE
    code {
      .token {
        &.tag,
        &.attr-name {
          color: ${black} !important;
        }

        &.attr-value {
          color: ${errorColor} !important;

          & * {
            color: inherit !important;
          }
        }
      }
    }
    
  pre[class*="language-"] {
    overflow: auto!important;
    padding: ${spacing * 2}px!important;
    background: ${gray95}!important;
    font-size: ${fontNormal}px!important;
    margin: 0 0 ${spacing * 2}px!important;
    border-radius: ${borderRadius}px!important;
    border: none!important;
    user-select: all;
}
`;

export {StyledCodeviewer, CodeviewerCopyButton, CommonCodeViewerStyles};
