import { Schema } from "effect";
import { Expression, HttpRequestResult, LocaleMarkdown } from "../../../../../share/expression.js";
import { Slot, defaultSlot } from "../../../../../share/layout.js";
export { getStructFieldDescription, getStructFieldTitle } from "../../../../table/utils/schema-meta.js";
export const type = "com.shwfed.block.card";
export const compatibilityDate = "2026-06-02";
export const metadata = {
  name: "\u5361\u7247",
  icon: "fluent:card-ui-20-regular",
  w: { initial: 12, min: 4, max: Infinity },
  h: { initial: 6, min: 4, max: Infinity }
};
export const JSON_VAR = {
  type: "optional<dyn>",
  label: "HTTP \u54CD\u5E94\u4F53",
  description: "HTTP \u54CD\u5E94\u4F53\uFF08\u914D\u7F6E\u4E86\u8BF7\u6C42\u65F6\u4E3A\u5DF2\u89E3\u6790 JSON\uFF0C\u5426\u5219\u4E3A none\uFF09"
};
function registerJson(env) {
  env.registerVariable("json", JSON_VAR.type, {
    label: JSON_VAR.label,
    description: JSON_VAR.description
  });
}
export const BADGE_VARIANTS = ["default", "secondary", "destructive", "outline"];
export function badgeSchema(configure) {
  const CelRequest = Expression({
    configure,
    resultType: HttpRequestResult
  });
  const Content = LocaleMarkdown({
    configure: (env) => {
      configure(env);
      registerJson(env);
    }
  });
  const CelShow = Expression({
    configure: (env) => {
      configure(env);
      registerJson(env);
    },
    resultType: "bool"
  });
  return Schema.Struct({
    request: Schema.optional(CelRequest).annotations({
      title: "\u8BF7\u6C42",
      description: "\u53EF\u9009\u7684 HTTP \u8BF7\u6C42\u8868\u8FBE\u5F0F\uFF08\u8FD4\u56DE `HttpRequest`\uFF09\uFF1B\u672A\u914D\u7F6E\u65F6\u63D2\u503C\u4E2D\u7684 `json` \u4E3A none"
    }),
    content: Schema.optional(Content).annotations({
      title: "\u5185\u5BB9",
      description: "\u672C\u5730\u5316\u7684\u5185\u8054 Markdown\uFF0C\u652F\u6301 `{{ \u8868\u8FBE\u5F0F }}` CEL \u63D2\u503C\uFF0C\u53EF\u5F15\u7528 `json`\uFF1B\u7559\u7A7A\u5219\u4E0D\u663E\u793A\u5FBD\u7AE0"
    }),
    show: Schema.optional(CelShow).annotations({
      title: "\u663E\u793A\u6761\u4EF6",
      description: "\u8FD4\u56DE `bool` \u7684\u8868\u8FBE\u5F0F\uFF0C\u53EF\u5F15\u7528 `json`\uFF1B\u8FD4\u56DE `false` \u65F6\u5373\u4F7F `\u5185\u5BB9` \u975E\u7A7A\u4E5F\u4E0D\u663E\u793A\u5FBD\u7AE0\uFF1B\u7559\u7A7A\u5219\u59CB\u7EC8\u663E\u793A\u3002\u5E38\u7528\u4E8E\u5FFD\u7565\u7279\u5B9A\u503C\uFF08\u5982 total \u4E3A 0 \u65F6\u9690\u85CF\uFF09"
    }),
    interval: Schema.optional(
      Schema.Number.pipe(Schema.int(), Schema.positive()).annotations({
        title: "\u8F6E\u8BE2\u95F4\u9694",
        description: "\u8F6E\u8BE2\u5237\u65B0\u95F4\u9694\uFF08\u79D2\uFF09\uFF0C\u6B63\u6574\u6570\uFF1B\u7559\u7A7A\u5219\u4E0D\u8F6E\u8BE2\u3002\u7A97\u53E3\u5931\u7126\u65F6\u6682\u505C\uFF0C\u91CD\u65B0\u805A\u7126\u65F6\u7ACB\u5373\u5237\u65B0\u5E76\u6062\u590D\u8F6E\u8BE2"
      })
    ),
    dot: Schema.optional(Schema.Boolean.annotations({
      title: "\u5706\u70B9",
      description: "\u5F00\u542F\u540E\u5FBD\u7AE0\u6298\u53E0\u4E3A\u4E00\u4E2A\u5C0F\u5706\u70B9\uFF08\u4EC5\u4FDD\u7559\u53D8\u4F53\u989C\u8272\uFF0C\u4E0D\u5C55\u793A\u6587\u672C\uFF09"
    })),
    variant: Schema.optional(Schema.Literal(...BADGE_VARIANTS).annotations({
      title: "\u6837\u5F0F\u53D8\u4F53",
      description: "\u5FBD\u7AE0\u5916\u89C2\uFF1A`default` | `secondary` | `destructive` | `outline`\uFF1B\u7559\u7A7A\u7B49\u540C `default`"
    }))
  }).annotations({
    title: "\u5FBD\u7AE0",
    description: "\u5361\u7247\u53F3\u4E0A\u89D2\u5FBD\u7AE0\uFF1B`\u5185\u5BB9` \u7559\u7A7A\u5219\u4E0D\u663E\u793A"
  });
}
export function schema(configure, blockRef) {
  const CardSlot = Slot(blockRef, configure);
  const CelStyle = Expression({
    configure,
    resultType: (t) => t === "string" || t === "dyn" || t.startsWith("map") || t.startsWith("optional")
  });
  const CelUrl = Expression({
    configure,
    resultType: (t) => t === "string" || t === "dyn" || t.startsWith("optional")
  });
  return Schema.Struct({
    id: Schema.UUID.annotations({ description: "\u5757\u552F\u4E00\u6807\u8BC6" }),
    type: Schema.tag(type),
    compatibilityDate: Schema.tag(compatibilityDate),
    displayName: Schema.optional(Schema.String.annotations({
      title: "\u5185\u90E8\u540D\u79F0",
      description: "\u4EC5\u5728\u7F16\u8F91\u5668\u5185\u53EF\u89C1\u7684\u5757\u540D\uFF0C\u7528\u4E8E\u5728\u4FA7\u8FB9\u680F\u548C\u5E03\u5C40\u7F16\u8F91\u5668\u4E2D\u8BC6\u522B\u5757\uFF1B\u8FD0\u884C\u65F6\u4E0D\u5C55\u793A"
    })),
    style: Schema.optional(CelStyle).annotations({
      title: "\u6837\u5F0F",
      description: "\u8FD4\u56DE\u5E94\u7528\u5728\u5361\u7247\u6839\u5143\u7D20\u4E0A\u7684\u6837\u5F0F\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u53EF\u8FD4\u56DE CSS \u5B57\u7B26\u4E32\uFF08\u5982 `'padding: 2rem'`\uFF09\u6216\u6837\u5F0F\u5BF9\u8C61\uFF08\u5982 `{'padding': '2rem'}`\uFF09\uFF1B\u7559\u7A7A\u5219\u4E0D\u8BBE\u989D\u5916\u6837\u5F0F"
    }),
    url: Schema.optional(CelUrl).annotations({
      title: "\u94FE\u63A5",
      description: "\u8FD4\u56DE `string` \u7684 CEL \u8868\u8FBE\u5F0F\uFF1B\u914D\u7F6E\u540E\u70B9\u51FB\u5361\u7247\u7A7A\u767D\u5904\u5C06\u901A\u8FC7\u8DEF\u7531\u8DF3\u8F6C\u5230\u8BE5\u94FE\u63A5\uFF08\u7ECF `NuxtLink`\uFF0C\u9075\u5FAA\u5E94\u7528 base URL\uFF09\u3002\u70B9\u51FB\u5361\u7247\u5185\u7684\u6309\u94AE\u3001\u94FE\u63A5\u7B49\u4EA4\u4E92\u5143\u7D20\u4E0D\u4F1A\u89E6\u53D1"
    }),
    badge: Schema.optional(badgeSchema(configure)).annotations({
      title: "\u5FBD\u7AE0",
      description: "\u5361\u7247\u53F3\u4E0A\u89D2\u5FBD\u7AE0\uFF1B\u7559\u7A7A\u5219\u4E0D\u663E\u793A"
    }),
    slot: CardSlot.annotations({
      title: "\u5185\u5BB9",
      description: "\u5361\u7247\u5185\u90E8\u7684\u5757\u4E0E\u5E03\u5C40"
    })
  }).annotations({
    title: "\u5361\u7247\u5757",
    description: "\u5E26\u53EF\u9009\u5FBD\u7AE0\u7684\u6837\u5F0F\u5316\u5BB9\u5668\uFF0C\u53EF\u653E\u5165\u4EFB\u610F\u5757\u4E0E\u5E03\u5C40\uFF1B\u652F\u6301\u4EFB\u610F\u5C42\u7EA7\u5D4C\u5957"
  });
}
export function defaultBody() {
  return { slot: defaultSlot() };
}
