load(
    "@rules_ruby//ruby:defs.bzl",
    "rb_binary",
    "rb_library",
    "rb_test",
)

package(default_visibility = ["//rb:__subpackages__"])

rb_library(
    name = "atoms",
    srcs = ["atoms.rb"],
    data = [
        "//rb/lib/selenium/webdriver/atoms:find-elements",
        "//rb/lib/selenium/webdriver/atoms:get-attribute",
        "//rb/lib/selenium/webdriver/atoms:is-displayed",
    ],
)

rb_library(
    name = "bidi",
    srcs = glob([
        "bidi/**/*.rb",
        "bidi.rb",
    ]),
    deps = [":common"],
)

rb_binary(
    name = "bidi-generate",
    srcs = ["bidi/support/bidi_generate.rb"],
    args = [
        "$(location //javascript/selenium-webdriver:create-bidi-src_schema)",
        "rb/lib/selenium/webdriver/bidi/protocol",
    ],
    data = [
        "bidi/support/templates/module.rb.erb",
        "bidi/support/templates/module.rbs.erb",
        "//javascript/selenium-webdriver:create-bidi-src_schema",
    ],
    main = "bidi/support/bidi_generate.rb",
)

# Fails if a checked-in protocol .rb was hand-edited or left stale after a generator/schema
# change. Re-renders each module in memory and compares (see check_generated.rb). Fix with
# `bazel run //rb/lib/selenium/webdriver:bidi-generate`.
rb_test(
    name = "verify-bidi-generated",
    size = "small",
    srcs = ["bidi/support/check_generated.rb"],
    args = ["$(rootpath //javascript/selenium-webdriver:create-bidi-src_schema)"],
    data = [
        "bidi/support/bidi_generate.rb",
        "bidi/support/templates/module.rb.erb",
        "//javascript/selenium-webdriver:create-bidi-src_schema",
    ] + glob(
        ["bidi/protocol/*.rb"],
        exclude = ["bidi/protocol/domain.rb"],
    ),
    main = "bidi/support/check_generated.rb",
)

rb_library(
    name = "devtools",
    srcs = glob([
        "devtools/**/*.rb",
        "devtools.rb",
    ]),
    data = ["//rb/lib/selenium/webdriver/atoms:mutation-listener"],
    deps = [":common"],
)

rb_library(
    name = "chromium",
    srcs = glob([
        "chromium/**/*.rb",
        "chromium.rb",
    ]),
    deps = [":common"],
)

rb_library(
    name = "chrome",
    srcs = glob([
        "chrome/**/*.rb",
        "chrome.rb",
    ]),
    deps = [":chromium"],
)

rb_library(
    name = "common",
    srcs = glob([
        "common/**/*.rb",
        "common.rb",
        "support/**/*.rb",
        "support.rb",
    ]),
)

rb_library(
    name = "version",
    srcs = ["version.rb"],
)

rb_library(
    name = "edge",
    srcs = glob([
        "edge/**/*.rb",
        "edge.rb",
    ]),
    deps = [":chromium"],
)

rb_library(
    name = "firefox",
    srcs = glob([
        "firefox/**/*.rb",
        "firefox.rb",
    ]),
    deps = [":common"],
)

rb_library(
    name = "ie",
    srcs = glob([
        "ie/**/*.rb",
        "ie.rb",
    ]),
    deps = [":common"],
)

rb_library(
    name = "remote",
    srcs = glob([
        "remote/**/*.rb",
        "remote.rb",
    ]),
    deps = [":common"],
)

rb_library(
    name = "safari",
    srcs = glob([
        "safari/**/*.rb",
        "safari.rb",
    ]),
    deps = [":common"],
)
