import { useProp, useEvent, h } from 'atomico';
import 'funfix';
import { g as getComponentOrDefine } from './chunks/65ef80fe.js';
import '@caedman/gs/dist/global-style';
import './kun-icon.js';
import './kun-button-puer.js';
import './kun-checkbox.js';
import { Maybe } from 'purify-ts/es/Maybe';
import { ConstantExerciseType } from '@caedman/seek-api/build/api/req-create-exercise';

var style = ":host {\n}\n";

const _jsxFileName = "/Users/rang/rang/frond_ng/packages/six/src/components/kun-item-exercise/kun-item-exercise.tsx";
// type ConstantPostType = Value
// final val OPEN = Value(1, "OPEN")
// final val LINK = Value(2, "LINK") // title, link
// final val BOOK = Value(3, "BOOK") // book, link`
// final val CALC = Value(4, "CALC") // book, link`
// final val SELECT = Value(5, "SELECT") // book, link`
// final val ORDER = Value(6, "ORDER") // book, link`
// final val CHECK = Value(7, "CHECK") // book, link`

const getTitle = (type) => {
  if (type === "SELECT") {
    return "选择题";
  }
  if (type === "OPEN") {
    return "问答题";
  }
  if (type === "CALC") {
    return "计算题";
  }
  if (type === "CHECK") {
    return "判断题";
  }
  return "练习题";
};

const defaultSeries = {
  channelId: 50, seriesId: "AR", postId: "den", id: "8ca3c6a0-a13a-11ea-b2de-8583ea9a54e8", exerciseType: "OPEN", background: null, title: "dddd", tips: null, tags: [], correct: [], options: [], answer: "d", editor: "d13e2460-b025-11e9-b2ef-bff457d1b4dd", editorName: "liming", postTitle: null, seriesName: null, seriesType: null,
};

const KunItemExercise = () => {
  const [kunExercise] = useProp("kunExercise");
  const [kunNumber] = useProp("kunNumber");

  const onEdit = useEvent("MyEdit", {
    composed: true,
    bubbles: true,
  });

  const onDelete = useEvent("MyDelete", {
    composed: true,
    bubbles: true,
  });

  const exercise = Maybe.fromNullable(kunExercise).orDefault(defaultSeries);

  const deleteExercise = (exerciseItem) => {
    onDelete(exerciseItem);
  };

  const editExercise = (exerciseItem) => {
    onEdit(exerciseItem);
  };

  return (
    h('host', {__self: undefined, __source: {fileName: _jsxFileName, lineNumber: 68}}
      , h('style', {__self: undefined, __source: {fileName: _jsxFileName, lineNumber: 69}}, style)
      , h('div', { class: "border border-r-2 border-solid p-4 bg-white"    , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 70}}
        , h('div', { class: "flex items-center mb-4"  , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 71}}, "题目"

          , kunNumber
          , h('span', { class: "ml-2", __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 74}}
            , getTitle(exercise.exerciseType)
          )
        )
        , h('div', { class: "flex flex-row" , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 78}}
          , h('span', { class: "mr-2", __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 79}}, "问题:"

          )
          , exercise.title
        )
        , 
          exercise.exerciseType === ConstantExerciseType.SELECT && (
          h('div', { className: "flex flex-row" , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 86}}
            , h('span', { className: "mr-2", __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 87}}, "答案:"

            )
            , h('div', { class: "ml-8", __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 90}}
              , 
                exercise.options.map((option, index) => (
                  h('div', { class: "flex flex-row mt-2 items-center"   , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 93}}
                    , h('kun-checkbox', { checked: exercise.correct.indexOf(index) > -1, class: "mr-2", disabled: true, __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 94}} )
                    , h('div', {__self: undefined, __source: {fileName: _jsxFileName, lineNumber: 95}}, option)
                  )
                ))
              
            )
          )
          )
        
        , 
          exercise.exerciseType === ConstantExerciseType.OPEN && (
          h('div', { className: "flex flex-row" , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 105}}
            , h('span', { className: "mr-2", __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 106}}, "答案:"

            )
            , exercise.answer
          )
          )
        

        , h('div', { class: "py-2 flex flex-row justify-end items-center"    , __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 114}}
          , h('kun-icon', { iconType: "bianji", iconWidth: 28, iconHeight: 28, onclick: () => editExercise(exercise), __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 115}} )
          , h('kun-icon', { iconType: "shanchu", iconWidth: 20, iconHeight: 20, onclick: () => deleteExercise(exercise), __self: undefined, __source: {fileName: _jsxFileName, lineNumber: 116}} )
        )
      )
    )
  );
};

KunItemExercise.props = {
  kunExercise: {
    type: Object,
  },
  kunNumber: {
    type: Number,
    value: 1,
  },
};

var kunItemExercise = getComponentOrDefine("kun-item-exercise", KunItemExercise);

export default kunItemExercise;
