load("@rules_python//python:defs.bzl", "py_binary")
load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test")
load("//ts:protobuf.bzl", "protobufjs_library")
load("//ts:typescript.bzl", "typescript")
load("@py_deps//:requirements.bzl", "requirement")
load("//ts:jest.bzl", "jest_test")

py_binary(
    name = "genfluent",
    srcs = [
        "genfluent.py",
    ],
    deps = [
        requirement("black"),
        "//pylib/anki/_vendor:stringcase",
    ],
)

_i18n_generated = [
    "ftl.ts",
    "i18n/modules.ts",
]

genrule(
    name = "fluent_gen",
    outs = _i18n_generated,
    cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $(OUTS)",
    tools = [
        "genfluent",
        "//rslib/i18n:strings.json",
    ],
)

protobufjs_library(
    name = "backend_proto",
    proto = "//proto:backend_proto_lib",
    visibility = ["//visibility:public"],
)

typescript(
    name = "lib",
    generated = [
        ":backend_proto.d.ts",
        ":ftl.ts",
        ":i18n/modules.ts",
    ],
    deps = [
        ":backend_proto",
        "@npm//@fluent/bundle",
        "@npm//@types/jest",
        "@npm//@types/long",
        "@npm//intl-pluralrules",
        "@npm//protobufjs",
        "@npm//tslib",
    ],
)

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

prettier_test()

eslint_test()

jest_test(
    env = "jsdom",
    deps = [
        ":lib",
    ],
)
