load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte_check")
load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test")
load("//ts:esbuild.bzl", "esbuild")
load("//ts:compile_sass.bzl", "compile_sass")
load("//ts:typescript.bzl", "typescript")

compile_sass(
    srcs = [
        "editor-base.scss",
        "legacy.scss",
    ],
    group = "editor_css",
    visibility = ["//visibility:public"],
    deps = [
        "//sass:base_lib",
        "//sass:button_mixins_lib",
        "//sass:scrollbar_lib",
    ],
)

_ts_deps = [
    "//ts/components",
    "//ts/editable:editable_ts",
    "//ts/html-filter",
    "//ts/lib",
    "//ts/domlib",
    "//ts/sveltelib",
    "@npm//@fluent",
    "@npm//@types/codemirror",
    "@npm//codemirror",
    "@npm//svelte",
]

compile_svelte(deps = _ts_deps)

typescript(
    name = "editor",
    deps = _ts_deps + [
        ":svelte",
    ],
)

_esbuild_deps = [
    ":editor",
    ":editor_css",
    "//sass:button_mixins_lib",
    "@npm//@mdi",
    "@npm//bootstrap-icons",
    "//ts/icons",
    "@npm//protobufjs",
]

esbuild(
    name = "browser_editor",
    args = {
        "loader": {".svg": "text"},
    },
    entry_point = "index_browser.ts",
    output_css = "browser_editor.css",
    visibility = ["//visibility:public"],
    deps = _esbuild_deps,
)

esbuild(
    name = "reviewer_editor",
    args = {
        "loader": {".svg": "text"},
    },
    entry_point = "index_reviewer.ts",
    output_css = "reviewer_editor.css",
    visibility = ["//visibility:public"],
    deps = _esbuild_deps,
)

esbuild(
    name = "note_creator",
    args = {
        "loader": {".svg": "text"},
    },
    entry_point = "index_creator.ts",
    output_css = "note_creator.css",
    visibility = ["//visibility:public"],
    deps = _esbuild_deps,
)

# Tests
################

prettier_test()

eslint_test()

svelte_check(
    name = "svelte_check",
    srcs = glob([
        "**/*.ts",
        "**/*.svelte",
    ]) + [
        "//sass:button_mixins_lib",
        "//sass/bootstrap",
        "//ts/components",
        "//ts/editable:editable_ts",
        "@npm//@types/bootstrap",
        "@npm//@types/codemirror",
        "@npm//codemirror",
    ],
)
